-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_02_a_AdditiveCipher.py
47 lines (38 loc) · 1.02 KB
/
A_02_a_AdditiveCipher.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
# Author: Devashish Roy, Roll No: 2024PGCSIS08
# Assignment No: 02
# Implementation of Classical Substitution Ciphers
# a) Additive (Ceasar) Cipher
# b) Multiplicative Cipher
# c) Affine Cipher
# d) Playfair Cipher
# e) Hill Cipher
# Additive (Ceasar) Cipher
def encryption(plaintext, key) :
ciphertext = ""
for x in plaintext:
if(x == " "):
cipherChar = " "
else :
cipherChar = chr(((ord(x) - 97 + key) % 26)+65)
ciphertext += cipherChar
return ciphertext
def decryption(ciphertext, key) :
plaintext = ""
for x in ciphertext:
if(x == " "):
plainChar = " "
else:
plainChar = chr(((ord(x) - 65 - key) % 26) + 97)
plaintext += plainChar
return plaintext
def main():
key = 81
sampletext = input()
cipher = encryption(sampletext, key)
print("Cipher Text is: ")
print(cipher)
plain = decryption(cipher, key)
print("Deciphered Text is: ")
print(plain)
if __name__ == "__main__":
main()