-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiftCipher.py
More file actions
executable file
·46 lines (36 loc) · 1.11 KB
/
shiftCipher.py
File metadata and controls
executable file
·46 lines (36 loc) · 1.11 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
#!/usr/bin/python3
print(" ^", " ^")
print(" / \ ", " / \ ")
print(" / \ ", " / \ ")
print(" / \ ", " / \ ")
print(" / \ ", " / \ ")
print("___________", "___________")
print("WELCOME TO MIKAH'S SHIFT CIPHER")
print("")
print("")
print("1. Encrypt Text")
print("2. Decrypt Text")
choice = int(input("Select choice: "))
alphabets = ["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']
text = input("Enter text here >>> ")
text = text.upper()
K = input("Enter key here >>> ")
result = []
# encrypt text
def encrypt():
Y = index
i = (int(K) + int(Y)) % 26
result.append(alphabets[i])
# decrypt text
def decrypt():
Y = index
i = (int(Y) - int(K)) % 26
result.append(alphabets[i])
for x in text:
index = alphabets.index(x)
if(choice == 1): encrypt()
else: decrypt()
# convert list to string and print
if(choice == 1): print("The ciphertext is >>" , ''.join(result))
# convert list to string and plaintext to lowercase
else: print("The plaintext is >>" , ''.join(result).lower())