# -*- coding: utf-8 -*-
import sys
from Crypto.Hash import MD5
from Crypto.Hash import SHA
 
#Open the files. One file that was given as input for reading and separate files for both hashes.
FILEIN = open( sys.argv[1], 'rb' )
MD5File = open( 'MD5', 'wb' )
SHAFile = open( 'SHA', 'wb' )
file_block_size = 512
 
md5 = MD5.new()
sha = SHA.new()
 
#Read file in small pieces
while True:
        contents=FILEIN.read(file_block_size)
        #No content - break
        if not contents:
                break
        #Feed the content to digests
        md5.update(contents)
        sha.update(contents)
 
#Print both digests
print md5.hexdigest()
print sha.hexdigest()
 
#Write hashes to files
MD5File.write(md5.hexdigest());
SHAFile.write(sha.hexdigest());
 
#close all files
FILEIN.close()
MD5File.close()
SHAFile.close()
Last modified: 2014/02/04 15:50