-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.py
More file actions
47 lines (36 loc) · 1.26 KB
/
cipher.py
File metadata and controls
47 lines (36 loc) · 1.26 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
def main():
while True:
print("Would you like to encrypt or decrypt a message?")
mode = input()
if mode == 'encrypt':
encryption_cipher()
if mode == 'decrypt':
decryption_cipher()
else:
print("You must type encrypt or decrypt")
continue
def encryption_cipher():
text = input("What is your plaintext? ")
shift = int(input("What is your key shift?"))
cipherText = ""
for ch in text:
if ch.isalpha():
stayInAlphabet = ord(ch) + shift
if stayInAlphabet > ord('z'):
stayInAlphabet -= 26
finalLetter = chr(stayInAlphabet)
cipherText += finalLetter
print ("Your ciphertext is: ", cipherText)
def decryption_cipher():
encryption=input("Enter message for decryption")
encryption_shift=int(input("Enter your decryption key shift"))
cipherText1 = ""
for c in encryption:
if c.isalpha():
stayInAlphabet1 = ord(c) - encryption_shift
if stayInAlphabet1 > ord('z'):
stayInAlphabet1 += 26
finalLetter1 = chr(stayInAlphabet1)
cipherText1 += finalLetter1
print ("Your ciphertext is: ", cipherText1)
main()