-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.py
More file actions
37 lines (23 loc) · 919 Bytes
/
encryption.py
File metadata and controls
37 lines (23 loc) · 919 Bytes
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
def encrypt(text, s):
result = ''
# transverse the plain text
for i in range(len(text)):
char = text[i]
# Encrypt uppercase characters in plain text
if char.isupper():
result += chr((ord(char) + s - 65) % 26 + 65)
elif char.islower():
# Encrypt lowercase characters in plain text
result += chr((ord(char) + s - 97) % 26 + 97)
elif ord(char) <= 64 and ord(char) >= 32:
# Encrypt common special characters
result += chr((ord(char) + s - 32) % 33 + 32)
else:
# Rest all symbols remain the same
result += char
return result
text = input('Enter your text : ')
s = int(input('Enter shift pattern : '))
print ('Plain text : ' + text)
print ('Shift pattern : ' + str(s))
print ('Cipher : ' + encrypt(text, s))