Let us take a look at what is going to be discussed in this blog: Watch this Cybersecurity Course video:Vigenere Cipher is an encryption and decryption algorithm. It is a type of polyalphabetic substitution cipher, which means that the cipher alphabet is changed regularly during the encryption process. Due to this, the cipher becomes less vulnerable to cryptanalysis. The Vigenere Cipher was developed in 1585 by Blaise de Vigenere. He used a Vigenere table or square to encode messages. Let us now take a look at what the Vigenere table is. It table consists of all the alphabets written 26 times in different rows. Each alphabet in every subsequent row and column is shifted cyclically to the left. This generates 26 Caesar Ciphers. Different alphabets from different rows are used at different points in the encryption process. The alphabet chosen depends on the method used for encryption. There are three main Vigenere Cipher Methods:
Let’s talk about each of these in detail. The Autokey Method makes use of the Vigenere Cipher table to encrypt and decrypt the plaintext. In this method, the priming key is just one letter. Vigenere Cipher EncoderThe first step in the autokey method is to decide on a priming key. Both sender and receiver have to agree on this key. The priming key is the single alphabet that is added to the beginning of messages to help make the key. The sender encrypts the message starting with writing the first letter of the plaintext on one line and the priming key under it. The rest of the plaintext is written as is, shifted one place to the right.
The steps involved are as follows:
Vigenere Cipher DecoderThe below-mentioned steps are followed to decipher the ciphertext:
SecurityThe autokey method for Vigenere Cipher is not very secure. We can only use 26 keys, which makes breaking the code fairly easy. Anyone who wants to break the code needs to only try each alphabet as the priming key before they make a sensible message out of it. This can be done manually in a short time. Check out this Cybersecurity Tutorial to learn Cybersecurity Essentials! The Keyword Method also uses the Vigenere Cipher table to encrypt and decrypt the plaintext. In this method, the key is usually more than one letter. Vigenere Cipher EncoderThe Vigenere Cipher encoder is similar to the autokey method. The difference is that instead of using just one priming key, the Vigenere Cipher encoder uses a keyword that is more than one letter. So, there are endless possibilities of a possible keyword. The steps involved are as follows:
For this example, let us use the phrase ALL IS WELL and the keyword as CAKE.
Vigenere Cipher DecoderTo decode this, the following steps can be followed:
SecurityThis method is much more secure than the autokey method, but that does not mean it is not vulnerable. The cipher is more secure with longer keywords. If the Vigenere table is not available or accessible, for whatever reason, then encryption and decryption processes can be carried out using the Vigenere algebraic formula. For this method to work, the alphabets have to be converted into numbers (0-25). The encryption formula is: The decryption formula is: Di = (Ei – Ki) mod 26Where E is the encipher, D is the decipher, P is the plaintext, and K is the key. If the value of Di is ever negative, 26 is added to that value. For example, let us take our plaintext to be CYBER SECURITY. So, The key can be BEST. Remember, if the value of Di is ever negative, 26 is added to that value. Let us take a look at what the Vigenere Cipher calculator will look like as Python code. #Python code to implement # Vigenere Cipher # This function generates the # key in a cyclic manner until # it's length isn't equal to # the length of original text def generateKey(string, key): key = list(key) if len(string) == len(key): return(key) else: for i in range(len(string) - len(key)): key.append(key[i % len(key)]) return("" . join(key)) # This function returns the # encrypted text generated # with the help of the key def cipherText(string, key): cipher_text = [] for i in range(len(string)): x = (ord(string[i]) + ord(key[i])) % 26 x += ord('A') cipher_text.append(chr(x)) return("" . join(cipher_text)) # This function decrypts the # encrypted text and returns # the original text def originalText(cipher_text, key): orig_text = [] for i in range(len(cipher_text)): x = (ord(cipher_text[i]) - ord(key[i]) + 26) % 26 x += ord('A') orig_text.append(chr(x)) return("" . join(orig_text)) # Driver code if __name__ == "__main__": string = "CYBERSECURITY" keyword = "BEST" key = generateKey(string, keyword) cipher_text = cipherText(string,key) print("Ciphertext :", cipher_text) print("Original/Decrypted Text :", originalText(cipher_text, key))OutputCiphertext: DCTXSWWVVVAMZ Original or Decrypted Text: CYBERSECURITYVigenere Cipher is a simple polyalphabetic substitution method that goes from a simple to advanced method. The Vigenere Square or Table is an important tool used in this Cipher. You can use this cipher in three different ways as per your needs. All the three methods involve different steps. The autokey method is the least secure method. Even though the keyword method has its vulnerabilities, it is more secure than the autokey method. The Python Code method is relatively the most secure method. |