Javatpoint Logo
Javatpoint Logo

Vigenere Cypher Program in C

In this article, we will discuss the Vigenere Cypher Program in C.

Introduction:

The text can be encrypted and decrypted using the Vigenere cypher algorithm. Caesar cyphers are related to the Vigenere cipher. It is a technique for encrypting alphabetic text. The letter structure of a keyword serves as its basis. Polyalphabetic characters are used in this substitution cypher. It is easy to comprehend and apply this algorithm. This algorithm was first introduced in 1553 by Giovan Battista Bellaso.

Algorithm:

1. Enter the term and the plaintext.

2. To make the keyword the length of the plaintext, repeat it.

3. Implement modular addition of the repeated keyword and the plaintext when encrypting data.

Ci = Pi + Ki(mod m)

Where Ci is the cipher text,

Pi is the plaintext,

Ki is the repeating keyword, and 'm' is the length of the alphabet.

4. Decryption: Perform modular subtraction of key phrases from the cipher text.

Pi = Ci - Ki

(mod m)

5. Display the encrypted and decrypted message as well.

Example:

Now, let's take a program to understand how we can use the Vigenere Cypher method in C.

Working mechanism:

  • The user is given a menu with the options to encrypt, decrypt, or exit the program.
  • If a user chooses to "Encrypt":

The user is asked to enter a plaintext message and a key by the program.

  • After that, the Vigenere encryption algorithm is used to construct the encrypted character by iteratively going through each character in the plaintext and the key.
  • The cypher text is printed using the encoded characters.
  • Whenever a user chooses "Decrypt":

The software asks the user to enter a key and a ciphertext.

  • In order to produce the decrypted character, the Vigenère decryption formula is applied iteratively to each character in the ciphertext and the key.
  • The original plaintext of the decrypted characters is printed.
  • The user can repeatedly execute encryption and decryption processes because the program loops until the user chooses the "Exit" option.

Output:

Some expected output like:

1. Encrypt
2. Decrypt
3. Exit

Enter your option: 1

Enter the plaintext (up to 128 characters): Hello World
Enter the key (up to 16 characters): KEY

Cipher Text: RIJVS UYVJN

1. Encrypt
2. Decrypt
3. Exit

Enter your option: 2

Enter the ciphertext: RIJVS UYVJN
Enter the key: KEY

Deciphered Text: HELLO WORLD

1. Encrypt
2. Decrypt
3. Exit

Enter your option: 3

Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA