File tree 2 files changed +72
-0
lines changed
2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ # function to apply algo of vernam cipher
3
+ def vernam (cipher_text ,key ):
4
+
5
+ # convert into lower cases and remove spaces
6
+ cipher_text = cipher_text .lower ()
7
+ key = key .lower ()
8
+ cipher_text = cipher_text .replace (" " ,"" )
9
+ key = key .replace (" " ,"" )
10
+
11
+ plain_text = ""
12
+
13
+ # iterating through the length
14
+ for i in range (len (cipher_text )):
15
+ k1 = ord (cipher_text [i ])- 97
16
+ k2 = ord (key [i ])- 97
17
+ s = chr ((((k1 - k2 )+ 26 )% 26 )+ 97 )
18
+ plain_text += s
19
+ print ("Decrypted message is: " ,plain_text )
20
+
21
+
22
+ plain_text = input ("Enter the message to be decrypted: " )
23
+ key = input ("Enter the one time pad: " )
24
+ vernam (plain_text ,key )
25
+
26
+
27
+ '''
28
+ ----------OUTPUT----------
29
+ Enter the message to be decrypted: wioqfidxqam
30
+ Enter the one time pad: Quantum king
31
+ Decrypted message is: goodmorning
32
+ >>>
33
+ '''
Original file line number Diff line number Diff line change
1
+
2
+ # function to apply algo of vernam cipher
3
+ def vernam (plain_text ,key ):
4
+
5
+ # convert into lower cases and remove spaces
6
+
7
+ plain_text = plain_text .replace (" " ,"" )
8
+ key = key .replace (" " ,"" )
9
+ plain_text = plain_text .lower ()
10
+ key = key .lower ()
11
+
12
+ # conditional statements
13
+ if (len (plain_text )!= len (key )):
14
+ print ("Lengths are different" )
15
+
16
+ else :
17
+ cipher_text = ""
18
+
19
+ # iterating through the length
20
+ for i in range (len (plain_text )):
21
+ k1 = ord (plain_text [i ])- 97
22
+ k2 = ord (key [i ])- 97
23
+ s = chr ((k1 + k2 )% 26 + 97 )
24
+ cipher_text += s
25
+ print ("Enrypted message is: " ,cipher_text )
26
+
27
+
28
+ plain_text = input ("Enter the message: " )
29
+ key = input ("Enter the one time pad: " )
30
+ vernam (plain_text ,key )
31
+
32
+
33
+ '''
34
+ ----------OUTPUT----------
35
+ Enter the message: Good morning
36
+ Enter the one time pad: Quantum king
37
+ Encrypted message is: wioqfidxqam
38
+ >>>
39
+ '''
You can’t perform that action at this time.
0 commit comments