# -*- coding: utf-8 -*-
import sys
from Crypto.Hash import MD5
 
file_block_size = 512
 
#Open the given file 
FILEIN = open( sys.argv[1], 'rb' )
 
# Initialize digest
md5 = MD5.new()
 
#Read the content in pieces with file_block_size
while True:
	contents = FILEIN.read(file_block_size)
	# File end reached
	if not contents:
		break
	# After every red update the digest with read content
	md5.update(contents)
 
#Simply compare the hash values
if md5.hexdigest() == sys.argv[2]:
	print "MD5 checksum is correct"
else:
	print "MD5 checksum is invalid"
 
FILEIN.close()
Last modified: 2014/02/04 15:51