-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.py
More file actions
41 lines (38 loc) · 1.34 KB
/
Copy pathdecrypt.py
File metadata and controls
41 lines (38 loc) · 1.34 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
#CAESAR CIPHER DECRYPTION
inputString = input("Enter string to decrypt: ")
numberOfShifts = int(input("Enter number of shifts: "))
decryptedString = ""
upperLimit = 0
lowerLimit = 0
length = len(inputString)
#CORE Logic
for i in range(0, length):
alphabet = inputString[i]
alphabetASCII = ord(alphabet)
calculatedASCII = 0
if(alphabetASCII >= 97):
#transform small letters
lowerLimit = 97
upperLimit = 122
calculatedASCII = alphabetASCII - numberOfShifts
if(calculatedASCII < lowerLimit):
calculatedASCII = lowerLimit - calculatedASCII
calculatedASCII = (upperLimit + 1) - calculatedASCII
decryptedString += chr(calculatedASCII)
else:
decryptedString += chr(calculatedASCII)
elif (alphabetASCII >= 65 and alphabetASCII <= 90):
#transform CAPITAL letters
lowerLimit = 65
upperLimit = 90
calculatedASCII = alphabetASCII - numberOfShifts
if(calculatedASCII < lowerLimit):
calculatedASCII = lowerLimit - calculatedASCII
calculatedASCII = (upperLimit + 1) - calculatedASCII
decryptedString += chr(calculatedASCII)
else:
decryptedString += chr(calculatedASCII)
elif (alphabet == " ") :
decryptedString += " "
#printing result
print(decryptedString)