-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar cipher.py
More file actions
17 lines (15 loc) · 906 Bytes
/
caesar cipher.py
File metadata and controls
17 lines (15 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',' ','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("Type 'encode' or 'decode' to do whatever you want :\n")
text = input(f"Enter the text you want to {direction}: ")
shift = int(input("Enter the shift amount"))
def cipher(starttext,shiftamount,cipher_direction):
endtext = ""
if cipher_direction == "decode":
shiftamount *= (-1)
for letter in starttext:
position = alphabet.index(letter)
new_position = position + shiftamount
letter = alphabet[new_position]
endtext += letter
print(f"the {cipher_direction}d result is: {endtext}")
cipher(starttext = text, shiftamount = shift, cipher_direction = direction)