#!/usr/bin/env python3
# Author: AnalogMan
# Modified Date: 2018-11-06
# Purpose: Generates Nintendo Switch Title IDs based on a 5-character alphanumeric code
import os
import argparse
import re
def main():
print('\n========== Title ID Generator ==========\n')
# Arg parser for program options
parser = argparse.ArgumentParser(description='Generate Title ID from 5-character alphanumeric code')
parser.add_argument('-c', '--code', help='5-character alphanumeric code')
# Check passed arguments
args = parser.parse_args()
if args.code:
code = args.code
else:
code = input('\nInput 5-character alphanumeric code: ')
pattern = re.compile("[a-zA-Z0-9]{5}")
if not pattern.match(code) or len(code) != 5:
print('\nCode must be alphanumeric (A-Z, a-z, 0-9) and 5 characters in length.\n')
return
titleID = '010'
for char in code:
titleID += '{:02x}'.format(ord(char))
titleID += '000'
sanitized_titleID = int(titleID, 16) & 0xFFFFFFFFFFFFE000
print('Title ID: 0x{:016x}'.format(sanitized_titleID))
if __name__ == '__main__':
main()