Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import ast
- import datetime
- errorMsg = ""
- def extractPasscode(encPasscode):
- passcode_split = splitPasscode(encPasscode)
- try:
- decPassword = str(base64.b64decode(passcode_split)).strip("b''")
- extractedData = stringToArray(decPassword)
- except:
- raise ValueError
- return extractedData
- def splitPasscode(encPasscode):
- split_ = encPasscode.split("_")
- if len(split_) != 7:
- while True:
- doContinue = input("Invalid metadata. Continue?\nY/N\n").upper()
- if doContinue == "Y":
- break
- elif doContinue == "N":
- global errorMsg
- errorMsg = "Invalid metadata - check the start and end of the passcode"
- raise NameError
- else:
- print("Invalid choice:", doContinue)
- global date
- date = split_[0]
- for i in split_:
- if len(i) > 200:
- return i
- errorMsg = "General array is too short!"
- raise ValueError
- def stringToArray(inp):
- arr = []
- split = str(inp).split(",")
- arr.append(split[0])
- for i in range(1, 8):
- arr.append(int(split[i]))
- arr.append(itemString(split[8]))
- arr.append(indexString(split[9]))
- arr.append(keyString(split[10]))
- arr.append(int(split[11]))
- if int(split[12]) < 3840:
- split[12] = 3840
- arr.append(int(split[12]))
- for i in range(13, len(split)):
- arr.append(int(split[i]))
- return str(arr)
- def itemString(arr):
- split_ = arr.split("_")
- row0 = []
- row1 = []
- row2 = []
- for i in range(0, len(split_)):
- if i < 9:
- row0.append(int(split_[i]))
- elif i < 18:
- row1.append(int(split_[i]))
- elif i < 27:
- row2.append(int(split_[i]))
- return [row0, row1, row2]
- def indexString(arr):
- genArr = []
- trueIndex = 0
- falseIndex = 0
- for i in range(0, len(arr)):
- if arr[i] == "ABCDEFGHIJKLM01234"[trueIndex]:
- genArr.append(True)
- trueIndex = (trueIndex + 1) % 18
- elif arr[i] == "NOPQRSTUVWXYZ56789"[falseIndex]:
- genArr.append(False)
- falseIndex = (falseIndex + 1) % 18
- else:
- global errorMsg
- errorMsg = "General array contains invalid character: " + arr[i]
- raise ValueError
- return genArr
- def keyString(arr):
- split_ = arr.split("_")
- keys = []
- for i in range(0, len(split_)):
- if split_[i] == "-1":
- keys.append(False)
- elif split_[i] != "":
- keys.append(split_[i])
- return keys
- def formatAndEncode(decPasscode):
- decPasscode = ast.literal_eval(decPasscode)
- decPasscode[8] = invToString(decPasscode[8][0]) + invToString(decPasscode[8][1]) + invToString(decPasscode[8][2])
- decPasscode[9] = genToString(decPasscode[9])
- decPasscode[10] = keysToString(decPasscode[10])
- formatted = ""
- for i in decPasscode:
- formatted += str(i) + ","
- date_time = str(datetime.datetime.now()).split(" ")
- time = date_time[1].split(":")
- formatted = "PHOENOTOPIA-" + date_time[0] + "-" + time[0] + ":" + time[1] + "-___" + str(base64.b64encode(formatted.rstrip(",").encode("ascii"))).strip("b''") + "___"
- return formatted
- def invToString(invArray):
- invString = ""
- for i in invArray:
- invString += str(i) + "_"
- return invString
- def keysToString(keysArray):
- keyString = ""
- for i in keysArray:
- if i:
- keyString += i + "_"
- else:
- keyString += "-1_"
- return keyString
- def genToString(genArray):
- genString = ""
- trueIndex = 0
- falseIndex = 0
- for i in genArray:
- if i:
- genString += "ABCDEFGHIJKLM01234"[trueIndex]
- trueIndex = (trueIndex + 1) % 18
- else:
- genString += "NOPQRSTUVWXYZ56789"[falseIndex]
- falseIndex = (falseIndex + 1) % 18
- return genString
- mode = 0
- menu = True
- while True:
- modeSelect = input("Would you like to:\n\t1.\tDecode a save file\n\tor\n\t2.\tEncode a save file\n\tor\n\t3.\t(Re)build metadata\n?\n")
- try:
- mode = int(modeSelect)
- if mode not in [1, 2, 3]:
- raise NotImplementedError
- elif mode == 1:
- while True:
- try:
- inputPasscode = input("Please input a Phoenotopia 1 encoded passcode:\n")
- print("Output:\n\n\n" + extractPasscode(inputPasscode), "\n\n\nDone!")
- break
- except:
- if errorMsg == "":
- errorMsg = "Base 64 decode error (likely incorrect passcode)"
- print("Invalid passcode:", errorMsg)
- elif mode == 2:
- while True:
- try:
- inputPasscode = str(input("Please input a Phoenotopia 1 decoded formatted passcode:\n"))
- print("Output:\n\n\n" + formatAndEncode(inputPasscode), "\n\n\nDone!")
- break
- except:
- if errorMsg == "":
- errorMsg = "Base 64 encode error (something messed up, please send me the passcode)"
- print("Invalid passcode:", errorMsg)
- else:
- run = True
- while run:
- try:
- inputPasscode = str(input("Please input a Phoenotopia 1 encoded passcode:\n"))
- if len(inputPasscode.split("_")) == 7:
- while True:
- doContinue = input("The inputted passcode's metadata is (probably) valid! Continue?\nY/N\n").upper()
- if doContinue == "Y":
- inputPasscode = inputPasscode.split("_")[3]
- break
- elif doContinue == "N":
- run = False
- break
- else:
- print("Invalid choice:", doContinue)
- if run:
- run = False
- try:
- completePasscode = "PHOENOTOPIA-0000-00-00-00:00-___" + inputPasscode + "___"
- verif = formatAndEncode(extractPasscode(completePasscode))
- print("Output:\n\n\n" + verif, "\n\n\nDone!")
- except:
- print(inputPasscode, "isn't a valid passcode!")
- except:
- print("Unknown error! Please talk to me")
- except:
- print("Invalid choice! Please choose a valid option...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement