-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path001.py
More file actions
45 lines (24 loc) · 917 Bytes
/
001.py
File metadata and controls
45 lines (24 loc) · 917 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
33
34
35
36
37
38
39
40
41
42
43
44
import string
#import clear
alphabet = list(string.ascii_lowercase) + list(string.ascii_lowercase)
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
#clear()
shift = int(input("Type the shift number:\n"))
# code to encode the desired word
def encrypt(text, shift):
encrypted_word = ""
for i in range(len(text)):
encrypted_word = encrypted_word + alphabet[alphabet.index(text[i]) + shift]
print("The encoded word is", encrypted_word)
# code to decode the encrypted word
def decrypt(text, shift):
decrypt_word = ""
for i in range(len(text)):
decoding = alphabet[alphabet.index(text[i]) - shift]
decrypt_word += decoding
print("The decoded text is", decrypt_word)
if direction == "encode":
encrypt(text, shift)
elif direction == "decode":
decrypt(text, shift)