|
|
@@ -1,6 +1,6 @@ |
|
|
|
# This uses http://games.technoplaza.net/mpg/password.txt as a basis for its password algorithm |
|
|
|
|
|
|
|
import random |
|
|
|
import random, sys |
|
|
|
|
|
|
|
class MetroidState: |
|
|
|
def __init__(self): |
|
|
@@ -104,6 +104,7 @@ class MetroidState: |
|
|
|
self.startLocation = 0 |
|
|
|
self.bitfield = [] |
|
|
|
self.initializeBitfield() |
|
|
|
self.fullbitfield = [] |
|
|
|
|
|
|
|
def initializeBitfield(self): |
|
|
|
self.bitfield = [] |
|
|
@@ -312,8 +313,9 @@ class MetroidState: |
|
|
|
sl = "Start Location: {}".format(self.locations[self.startLocation]) |
|
|
|
dr = "Unlocked Doors: {}".format(self.openedDoors()) |
|
|
|
ms = "Missiles: {}".format(self.missileCount) |
|
|
|
bf = "Bitfield:\n{}".format(self.getBits()) |
|
|
|
return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr, ms, bf]) |
|
|
|
pw = "Password: {}".format(self.password) |
|
|
|
# bf = "Bitfield:\n{}".format(self.getBits()) |
|
|
|
return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr, ms, pw]) |
|
|
|
|
|
|
|
def randomize(self): |
|
|
|
# Items |
|
|
@@ -672,43 +674,83 @@ class MetroidState: |
|
|
|
# checking = [] |
|
|
|
# for i in range(16): |
|
|
|
# checking.append(int("".join([str(x) for x in bitfield[i:i+8]]), 2)) |
|
|
|
decChecksum = sum(bitfield) |
|
|
|
# print("Full Bitfield: {}".format("".join([str(x) for x in bitfield]))) |
|
|
|
self.fullbitfield = "".join([str(x) for x in bitfield]) |
|
|
|
newBitfield = [] |
|
|
|
for i in range(17): |
|
|
|
j = i * 8 |
|
|
|
k = j + 8 |
|
|
|
word = self.fullbitfield[j:k][::-1] |
|
|
|
newBitfield.append(word) |
|
|
|
decChecksum = sum([int(x, 2) for x in newBitfield]) |
|
|
|
bitfield = "".join(newBitfield) |
|
|
|
binChecksum = bin(decChecksum).replace('0b','') |
|
|
|
checksum = binChecksum[-8:] |
|
|
|
while len(checksum) < 8: |
|
|
|
checksum = checksum + "0" |
|
|
|
print(checksum) |
|
|
|
checksum = "0" + checksum |
|
|
|
# print(checksum) |
|
|
|
for bit in checksum: |
|
|
|
bitfield.append(int(bit)) |
|
|
|
print("Full Bitfield: {}".format("".join([str(x) for x in bitfield]))) |
|
|
|
print(len(bitfield)) |
|
|
|
bitfield += bit |
|
|
|
# print("Real Bitfield: {}".format(bitfield)) |
|
|
|
|
|
|
|
letters = [] |
|
|
|
letter = [] |
|
|
|
for bit in bitfield: |
|
|
|
letter.append(str(bit)) |
|
|
|
letter.append(bit) |
|
|
|
if len(letter) == 6: |
|
|
|
print(letter) |
|
|
|
letters.append(self.alphabet[int("".join(letter),2)]) |
|
|
|
letter = [] |
|
|
|
print(letters) |
|
|
|
words = [] |
|
|
|
word = [] |
|
|
|
print(letters) |
|
|
|
print(len(letters)) |
|
|
|
for lt in letters: |
|
|
|
word.append(lt) |
|
|
|
if len(word) == 6: |
|
|
|
words.append("".join(word)) |
|
|
|
word = [] |
|
|
|
words.append("".join(word)) |
|
|
|
return " ".join(words) |
|
|
|
self.password = " ".join(words) |
|
|
|
return self.password |
|
|
|
|
|
|
|
def decodePassword(self, pwd): |
|
|
|
densePwd = pwd.replace(" ","") |
|
|
|
numPwd = [] |
|
|
|
for chr in densePwd: |
|
|
|
numPwd.append(self.alphabet.index(chr)) |
|
|
|
bitPwd = [bin(x).replace("0b","") for x in numPwd] |
|
|
|
longBitPwd = [] |
|
|
|
for word in bitPwd: |
|
|
|
longword = word |
|
|
|
while len(longword) < 6: |
|
|
|
longword = "0" + longword |
|
|
|
longBitPwd.append(longword) |
|
|
|
# print(self.fullbitfield) |
|
|
|
newBitfield = "".join(longBitPwd) |
|
|
|
# print(newBitfield) |
|
|
|
# print(newBitfield == self.fullbitfield) |
|
|
|
# print(len(newBitfield[:136])) |
|
|
|
# print(newBitfield[:136]) |
|
|
|
csm = sum([int(x) for x in newBitfield[:136]]) |
|
|
|
print(csm) |
|
|
|
# print(bin(csm).replace("0b","")) |
|
|
|
for i in range(len(newBitfield)): |
|
|
|
print(newBitfield[i], end="") |
|
|
|
if i%8 == 7: |
|
|
|
print(" ", end="") |
|
|
|
if i%64 == 63: |
|
|
|
print() |
|
|
|
|
|
|
|
def main(): |
|
|
|
gs = MetroidState() |
|
|
|
gs.randomize() |
|
|
|
gs.createBitfield() |
|
|
|
pwd = gs.generatePassword() |
|
|
|
print(gs.toString()) |
|
|
|
print(gs.generatePassword()) |
|
|
|
# print(pwd) |
|
|
|
# gs.decodePassword(pwd) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |
|
|
|
if len(sys.argv) == 2: |
|
|
|
gs = MetroidState() |
|
|
|
gs.decodePassword(sys.argv[1]) |
|
|
|
else: |
|
|
|
main() |