-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonoalphabetic.py
More file actions
27 lines (24 loc) · 888 Bytes
/
Monoalphabetic.py
File metadata and controls
27 lines (24 loc) · 888 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
import random
import letterfrequencychart
alphabet = "abcdefghijklmnopqrstuvwxyz"
def make_mono_sub(message):
ciphertext = ""
new_alphabet = ""
message = message.lower()
random_letter = random.randint(0,25)
while len(new_alphabet) < 26:
if alphabet[random_letter] not in new_alphabet:
new_alphabet = new_alphabet + alphabet[random_letter]
random_letter = random.randint(0, 25)
else:
random_letter = random.randint(0,25)
for le in message:
if le in alphabet:
messagenum = alphabet.find(le)
ciphertext = ciphertext + new_alphabet[messagenum]
else:
ciphertext = ciphertext + le
print (ciphertext)
x = letterfrequencychart.frequency_chart(ciphertext)
print (x[1])
return [ ciphertext + "\n" + x[0], message + "\nAlphabet used: " + new_alphabet]