checksum 604 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python
  2. # Import hashlib library (md5 method is part of it)
  3. import hashlib
  4. import sys
  5. # File to check
  6. file_name = sys.argv[1]
  7. # Correct original md5 goes here
  8. sums = sys.argv[2]
  9. # Open,close, read file and calculate MD5 on its contents
  10. with open(file_name, 'rb') as file_to_check:
  11. # read contents of the file
  12. data = file_to_check.read()
  13. # pipe contents of the file through
  14. md5_returned = hashlib.md5(data).hexdigest()
  15. # Finally compare original MD5 with freshly calculated
  16. if sums == md5_returned:
  17. print("MD5 verified.")
  18. else:
  19. print("MD5 verification failed!.")