-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday11p1.py
More file actions
executable file
·55 lines (38 loc) · 1.29 KB
/
day11p1.py
File metadata and controls
executable file
·55 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
alphabet = 'abcdefghijklmnopqrstuvwxyz'
rejected_letters = 'ilo'.split()
doubles = [x * 2 for x in alphabet]
triples = [
''.join(x) for x in zip(alphabet[:-2], alphabet[1:-1], alphabet[2:])
]
valid_triples = [
x for x in triples if all(i not in x for i in rejected_letters)
]
ord_base = 97 # Only works with ASCII!
def good_password(password):
if not any(triple in password for triple in valid_triples):
return False
if any(bad_letter in password for bad_letter in rejected_letters):
return False
if len([double for double in doubles if double in password]) < 2:
return False
return True
def bump_password(password):
new_password = list()
carry = False
for idx, char in enumerate(reversed(password)):
if idx == 0 or carry:
new_char = chr((ord(char) - ord_base + 1) % 26 + ord_base)
if new_char == 'a':
carry = True
else:
carry = False
new_password.append(new_char)
else:
new_password.append(char)
return ''.join(reversed(new_password))
orig_password = 'hepxcrrq'
new_password = bump_password(orig_password)
while not good_password(new_password):
new_password = bump_password(new_password)
print new_password