-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cypher.py
More file actions
52 lines (42 loc) · 1.22 KB
/
caesar_cypher.py
File metadata and controls
52 lines (42 loc) · 1.22 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# simple implementation of caesar cypher
a=ord('a')
alphabet = [chr(i) for i in range(a,a+26)]
def print_menu():
print("\n\n\n")
print("------ CAESAR CYPHER ------")
print("e - Encrypt")
print("d - Decrypt")
print("q - Quit")
def encrypt(word, shift):
encrypt = []
for letter in word:
encrypt.append(ord(letter) + shift % 26)
encrypted_list = [chr(i) for i in encrypt]
encrypted_word = "".join(encrypted_list)
return encrypted_word
def decrypt(word, shift):
decrypt = []
for letter in word:
decrypt.append(ord(letter) - shift % 26)
decrypted_list = [chr(i) for i in decrypt]
decrypted_word = "".join(decrypted_list)
return decrypted_word
print("hello >> 6")
enc = encrypt("hello", 6)
dec = decrypt(enc, 6)
print(enc)
print(dec)
option = ""
while option != "q":
print_menu()
option = input("Option: ")
if option == "e":
word = input("Word: ")
shift = int(input("Shift: "))
encrypted = encrypt(word, shift)
print(f"Result: {encrypted}")
if option == "d":
mistery = input("Mistery: ")
shift = int(input("Shift: "))
decrypted = decrypt(mistery, shift)
print(f"Word: {decrypted}")