A save state/password generator for the original Metroid.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

metroidgen.py 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. import random
  2. class MetroidState:
  3. def __init__(self):
  4. self.alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?-"
  5. self.itemsCollected = {
  6. "Maru Mari": False,
  7. "Bombs": False,
  8. "Long Beam": False,
  9. "Ice Beam": False,
  10. "Wave Beam": False,
  11. "High Jump Boots": False,
  12. "Varia": False,
  13. "Screw Attack": False
  14. }
  15. self.samusHas = {
  16. "Maru Mari": False,
  17. "Bombs": False,
  18. "Long Beam": False,
  19. "Ice Beam": False,
  20. "Wave Beam": False,
  21. "High Jump Boots": False,
  22. "Varia": False,
  23. "Screw Attack": False
  24. }
  25. self.missileTanks = {
  26. 1: False,
  27. 2: False,
  28. 3: False,
  29. 4: False,
  30. 5: False,
  31. 6: False,
  32. 7: False,
  33. 8: False,
  34. 9: False,
  35. 10: False,
  36. 11: False,
  37. 12: False,
  38. 13: False,
  39. 14: False,
  40. 15: False,
  41. 16: False,
  42. 17: False,
  43. 18: False,
  44. 19: False,
  45. 20: False,
  46. 21: False
  47. }
  48. self.energyTanks = {
  49. 1: False,
  50. 2: False,
  51. 3: False,
  52. 4: False,
  53. 5: False,
  54. 6: False,
  55. 7: False,
  56. 8: False
  57. }
  58. self.zebetitesDestroyed = {
  59. 1: False,
  60. 2: False,
  61. 3: False,
  62. 4: False,
  63. 5: False
  64. }
  65. self.doors = {
  66. "Brinstar": {
  67. 1: False,
  68. 2: False,
  69. 3: False,
  70. 4: False,
  71. 5: False
  72. }, "Norfair": {
  73. 1: False,
  74. 2: False,
  75. 3: False,
  76. 4: False
  77. }, "Kraid": {
  78. 1: False,
  79. 2: False,
  80. 3: False,
  81. 4: False,
  82. 5: False
  83. }, "Ridley": {
  84. 1: False,
  85. 2: False
  86. }, "Tourian": {
  87. 1: False,
  88. 2: False,
  89. 3: False
  90. }
  91. }
  92. self.kraidKilled = False
  93. self.ridleyKilled = False
  94. self.motherBrainKilled = False
  95. self.kraidStatue = False
  96. self.ridleyStatue = False
  97. self.swimsuit = False
  98. self.missileCount = 0
  99. self.gameAge = 0
  100. self.locations = ["Brinstar", "Norfair", "Kraid's Lair", "Ridley's Lair", "Tourian"]
  101. self.startLocation = 0
  102. self.bitfield = []
  103. for _ in range(128):
  104. self.bitfield.append(0)
  105. def toggleItem(self, itm):
  106. if itm in self.itemsCollected.keys():
  107. self.itemsCollected[itm] = not self.itemsCollected[itm]
  108. self.samusHas[itm] = not self.samusHas[itm]
  109. else:
  110. print("Couldn't find item: {}".format(str(itm)))
  111. def toggleMissileTank(self, num):
  112. try:
  113. num = int(num)
  114. except:
  115. print("{} is not a number".format(num))
  116. return
  117. if num in self.missileTanks.keys():
  118. self.missileTanks[num] = not self.missileTanks[num]
  119. else:
  120. print("Couldn't find missile tank: {}".format(num))
  121. def toggleEnergyTank(self, num):
  122. try:
  123. num = int(num)
  124. except:
  125. print("{} is not a number".format(num))
  126. return
  127. if num in self.energyTanks.keys():
  128. self.energyTanks[num] = not self.energyTanks[num]
  129. else:
  130. print("Couldn't find energy tank: {}".format(num))
  131. def toggleZebetite(self, num):
  132. try:
  133. num = int(num)
  134. except:
  135. print("{} is not a number".format(num))
  136. return
  137. if num in self.zebetitesDestroyed.keys():
  138. self.zebetitesDestroyed[num] = not self.zebetitesDestroyed[num]
  139. else:
  140. print("Couldn't find Zebetite: {}".format(num))
  141. def toggleKraid(self):
  142. self.kraidKilled = not self.kraidKilled
  143. self.kraidStatue = self.kraidKilled
  144. def toggleKraidStatue(self):
  145. self.kraidStatue = not self.kraidStatue
  146. if self.kraidKilled and not self.kraidStatue:
  147. print("WARNING: Kraid has been killed but his statue has not been raised.")
  148. def toggleRidley(self):
  149. self.ridleyKilled = not self.ridleyKilled
  150. self.ridleyStatue = self.ridleyKilled
  151. def toggleRidleyStatue(self):
  152. self.ridleyStatue = not self.ridleyStatue
  153. if self.ridleyKilled and not self.ridleyStatue:
  154. print("WARNING: Ridley has been killed but his statue has not been raised.")
  155. def toggleMotherBrain(self):
  156. self.motherBrainKilled = not self.motherBrainKilled
  157. def toggleDoor(self, area, door):
  158. try:
  159. area = str(area)
  160. door = int(door)
  161. except:
  162. print("Area must be string, door must be a positive integer")
  163. return
  164. if area in self.doors.keys() and int(door) in self.doors[area].keys():
  165. self.doors[area][door] = not self.doors[area][door]
  166. else:
  167. print("Couldn't find door {} in area {}".format(door, area))
  168. def toggleSwimsuit(self):
  169. self.swimsuit = not self.swimsuit
  170. def newLocation(self, loc):
  171. try:
  172. loc = str(loc)
  173. except:
  174. print("Location must be a string")
  175. return
  176. if loc in self.locations:
  177. self.startLocation = self.locations.index(loc)
  178. else:
  179. print("Couldn't find location: {}".format(loc))
  180. def collectedItems(self):
  181. o = []
  182. for k,v in self.itemsCollected.items():
  183. if v == True:
  184. o.append(k)
  185. if len(o) == 0:
  186. return "None"
  187. else:
  188. return ", ".join(o)
  189. def collectedMissiles(self):
  190. o = []
  191. for k, v in self.missileTanks.items():
  192. if v == True:
  193. o.append(k)
  194. if len(o) == 0:
  195. return "None"
  196. else:
  197. return ", ".join([str(b) for b in o])
  198. def collectedEtanks(self):
  199. o = []
  200. for k, v in self.energyTanks.items():
  201. if v == True:
  202. o.append(k)
  203. if len(o) == 0:
  204. return "None"
  205. else:
  206. return ", ".join([str(b) for b in o])
  207. def killedZebetites(self):
  208. o = []
  209. for k, v in self.zebetitesDestroyed.items():
  210. if v == True:
  211. o.append(k)
  212. if len(o) == 0:
  213. return "None"
  214. else:
  215. return ", ".join([str(b) for b in o])
  216. def killedBosses(self):
  217. o = []
  218. if self.kraidKilled:
  219. o.append("Kraid")
  220. if self.ridleyKilled:
  221. o.append("Ridley")
  222. if self.motherBrainKilled:
  223. o.append("Mother Brain")
  224. if len(o) == 0:
  225. return "None"
  226. else:
  227. return ", ".join(o)
  228. def raisedStatues(self):
  229. o = []
  230. if self.kraidStatue:
  231. o.append("Kraid")
  232. if self.ridleyStatue:
  233. o.append("Ridley")
  234. if len(o) == 0:
  235. return "None"
  236. else:
  237. return ", ".join(o)
  238. def inBailey(self):
  239. if self.swimsuit:
  240. return "Yes"
  241. else:
  242. return "No"
  243. def openedDoors(self):
  244. d = {"Brinstar": 0, "Norfair": 0, "Kraid": 0, "Ridley": 0, "Tourian": 0}
  245. o = []
  246. for k,v in self.doors["Brinstar"].items():
  247. if v == True:
  248. d["Brinstar"] = d["Brinstar"] + 1
  249. for k,v in self.doors["Norfair"].items():
  250. if v == True:
  251. d["Norfair"] = d["Norfair"] + 1
  252. for k,v in self.doors["Kraid"].items():
  253. if v == True:
  254. d["Kraid"] = d["Kraid"] + 1
  255. for k,v in self.doors["Ridley"].items():
  256. if v == True:
  257. d["Ridley"] = d["Ridley"] + 1
  258. for k,v in self.doors["Tourian"].items():
  259. if v == True:
  260. d["Tourian"] = d["Tourian"] + 1
  261. for k, v in d.items():
  262. o.append("{} {}".format(k, v))
  263. return ", ".join(o)
  264. def getBits(self):
  265. o = []
  266. word = []
  267. for i in range(128):
  268. word.append(str(self.bitfield[i]))
  269. if len(word) == 8:
  270. o.append("".join(word))
  271. word = []
  272. o1 = " ".join(o[:8])
  273. o2 = " ".join(o[8:])
  274. return o1 + "\n" + o2
  275. def toString(self):
  276. ic = "Items Collected: {}".format(self.collectedItems())
  277. mt = "Missile Tanks Collected: {}".format(self.collectedMissiles())
  278. et = "Energy Tanks Collected: {}".format(self.collectedEtanks())
  279. zb = "Zebetites Killed: {}".format(self.killedZebetites())
  280. kb = "Bosses Killed: {}".format(self.killedBosses())
  281. rs = "Statues Raised: {}".format(self.raisedStatues())
  282. sw = "Swimsuit?: {}".format(self.inBailey())
  283. sl = "Start Location: {}".format(self.locations[self.startLocation])
  284. dr = "Unlocked Doors: {}".format(self.openedDoors())
  285. ms = "Missiles: {}".format(self.missileCount)
  286. bf = "Bitfield:\n{}".format(self.getBits())
  287. return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr, ms, bf])
  288. def randomize(self):
  289. # Items
  290. if random.randint(0,1) == 1:
  291. self.toggleItem("Maru Mari")
  292. if random.randint(0,1) == 1:
  293. self.toggleItem("Bombs")
  294. if random.randint(0,1) == 1:
  295. self.toggleItem("Varia")
  296. if random.randint(0,1) == 1:
  297. self.toggleItem("High Jump Boots")
  298. if random.randint(0,1) == 1:
  299. self.toggleItem("Screw Attack")
  300. if random.randint(0,1) == 1:
  301. self.toggleItem("Long Beam")
  302. beam = random.randint(0,2)
  303. if beam == 1:
  304. self.toggleItem("Ice Beam")
  305. elif beam == 2:
  306. self.toggleItem("Wave Beam")
  307. # Missile Tanks
  308. for i in range(21):
  309. if random.randint(0,1) == 1:
  310. self.toggleMissileTank(i+1)
  311. # Energy Tanks
  312. for i in range(8):
  313. if random.randint(0,1) == 1:
  314. self.toggleEnergyTank(i+1)
  315. # Zebetites
  316. for i in range(5):
  317. if random.randint(0,1) == 1:
  318. self.toggleZebetite(i+1)
  319. # Bosses killed
  320. if random.randint(0,1) == 1:
  321. self.toggleKraid()
  322. if random.randint(0,1) == 1:
  323. self.toggleRidley()
  324. if random.randint(0,1) == 1:
  325. self.toggleMotherBrain()
  326. # Statues raised
  327. if not self.kraidKilled and random.randint(0,1) == 1:
  328. self.toggleKraidStatue()
  329. if not self.ridleyKilled and random.randint(0,1) == 1:
  330. self.toggleRidleyStatue()
  331. # Doors
  332. # Brinstar 5, Norfair 4, Kraid 5, Ridley 2, Tourian 3
  333. for i in range(5):
  334. if random.randint(0,1) == 1:
  335. self.doors["Brinstar"][i+1] = True
  336. for i in range(4):
  337. if random.randint(0,1) == 1:
  338. self.doors["Norfair"][i+1] = True
  339. for i in range(5):
  340. if random.randint(0,1) == 1:
  341. self.doors["Kraid"][i+1] = True
  342. for i in range(2):
  343. if random.randint(0,1) == 1:
  344. self.doors["Ridley"][i+1] = True
  345. for i in range(3):
  346. if random.randint(0,1) == 1:
  347. self.doors["Tourian"][i+1] = True
  348. # Swimsuit
  349. if random.randint(0,2) == 2:
  350. self.toggleSwimsuit()
  351. # Start Location
  352. self.startLocation = random.randint(0,4)
  353. self.missileCount = random.randint(0,255)
  354. self.createBitfield()
  355. def createBitfield(self):
  356. # Doing this in order, which is dumb and tedious but accurate.
  357. if self.itemsCollected["Maru Mari"]:
  358. self.bitfield[0] = 1
  359. if self.missileTanks[1]:
  360. self.bitfield[1] = 1
  361. if self.doors["Brinstar"][1]:
  362. self.bitfield[2] = 1
  363. if self.doors["Brinstar"][2]:
  364. self.bitfield[3] = 1
  365. if self.energyTanks[1]:
  366. self.bitfield[4] = 1
  367. if self.doors["Brinstar"][3]:
  368. self.bitfield[5] = 1
  369. if self.itemsCollected["Bombs"]:
  370. self.bitfield[6] = 1
  371. if self.doors["Brinstar"][4]:
  372. self.bitfield[7] = 1
  373. if self.missileTanks[2]:
  374. self.bitfield[8] = 1
  375. if self.energyTanks[2]:
  376. self.bitfield[9] = 1
  377. if self.doors["Brinstar"][5]:
  378. self.bitfield[10] = 1
  379. if self.itemsCollected["Varia"]:
  380. self.bitfield[11] = 1
  381. if self.energyTanks[3]:
  382. self.bitfield[12] = 1
  383. if self.missileTanks[3]:
  384. self.bitfield[13] = 1
  385. if self.missileTanks[4]:
  386. self.bitfield[14] = 1
  387. if self.doors["Norfair"][1]:
  388. self.bitfield[15] = 1
  389. if self.missileTanks[5]:
  390. self.bitfield[16] = 1
  391. if self.missileTanks[6]:
  392. self.bitfield[17] = 1
  393. if self.missileTanks[7]:
  394. self.bitfield[18] = 1
  395. if self.missileTanks[8]:
  396. self.bitfield[19] = 1
  397. if self.missileTanks[9]:
  398. self.bitfield[20] = 1
  399. if self.missileTanks[10]:
  400. self.bitfield[21] = 1
  401. if self.missileTanks[11]:
  402. self.bitfield[22] = 1
  403. if self.doors["Norfair"][2]:
  404. self.bitfield[23] = 1
  405. if self.itemsCollected["High Jump Boots"]:
  406. self.bitfield[24] = 1
  407. if self.doors["Norfair"][3]:
  408. self.bitfield[25] = 1
  409. if self.itemsCollected["Screw Attack"]:
  410. self.bitfield[26] = 1
  411. if self.missileTanks[12]:
  412. self.bitfield[27] = 1
  413. if self.missileTanks[13]:
  414. self.bitfield[28] = 1
  415. if self.doors["Norfair"][4]:
  416. self.bitfield[29] = 1
  417. if self.energyTanks[4]:
  418. self.bitfield[30] = 1
  419. if self.missileTanks[14]:
  420. self.bitfield[31] = 1
  421. if self.doors["Kraid"][1]:
  422. self.bitfield[32] = 1
  423. if self.missileTanks[15]:
  424. self.bitfield[33] = 1
  425. if self.missileTanks[16]:
  426. self.bitfield[34] = 1
  427. if self.doors["Kraid"][2]:
  428. self.bitfield[35] = 1
  429. if self.energyTanks[5]:
  430. self.bitfield[36] = 1
  431. if self.doors["Kraid"][3]:
  432. self.bitfield[37] = 1
  433. if self.doors["Kraid"][4]:
  434. self.bitfield[38] = 1
  435. if self.missileTanks[17]:
  436. self.bitfield[39] = 1
  437. if self.missileTanks[18]:
  438. self.bitfield[40] = 1
  439. if self.doors["Kraid"][5]:
  440. self.bitfield[41] = 1
  441. if self.energyTanks[6]:
  442. self.bitfield[42] = 1
  443. if self.missileTanks[19]:
  444. self.bitfield[43] = 1
  445. if self.doors["Ridley"][1]:
  446. self.bitfield[44] = 1
  447. if self.energyTanks[7]:
  448. self.bitfield[45] = 1
  449. if self.missileTanks[20]:
  450. self.bitfield[46] = 1
  451. if self.doors["Ridley"][2]:
  452. self.bitfield[47] = 1
  453. if self.energyTanks[8]:
  454. self.bitfield[48] = 1
  455. if self.missileTanks[21]:
  456. self.bitfield[49] = 1
  457. if self.doors["Tourian"][1]:
  458. self.bitfield[50] = 1
  459. if self.doors["Tourian"][2]:
  460. self.bitfield[51] = 1
  461. if self.doors["Tourian"][3]:
  462. self.bitfield[52] = 1
  463. if self.zebetitesDestroyed[1]:
  464. self.bitfield[53] = 1
  465. if self.zebetitesDestroyed[2]:
  466. self.bitfield[54] = 1
  467. if self.zebetitesDestroyed[3]:
  468. self.bitfield[55] = 1
  469. if self.zebetitesDestroyed[4]:
  470. self.bitfield[56] = 1
  471. if self.zebetitesDestroyed[5]:
  472. self.bitfield[57] = 1
  473. if self.motherBrainKilled:
  474. self.bitfield[58] = 1
  475. # 59-63 unknown
  476. # if self.:
  477. # self.bitfield[59] = 1
  478. # if self.:
  479. # self.bitfield[60] = 1
  480. # if self.:
  481. # self.bitfield[61] = 1
  482. # if self.:
  483. # self.bitfield[62] = 1
  484. # if self.:
  485. # self.bitfield[63] = 1
  486. # not 64, 65, or 66 = Brinstar
  487. # 64 = Norfair
  488. # 65 and not 66 = Kraid's Lair
  489. # 66 and not 65 = Ridley's Lair
  490. # 65 and 66 = Tourian
  491. if self.startLocation == 1:
  492. self.bitfield[64] = 1
  493. if self.startLocation == 2 or self.startLocation == 4:
  494. self.bitfield[65] = 1
  495. if self.startLocation == 3 or self.startLocation == 4:
  496. self.bitfield[66] = 1
  497. # 67 is the reset bit, I want all passwords to be valid
  498. # if self.:
  499. # self.bitfield[67] = 1
  500. # 68-70 are unknown
  501. # if self.:
  502. # self.bitfield[68] = 1
  503. # if self.:
  504. # self.bitfield[69] = 1
  505. # if self.:
  506. # self.bitfield[70] = 1
  507. if self.swimsuit:
  508. self.bitfield[71] = 1
  509. if self.samusHas["Bombs"]:
  510. self.bitfield[72] = 1
  511. if self.samusHas["High Jump Boots"]:
  512. self.bitfield[73] = 1
  513. if self.samusHas["Long Beam"]:
  514. self.bitfield[74] = 1
  515. if self.samusHas["Screw Attack"]:
  516. self.bitfield[75] = 1
  517. if self.samusHas["Maru Mari"]:
  518. self.bitfield[76] = 1
  519. if self.samusHas["Varia"]:
  520. self.bitfield[77] = 1
  521. if self.samusHas["Wave Beam"]:
  522. self.bitfield[78] = 1
  523. if self.samusHas["Ice Beam"]:
  524. self.bitfield[79] = 1
  525. # Missile count
  526. # +2^n from 0 to 7
  527. binMissiles = bin(self.missileCount).replace('0b','')[::-1]
  528. while len(binMissiles) < 8:
  529. binMissiles += "0"
  530. if int(binMissiles[0]) == 1:
  531. self.bitfield[80] = 1
  532. if int(binMissiles[1]) == 1:
  533. self.bitfield[81] = 1
  534. if int(binMissiles[2]) == 1:
  535. self.bitfield[82] = 1
  536. if int(binMissiles[3]) == 1:
  537. self.bitfield[83] = 1
  538. if int(binMissiles[4]) == 1:
  539. self.bitfield[84] = 1
  540. if int(binMissiles[5]) == 1:
  541. self.bitfield[85] = 1
  542. if int(binMissiles[6]) == 1:
  543. self.bitfield[86] = 1
  544. if int(binMissiles[7]) == 1:
  545. self.bitfield[87] = 1
  546. # 88-119 are game age, leaving at 0
  547. # if self.:
  548. # self.bitfield[88] = 1
  549. # if self.:
  550. # self.bitfield[89] = 1
  551. # if self.:
  552. # self.bitfield[90] = 1
  553. # if self.:
  554. # self.bitfield[91] = 1
  555. # if self.:
  556. # self.bitfield[92] = 1
  557. # if self.:
  558. # self.bitfield[93] = 1
  559. # if self.:
  560. # self.bitfield[94] = 1
  561. # if self.:
  562. # self.bitfield[95] = 1
  563. # if self.:
  564. # self.bitfield[96] = 1
  565. # if self.:
  566. # self.bitfield[97] = 1
  567. # if self.:
  568. # self.bitfield[98] = 1
  569. # if self.:
  570. # self.bitfield[99] = 1
  571. # if self.:
  572. # self.bitfield[100] = 1
  573. # if self.:
  574. # self.bitfield[101] = 1
  575. # if self.:
  576. # self.bitfield[102] = 1
  577. # if self.:
  578. # self.bitfield[103] = 1
  579. # if self.:
  580. # self.bitfield[104] = 1
  581. # if self.:
  582. # self.bitfield[105] = 1
  583. # if self.:
  584. # self.bitfield[106] = 1
  585. # if self.:
  586. # self.bitfield[107] = 1
  587. # if self.:
  588. # self.bitfield[108] = 1
  589. # if self.:
  590. # self.bitfield[109] = 1
  591. # if self.:
  592. # self.bitfield[110] = 1
  593. # if self.:
  594. # self.bitfield[111] = 1
  595. # if self.:
  596. # self.bitfield[112] = 1
  597. # if self.:
  598. # self.bitfield[113] = 1
  599. # if self.:
  600. # self.bitfield[114] = 1
  601. # if self.:
  602. # self.bitfield[115] = 1
  603. # if self.:
  604. # self.bitfield[116] = 1
  605. # if self.:
  606. # self.bitfield[117] = 1
  607. # if self.:
  608. # self.bitfield[118] = 1
  609. # if self.:
  610. # self.bitfield[119] = 1
  611. # 120-123 are unknown
  612. # if self.:
  613. # self.bitfield[120] = 1
  614. # if self.:
  615. # self.bitfield[121] = 1
  616. # if self.:
  617. # self.bitfield[122] = 1
  618. # if self.:
  619. # self.bitfield[123] = 1
  620. if self.ridleyKilled:
  621. self.bitfield[124] = 1
  622. if self.ridleyStatue:
  623. self.bitfield[125] = 1
  624. if self.kraidKilled:
  625. self.bitfield[126] = 1
  626. if self.kraidStatue:
  627. self.bitfield[127] = 1
  628. def generatePassword(self):
  629. # not gonna do the bit-shifting yet
  630. # shiftbit = random.randint(0,7)
  631. bitfield = self.bitfield
  632. # for _ in range(shiftbit):
  633. # [bitfield[127]] + bitfield[:127]
  634. # binShift = bin(shiftbit).replace('0b','')
  635. # while len(binShift) < 8:
  636. # binShift = "0" + binShift
  637. # for bit in binShift:
  638. # bitfield.append(int(bit))
  639. bitfield = bitfield + [0,0,0,0,0,0,0,0]
  640. checking = []
  641. for i in range(16):
  642. checking.append(int("".join([str(x) for x in bitfield[i:i+8]]), 2))
  643. decChecksum = sum(checking)
  644. print(decChecksum)
  645. binChecksum = bin(decChecksum).replace('0b','')
  646. print(binChecksum)
  647. checksum = binChecksum[-8:]
  648. while len(checksum) < 8:
  649. checksum = checksum + "0"
  650. print(checksum)
  651. for bit in checksum:
  652. bitfield.append(int(bit))
  653. print("Full Bitfield: {}".format("".join([str(x) for x in bitfield])))
  654. print(len(bitfield))
  655. letters = []
  656. letter = []
  657. for bit in bitfield:
  658. letter.append(str(bit))
  659. if len(letter) == 6:
  660. print(letter)
  661. letters.append(self.alphabet[int("".join(letter),2)])
  662. letter = []
  663. print(letters)
  664. words = []
  665. word = []
  666. print(letters)
  667. print(len(letters))
  668. for lt in letters:
  669. word.append(lt)
  670. if len(word) == 6:
  671. words.append("".join(word))
  672. word = []
  673. words.append("".join(word))
  674. return " ".join(words)
  675. def main():
  676. gs = MetroidState()
  677. gs.randomize()
  678. gs.createBitfield()
  679. print(gs.toString())
  680. print(gs.generatePassword())
  681. if __name__ == "__main__":
  682. main()