Last active
July 21, 2020 15:26
-
-
Save jaames/3cb29aa9e9edc611dc3f3c3bf97f46d2 to your computer and use it in GitHub Desktop.
Implementation of PPM filename checksum used when Flipnotes are saved into storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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