-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc04.py
34 lines (26 loc) · 947 Bytes
/
c04.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
30
31
32
33
34
from binascii import unhexlify
from pals.freq_analysis import most_english_definition
def main():
# open the challenge file
with open("files/c4.txt", "rb") as f:
most_english = ""
best_score = 0
for line in f.readlines():
# try each single character (0-255) key on this line, get the result that
# best fits the english frequency scoring table.
line_result = most_english_definition(
unhexlify(line.strip())
)
# if this is the highest score, store it
if line_result.score > best_score:
best_score = line_result.score
most_english = line_result.plaintext
# output our best result
print(most_english)
if __name__ == '__main__':
main()
"""
Detect single-character XOR
One of the 60-character strings in this file has been encrypted by single-character XOR.
Find it.
"""