-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt_decrypt.py
31 lines (27 loc) · 1013 Bytes
/
encrypt_decrypt.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
def encryptText(input_text, key):
input_text = input_text.upper()
result = ''
for letter in input_text:
ascii_value = ord(letter)
if (ord("A") > ascii_value) or (ascii_value > ord("Z")):
result += letter
else:
key_value = ascii_value + key
if not((ord("A")) < key_value < ord("Z")):
key_value=ord("A") + (key_value-ord("A")) % (ord("Z")-ord("A")+1)
result += str(chr(key_value))
return result
def main():
print("Please enter text to scramble: ")
try:
user_input = input()
scrambled_result = encryptText(user_input,10)
print(f"Result: {scrambled_result}")
print("To un-scramble, press enter again")
input()
unscrambled_result = encryptText(scrambled_result,-10)
print(f"Result: {unscrambled_result}")
except UnicodeDecodeError:
print("Sorry: Only ASCII Characters are supported")
if __name__=="__main__":
main()