Last active
May 31, 2020 03:55
-
-
Save TobiX/0106edd801c6c9f276e1fa920d8b0fd8 to your computer and use it in GitHub Desktop.
Nintendo 3DS friendcode verification
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
#!/usr/bin/python3 | |
# Released into the public domain, where possible (http://creativecommons.org/publicdomain/zero/1.0/) | |
import sys | |
import re | |
import hashlib | |
fc = sys.argv[1] | |
parts = re.match('^(\d{4})-(\d{4})-(\d{4})$', fc) | |
if not parts: | |
print("Wrong format!") | |
sys.exit(1) | |
fcint = int("".join(parts.group(1, 2, 3))) | |
principal = fcint & 0xffffffff | |
checksum = fcint >> 32 | |
sha1 = hashlib.sha1() | |
sha1.update(principal.to_bytes(4, byteorder='little')) | |
calcsum = sha1.digest()[0] >> 1 | |
print(fc, fcint, principal, checksum, calcsum) | |
assert checksum == calcsum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment