-
Notifications
You must be signed in to change notification settings - Fork 2
/
Caesar.py
50 lines (32 loc) · 869 Bytes
/
Caesar.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
50
str = "abcd"
key = 25
result = ""
count1 = 0
leng1 = len(str)
while count1 != leng1:
char = str[count1]
# Encrypt uppercase characters
if (char.isupper()):
result += chr((ord(char) + key - 65) % 26 + 65)
# Encrypt lowercase characters
elif (char.islower()):
result += chr((ord(char) + key - 97) % 26 + 97)
else:
result += char
count1 = count1 + 1
print(result)
leng = len(result)
count = 0
result1 = ""
while count != leng:
char = result[count]
# For Uppercase
if (char.isupper()):
result1 += chr((ord(char) - key - 65) % 26 + 65)
# Encrypt lowercase characters
elif (char.islower()):
result1 += chr((ord(char) - key - 97) % 26 + 97)
else:
result1 += char
count = count + 1
print(result1)