Skip to content

Instantly share code, notes, and snippets.

@jaames
Last active July 21, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaames/3cb29aa9e9edc611dc3f3c3bf97f46d2 to your computer and use it in GitHub Desktop.
Save jaames/3cb29aa9e9edc611dc3f3c3bf97f46d2 to your computer and use it in GitHub Desktop.
Implementation of PPM filename checksum used when Flipnotes are saved into storage
checksum_dict = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def calc_check_digit(filename):
sumc = int(filename[0:2], 16)
for i in range(1, 16):
char = ord(filename[i])
sumc = (sumc + char) % 256
return checksum_dict[sumc % len(checksum_dict)]
def set_check_digit(filename):
digit = calc_check_digit(filename)
filename = digit + filename[1:]
return filename
# Example
set_check_digit('F78DA8_14768882B56B8_030')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment