-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.py
40 lines (38 loc) · 1.26 KB
/
encrypt.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
#CAESAR CIPHER ENCRYPTION
inputString = input("Enter string to encrypt: ")
numberOfShifts = int(input("Enter number of shifts: "))
encryptedString = ""
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 > upperLimit):
calculatedASCII -=upperLimit
calculatedASCII += lowerLimit - 1
encryptedString += chr(calculatedASCII)
else:
encryptedString += chr(calculatedASCII)
elif (alphabetASCII >= 65 and alphabetASCII <= 90):
#transform CAPITAL letters
lowerLimit = 65
upperLimit = 90
calculatedASCII = alphabetASCII + numberOfShifts
if(calculatedASCII > upperLimit):
calculatedASCII -=upperLimit
calculatedASCII += lowerLimit - 1
encryptedString += chr(calculatedASCII)
else:
encryptedString += chr(calculatedASCII)
elif (alphabet == " "):
encryptedString += " "
#printing result
print(encryptedString)