from ctypes import c_uint import sys import base64 import hashlib # GameSpy uses a slightly modified version of base64 which replaces +/= with []_ def base64_encode(input): output = base64.b64encode(input).replace('+', '[').replace('/',']').replace('=','_') return output def base64_decode(input): output = base64.b64decode(input.replace('[', '+').replace('/',']').replace('_','=')) return output # Parse my custom authtoken generated by the emulated nas.nintendowifi.net/ac def parse_authtoken(authtoken): messages = {} if authtoken[:3] == "NDS": authtoken = authtoken[3:] dec = base64.standard_b64decode(authtoken) for item in dec.split('|'): s = item.split('\\') messages[s[0]] = s[1] return messages def generate_response(challenge, ac_challenge, secretkey, authtoken): md5 = hashlib.md5() md5.update(ac_challenge) output = md5.hexdigest() output += ' ' * 0x30 output += authtoken output += secretkey output += challenge output += md5.hexdigest() md5_2 = hashlib.md5() md5_2.update(output) return md5_2.hexdigest() # The proof is practically the same thing as the response, except it has the challenge and the secret key swapped. # Maybe combine the two functions later? def generate_proof(challenge, ac_challenge, secretkey, authtoken): md5 = hashlib.md5() md5.update(ac_challenge) output = md5.hexdigest() output += ' ' * 0x30 output += authtoken output += challenge output += secretkey output += md5.hexdigest() md5_2 = hashlib.md5() md5_2.update(output) return md5_2.hexdigest()