Write a C Program to Implement the Vigenere Fair Substitution Technique

Aim:

To write a C Program to Implement the Simple Substitution Technique Named Vigenere Fair.

Algorithm:

  1. Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple form of polyalphabetic substitution. A polyalphabetic cipher is any cipher based on substitution, using multiple substitution alphabets .The encryption of the original text is done using the Vigenère square or Vigenère table.
  2. The table consists of the alphabets written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar Ciphers.
  3. At different points in the encryption process, the cipher uses a different alphabet from one of the rows.
  4. The alphabet used at each point depends on a repeating keyword.
  5. End.

Program:

#include<stdio.h>
#include<stdlib.h>
char matrix[26][26];
void constmatrix()
{
int i=0,j=0,ch=0,h=0;
for(i=0;i<26;i++)
{
ch=h++;
for(j=0;j<26;j++)
{
matrix[i][j]=ch;

if(ch==25)
ch=-1;

ch++;
}
}
}
int main()
{
char mes[100],k[100];
int i=0,j=0;
constmatrix();
printf("ENTER THE PLAIN TEXT :\n");
scanf("%s",mes);
printf("ENTER THE KEY :\n");
scanf("%s",k);
int mi=0,ki=0;
while(mes[i]!='\0'){ i++;}
mi=i,i=0;
while(k[i]!='\0'){ i++;}
ki=i;
int lk=i;
i=0;
if(mi!=ki)
{
while(ki<mi)
{
k[ki++]=k[i];
if(lk-1==i)
i=-1;
i++;
}
}
char en[100];
char de[100];
i=0;
printf("ENCRPTED MESSAGE = ");
while(mes[i]!='\0')
{
int c=mes[i]-97;
int r=k[i]-97;
en[i]=97+matrix[c][r];
printf("%c",en[i++]);
}
i=0;
printf("\nDECRPTED MESSAGE = ");
while(en[i]!='\0')
{
de[i]=(((en[i]-k[i])+26)%26)+97;
i++;
}
printf("%s",de);
return 0;
}

Execution:

Input:
anderson kil

Output:

ENTER THE PLAIN TEXT :
ENTER THE KEY :
ENCRPTED MESSAGE = kvoozdyv
DECRPTED MESSAGE = anderson

Result:

Thus implementation of the Vigenere Fair program was executed Successfully.

Leave a Comment