-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrulo_04.py
More file actions
38 lines (33 loc) · 834 Bytes
/
strulo_04.py
File metadata and controls
38 lines (33 loc) · 834 Bytes
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
"""
Strulo 04 - Cracking a Cipher
"""
import collections
import string
path_to_english_file = '/Users/jacob/Desktop/Python/Strulo/english.txt'
while True:
alphabet = string.ascii_lowercase
# a)
plain_file = ''
with open(path_to_english_file) as file:
for word in file:
for c in word:
c = c.lower()
if c in alphabet:
plain_file += c
letters = collections.Counter(plain_file)
print(letters)
# print(letters)
# b)
cipher = input('Enter cipher to crack\n>> ')
key = collections.Counter(cipher)
letters = ''.join(l for l in list(letters.keys()))
keyword = ''.join(l for l in list(key.keys()))
key = ''.join([l for l in alphabet if l not in keyword])
key = keyword + key
# print(key)
output = ''
for l in cipher:
if l in alphabet:
i = letters.index(l)
output += key[i]
print(output)