-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar.py
More file actions
32 lines (27 loc) · 981 Bytes
/
caesar.py
File metadata and controls
32 lines (27 loc) · 981 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
alphabets = " abcdefghijklmnopqrstuvwxyz"
def encrypt_casear(plaint_text, key):
cipher_text = ''
for i in plaint_text:
index = (alphabets.find(i) + key) % len(alphabets)
cipher_text = cipher_text + alphabets[index]
return cipher_text
def decrypt_caesar(cipher_text, key):
plaint_text = ''
for i in cipher_text:
index = (alphabets.find(i) - key) % len(alphabets)
plaint_text = plaint_text + alphabets[index]
return plaint_text
def crack_caesar(cipher_text):
for key in range(len(alphabets)):
plaint_text = ''
for i in cipher_text:
index = (alphabets.find(i) - key) % len(alphabets)
plaint_text = plaint_text + alphabets[index]
print("Key = ", key , " Decrypted msg = " , plaint_text)
def main():
test = "i am so good"
test = test.lower()
print(encrypt_casear(test, 3))
print(crack_caesar("lcdpcvrcjrrg"))
if __name__ == '__main__':
main()