Last active
August 29, 2015 14:04
-
-
Save kylemsguy/0404af2da0594c14bb09 to your computer and use it in GitHub Desktop.
Calculates the password to change the time in Pokemon GSC
This file contains hidden or 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
# Derived from http://www.pokezam.com/games/gameboy/gold/tc.js | |
# Usage: either import gen_pkmn_timecode or run directly | |
# NOTE: Pk is represented by + and Mn is represented by = | |
# e.g. if name is Kyle(Pk)(Mn) then type Kyle+= | |
# | |
# To access password screen (Source: Bulbapedia): | |
# G/S: Hold Down, Select, and B | |
# Crystal: Hold Down, Select, and B | |
# Release Down and B while still holding Select | |
# Press Left and Up while still holding Select | |
# Release Select while still holding Up and Left. | |
def gen_pkmn_timecode(name, cash, train_id): | |
new_cash = cash % 65535 | |
new_id = train_id % 65535 | |
final_cash = new_cash // 256 + new_cash % 256 | |
final_id = new_id // 256 + new_id % 256 | |
nval = 0 | |
counter = 0 | |
for char in name: | |
if counter >= 5: | |
break | |
else: | |
counter += 1 | |
nval += get_name_value(char) | |
return nval + final_cash + final_id | |
def get_name_value(char): | |
charcode = ord(char) | |
if char >= 'A' and char <= 'Z': | |
return (charcode - ord('A')) + 128 | |
elif char >= 'a' and char <= 'z': | |
return charcode - ord('a') + 160 | |
else: | |
if char == '-': | |
return 227 | |
elif char == '?': | |
return 230 | |
elif char == '/': | |
return 243 | |
elif char == '.': | |
return 232 | |
elif char == ',': | |
return 244 | |
elif char == '(': | |
return 154 | |
elif char == ')': | |
return 155 | |
elif char == ':': | |
return 156 | |
elif char == ';': | |
return 157 | |
elif char == '[': | |
return 158 | |
elif char == ']': | |
return 159 | |
elif char == '+': # PK | |
return 225 | |
elif char == '=': # MN | |
return 226 | |
elif char == '!': | |
return 231 | |
elif char == '*': | |
return 241 | |
else: | |
raise ValueError | |
if __name__ == "__main__": | |
name = input("Name: ") | |
cash = int(input("Cash on hand: ")) | |
trainer_id = int(input("Trainer ID: ")) | |
passwd = gen_pkmn_timecode(name, cash, trainer_id) | |
str_passwd = str(passwd) | |
while len(str_passwd) < 5: | |
str_passwd = '0' + str_passwd | |
print() | |
print("Password:", str_passwd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment