-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathvigenere_decryption.py
51 lines (39 loc) · 1.34 KB
/
vigenere_decryption.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
51
import string
main=string.ascii_lowercase
def conversion(cipher_text,key):
index=0
plain_text=""
# convert into lower case
cipher_text=cipher_text.lower()
key=key.lower()
for c in cipher_text:
if c in main:
# to get the number corresponding to the alphabet
off=ord(key[index])-ord('a')
positive_off=26-off
decrypt=chr((ord(c)-ord('a')+positive_off)%26+ord('a'))
# adding into plain text to get the decrypted messag
plain_text+=decrypt
# for cyclic rotation in generating key from keyword
index=(index+1)%len(key)
else:
plain_text+=c
print("cipher text: ",cipher_text)
print("plain text (message): ",plain_text)
cipher_text=input("Enter the message to be decrypted: ")
key=input("Enter the key for decryption: ")
# calling function
conversion(cipher_text,key)
'''
----------OUTPUT----------
Enter the message to be decrypted: he xzsdi zu brxh io etvuvni
Enter the key for decryption: awesome world
cipher text: he xzsdi zu brxh io etvuvni
plain text (message): hi there my name is abhiram
>>>
'''
'''
Took help from:
1. https://www.youtube.com/watch?v=FAbkLSktxWQ
2. https://www.youtube.com/watch?v=zLbZM_MA3qE&t=575s
'''