Skip to content

Instantly share code, notes, and snippets.

@mariomadproductions
Last active July 6, 2020 17:21
Show Gist options
  • Save mariomadproductions/779f6723ef81ae46536f900a33ee71c2 to your computer and use it in GitHub Desktop.
Save mariomadproductions/779f6723ef81ae46536f900a33ee71c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
#Decode Nintendo 3DS Game Card mastering codes
#To use interactive mode, pass '-i' as the argument instead of a mastering code.
from sys import argv
import string
from datetime import datetime
def print_decoded_mstr(input_var):
input_striped = input_var.strip()
if len(input_striped) != 10:
raise ValueError('Mastering code is the wrong length.')
factory = input_striped[0]
year = int('20' + input_striped[1:3])
if not input_striped[3].isupper():
raise ValueError('Month code is not uppercase.')
month = int(string.ascii_uppercase.index(input_striped[3]) + 1)
day = int(input_striped[4:6])
date = datetime(year, month, day)
prodrun = input_striped[6:8].lstrip('0')
print('Factory: {}\nProduction Date: {}\nProduction Run: {}\n'\
.format(factory,date.strftime('%d %B, %Y').lstrip('0'),prodrun))
def interactive_mode():
while True:
print_decoded_mstr(raw_input('Input: '))
arg = argv[1]
try:
if arg == '-i':
interactive_mode()
else:
print_decoded_mstr(arg)
except IndexError:
print('No valid argument entered.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment