forked from ndleah/python-mini-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextEncryptor.py
49 lines (36 loc) · 1.33 KB
/
TextEncryptor.py
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
#This application uses the ceaser cipher in order to encrypt text
def encrypt(text):
result = ""
for i in range(len(text)):
char = text[i]
if char.isupper():
result += chr((ord(char) + key - 65) % 26 + 65)
elif char.islower():
result += chr((ord(char) + key - 97) % 26 + 97)
else:
result += char
return result
def decrypt(text):
result = ""
for i in range(len(text)):
char = text[i]
if char.isupper():
result += chr((ord(char) - decryptkey - 65) % 26 + 65)
elif char.islower():
result += chr((ord(char) - decryptkey - 97) % 26 + 97)
else:
result += char
return result
choice = int(input("Would you like to encrypt some text or decrypt some text? Choose 1 to encrypt and 2 to decrypt "))
if choice == 1:
text = input("Input the text you want to encrypt: \n")
key = int(input("Input the key for the encryption *NOTE! This is using the Ceaser cipher \n"))
result = encrypt(text)
print(result)
elif choice == 2:
text = input("Input the text you want to decrypt: \n")
decryptkey = int(input("Input the key for the decryption *NOTE! This is using the Ceaser cipher \n"))
result = decrypt(text)
print(result)
else:
print("idk")