2023-07-14 23:29:10 -05:00
|
|
|
class FoundCondition(Exception):
|
|
|
|
pass
|
|
|
|
|
2023-07-14 23:52:08 -05:00
|
|
|
class PasswordModule:
|
|
|
|
"""
|
|
|
|
takes in information about passwords and returns the password
|
|
|
|
it could be given the information. implementation is pursuant
|
|
|
|
Bomb Defusal Manual, Version 1, English, Page 16.
|
|
|
|
"""
|
|
|
|
passwords = [
|
|
|
|
'about', 'after', 'again', 'below', 'could',
|
|
|
|
'every', 'first', 'found', 'great', 'house',
|
|
|
|
'large', 'learn', 'never', 'other', 'place',
|
|
|
|
'plant', 'point', 'right', 'small', 'sound',
|
|
|
|
'spell', 'still', 'study', 'their', 'there',
|
|
|
|
'these', 'thing', 'think', 'three', 'water',
|
|
|
|
'where', 'which', 'world', 'would', 'write'
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, cols):
|
|
|
|
"""
|
|
|
|
cols should contain a five element long array of numbers,
|
|
|
|
the first element containing all the possible characters for
|
|
|
|
the first position, the second containing all the characters for
|
|
|
|
the second position, and so on.
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.responses = cols
|
|
|
|
self.word = None
|
|
|
|
|
|
|
|
def solve(self):
|
|
|
|
"""
|
|
|
|
start solving.
|
|
|
|
"""
|
|
|
|
for word in self.passwords:
|
|
|
|
try:
|
|
|
|
self._solver(0, word)
|
|
|
|
except FoundCondition as e:
|
|
|
|
self.word = str(e)
|
|
|
|
return self.word
|
|
|
|
|
|
|
|
def _solver(self, index, word):
|
|
|
|
"""
|
|
|
|
internal method. end users need not use.
|
|
|
|
"""
|
|
|
|
responses = self.responses
|
|
|
|
|
|
|
|
if index == 5:
|
|
|
|
raise FoundCondition(word)
|
|
|
|
|
|
|
|
for a in responses[index]:
|
|
|
|
if a == word[index]:
|
|
|
|
self._solver(index + 1, word)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def human_helper(cls):
|
|
|
|
"""
|
|
|
|
prints stuff out to console to prompt for information.
|
|
|
|
useful for module specific debugging. see usage in the
|
|
|
|
default module execution location
|
|
|
|
|
|
|
|
(hint, default module execution location is where __name__ ==
|
|
|
|
"__main__"
|
2023-07-14 23:22:01 -05:00
|
|
|
|
2023-07-14 23:52:08 -05:00
|
|
|
"""
|
|
|
|
responses = []
|
|
|
|
for i in range(5):
|
|
|
|
response = [*input("{}th letters: ".format(str(i)))]
|
|
|
|
responses.append(response)
|
2023-07-14 23:29:10 -05:00
|
|
|
|
2023-07-14 23:52:08 -05:00
|
|
|
obj = cls(responses)
|
|
|
|
return obj.solve()
|
2023-07-14 23:29:10 -05:00
|
|
|
|
2023-07-14 23:52:08 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
print(PasswordModule.human_helper())
|