diff --git a/Encryption Decryption/Vigenere Cipher/Matrix.JPG b/Encryption Decryption/Vigenere Cipher/Matrix.JPG new file mode 100644 index 0000000..8df7ea9 Binary files /dev/null and b/Encryption Decryption/Vigenere Cipher/Matrix.JPG differ diff --git a/Encryption Decryption/Vigenere Cipher/ProblemStatement.md b/Encryption Decryption/Vigenere Cipher/ProblemStatement.md new file mode 100644 index 0000000..952c008 --- /dev/null +++ b/Encryption Decryption/Vigenere Cipher/ProblemStatement.md @@ -0,0 +1,21 @@ +

What is Vigenere Cipher?

+

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.

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

Encryption:

+ +There are 2 inputs: + + +

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.

+ +Ref: https://www.javatpoint.com/vigenere-cipher + + + diff --git "a/Encryption Decryption/Vigenere Cipher/Vigen\303\250re Cipher.py" "b/Encryption Decryption/Vigenere Cipher/Vigen\303\250re Cipher.py" new file mode 100644 index 0000000..c52a5ad --- /dev/null +++ "b/Encryption Decryption/Vigenere Cipher/Vigen\303\250re Cipher.py" @@ -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!') + +