-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCaesarCipher.py
More file actions
61 lines (49 loc) Β· 2.72 KB
/
CaesarCipher.py
File metadata and controls
61 lines (49 loc) Β· 2.72 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!bin/python3
import sys
#GLOBAL VARIABLES
UID = 119222119
Last_Name = 'Sinha'
First_Name = 'Aaryash Raj'
#ENCRYPTION CODE SNIPPET
def caesar_str_enc(s, shift):
s = s.upper()
encrypted = ""
for j in s:
if j.isupper():
encrypted += chr((ord(j) + shift - 65) % 26 + 65)
else:
encrypted += j
return encrypted
#DECRYPTION CODE SNIPPET
def caesar_str_dec(s, shift):
s = s.upper()
decrypted = ""
for j in s:
if j.isupper():
decrypted += chr((ord(j) - shift - 65) % 26 + 65)
else:
decrypted += j
return decrypted
#MAIN FUNCTION
if __name__ == "__main__":
#BANNER
print("\n")
print(" βββββββ ββββββ ββββββββββββββββ ββββββ βββββββ βββββββββββββββββ βββ ββββββββββββββββββ")
print(" ββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββ βββββββββββββββββββ")
print(" βββ ββββββββββββββ ββββββββββββββββββββββββ βββ βββββββββββββββββββββββββ ββββββββ")
print(" βββ ββββββββββββββ ββββββββββββββββββββββββ βββ ββββββββββ ββββββββββββββ ββββββββ")
print(" βββββββββββ ββββββββββββββββββββββ ββββββ βββ ββββββββββββββ βββ ββββββββββββββ βββ")
print(" ββββββββββ ββββββββββββββββββββββ ββββββ βββ βββββββββββββ βββ ββββββββββββββ βββ")
#working code
selection = input("\n\tHi! Select an option below \n\t1. Encrypt a string\n\t2. Decrypt a string\n\n")
if selection == "1":
s = input("\tEnter the string to encrypt: ").replace(" ","")
shift = int(input("\tEnter the shift value: "))
encstr = caesar_str_enc(s, shift)
print("\tEncrypted String: ",encstr)
elif selection == "2":
s = input("\tEnter the string to decrypt: ").replace(" ","")
shift = int(input("\tEnter the shift value: "))
decstr = caesar_str_dec(s, shift)
print("\tDecrypted String: ",decstr)
else: sys.exit()