Skip to content

Instantly share code, notes, and snippets.

@Mukundan314
Last active January 14, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mukundan314/02b8033b721d9eb784493b55686f64b4 to your computer and use it in GitHub Desktop.
Save Mukundan314/02b8033b721d9eb784493b55686f64b4 to your computer and use it in GitHub Desktop.
import string
substitutions = {
'a': ['@'],
'b': ['8'],
'c': ['('],
'd': ['6'],
'e': ['3'],
'f': ['#'],
'g': ['9'],
'h': ['#'],
'i': ['1', '!'],
'k': ['<'],
'l': ['1', 'i'],
'o': ['0'],
'q': ['9'],
's': ['5', '$'],
't': ['+'],
'v': ['<', '>'],
'w': ['uu', '2u'],
'x': ['%'],
'y': ['?'],
}
def memodict(f):
""" Memoization decorator for a function taking a single argument. """
class memodict(dict):
def __missing__(self, key):
ret = self[key] = f(key)
return ret
return memodict().__getitem__
@memodict
def gen_combinations(password):
if len(password) == 0:
return ['']
sub_passwords = gen_combinations(password[1:])
chars = substitutions.get(password[0].lower(), []) + [password[0]]
if password[0] in string.ascii_letters:
chars.append(password[0].swapcase())
return [char + sub_password for char in chars for sub_password in sub_passwords]
def main():
n = int(input('Number of input passwords: '))
passwords = [input(f"Input password {i}: ") for i in range(1, n + 1)]
for password in passwords:
print(*gen_combinations(password), sep='\n')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment