-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaintext_attack.py
More file actions
34 lines (30 loc) · 1.02 KB
/
plaintext_attack.py
File metadata and controls
34 lines (30 loc) · 1.02 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
cipher = input("Enter the text encrypted using Caeser's cipher: ")
original = input("Enter the plain text of the first world/letter: ")
og_len = len(original)
sub_cipher = cipher[:og_len]
for i in range(0, 28):
temp = ''
string = original[0:og_len]
for char in string:
if char == ' ':
temp = temp + char
elif char.isupper():
temp = temp + chr((ord(char) + i - 65) % 26 + 65)
else:
temp = temp+ chr((ord(char) + i - 97) % 26 + 97)
if (temp == sub_cipher):
print ("Shift towards right.\nKey= "+str(i))
break
for i in range(0, 28):
temp = ''
string = original[0:og_len]
for char in string:
if char == ' ':
temp = temp + char
elif char.isupper():
temp = temp + chr((ord(char) - i - 65) % 26 + 65)
else:
temp = temp + chr((ord(char) - i - 97) % 26 + 97)
if (temp == sub_cipher):
print("Shift towards left.\nKey= " + str(i))
break