Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Encryption Decryption/Vigenere Cipher/Matrix.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Encryption Decryption/Vigenere Cipher/ProblemStatement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h3 align="justify"><b>What is Vigenere Cipher?</b><br></h3>
<p align="justify">The vigenere cipher is an algorithm that is used to encrypting and decrypting the text. The vigenere cipher is an algorithm of encrypting an alphabetic text that uses a series of interwoven caesar ciphers. It is based on a keyword's letters. It is an example of a polyalphabetic substitution cipher. This algorithm is easy to understand and implement. This algorithm was first described in 1553 by Giovan Battista Bellaso. It uses a Vigenere table or Vigenere square for encryption and decryption of the text. The vigenere table is also called the tabula recta. </p>

When the vigenere table is given, the encryption and decryption are done using the vigenere table (26 * 26 matrix).

<img src = "Matrix.JPG" width="520" height="420" />

<h3 align="justify">Encryption:</h3>

There are 2 inputs:

<ul>
<li>Plaintext: Text that is to be encrypted</li>
<li>Key: key used for encryption</li>
</ul>
<p align="justify">The key is first repeated as long as the length of the key is not equal to the given plain text. Then the first letter of the plaintext is combined with the first letter of the key and the equivalent cell of the matrix is taken. The work in the cell is the encrypted letter. The same procedure is repeated over the entire plaintext to encrypt it.</p>

Ref: https://www.javatpoint.com/vigenere-cipher



75 changes: 75 additions & 0 deletions Encryption Decryption/Vigenere Cipher/Vigenère Cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import numpy as np
import pandas as pd
######################### CREATING THE CYPHER MATRIC#################################
alp=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',]
list2=[]
z=0
for i in range(26):
list1=[]
for k in range(26):
if(i==26):
z=i
i=0
list1.append(alp[i])
i=i+1
i=z
list2.append(list1)
df=pd.DataFrame(list2,columns=alp, index=alp)
#print(df)
#####################################################################################
#row=[]
#col=[]
#list5=[]
#wordlist_final=[]
def cipher(keyword):
list3=[]
list4=[]
z=0
count=1
plaintext=input('Enter plaintext:')
len_text=len(plaintext)
len_word=len(keyword)

for i in range(len_text):
for j in range(len_word):
if(count<=len_text):
list3.append(keyword[j])
count+=1

#for finding the cyphered word

for i in range(len_text):
list4.append(df[plaintext[i]][list3[i]])
word=''.join(list4)
print('Cyphered word is:',word)
return

def decipher(keyword):
inp=input('Enter the word to be decyphered:')
list6=[]
list5=[]
count=1
for i in range(len(inp)):
for j in range(len(keyword)):
if(count<=len(inp)):
list5.append(keyword[j])
count+=1
for i in range(len(list5)):
for j in range(26):
if(str(df[list5[i]][alp[j]])==str(inp[i])):
list6.append(alp[j])
og_list=''.join(list6)
print('The deciphered word is:',og_list)
return

################################## MAIN CODE STARTS HERE ##########################
keyword=input('Enter the key:')
variable=int(input('Menu driven code for Vigenère Cipher\nChoose any of the following:\n1.Cipher\n2.De-Cipher\n'))
if(variable==1):
cipher(keyword)
elif(variable==2):
decipher(keyword)
else:
print('Wrong input, try again!')