Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Created April 12, 2016 02:01
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 mipsparc/64dccb3535466787dc637926d6777ada to your computer and use it in GitHub Desktop.
Save mipsparc/64dccb3535466787dc637926d6777ada to your computer and use it in GitHub Desktop.
filename = 'TEST TXT'
total = 0
for newchar in filename:
#rotate(一番右のビットは一番左に)
total = ((total & 1) << 7) + (total >> 1)
#add
total += ord(newchar)
#桁溢れ防止
total = total & 0xFF
print(format(total, 'b'))
print(format(total, 'x'))
####結果
#$ python3 sfn_checksum.py
#10001111
#8f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment