Skip to content

Instantly share code, notes, and snippets.

@endes0
Last active September 20, 2022 16:45
Show Gist options
  • Save endes0/7575e1a005b7996f462b970bb55cea2a to your computer and use it in GitHub Desktop.
Save endes0/7575e1a005b7996f462b970bb55cea2a to your computer and use it in GitHub Desktop.
Wayback Machine (web.archive.org) Digest generator
#!/usr/bin/env python3
import sys
import os
import hashlib
import base64
# Get the file name to generate the digest for
if len(sys.argv) < 2:
print("Usage: %s <file>" % sys.argv[0])
sys.exit(1)
filename = sys.argv[1]
if not os.path.isfile(filename):
print("File %s not found" % filename)
sys.exit(1)
# Calculate the SHA-1 of the file (https://gist.github.com/techtonik/df09baeacbebc52d234b)
sha1sum = hashlib.sha1()
with open(sys.argv[1], 'rb') as source:
block = source.read(2**16)
while len(block) != 0:
sha1sum.update(block)
block = source.read(2**16)
# Calculate the Base32 of the SHA-1
base32 = base64.b32encode(sha1sum.digest()).decode('utf-8').upper()
# Print the information
print("Filename: %s" % filename)
print("SHA-1: %s" % sha1sum.hexdigest())
print("Wayback Digest (Base32): %s" % base32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment