-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.py
29 lines (26 loc) · 781 Bytes
/
4.py
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
"""
! Detect single-character XOR
* One of the 60-character strings in this file has been encrypted by single-character XOR.
* Find it.
* (Your code from #3 should help.)
"""
from utils import score, decode
def main():
with open('4.txt', 'r') as f:
ip = f.read().split()
keys = [max(range(256), key = lambda k: score(decode(i, k))) for i in ip]
print(
max(
[
{
"ciphertext": ip[i],
"key": keys[i],
"decoded": decode(ip[i], keys[i])
}
for i in range(len(keys))
],
key = lambda k: score(k["decoded"])
)
)
if __name__ == "__main__":
main()