VIGENERE CIPHER
#include<stdio.h>
#include<string.h>
#define max 30
char key[max],CT[max];
int k;
void enterKey(void);
void senderText(void);
void receiverText(void);
void enterKey()
{
printf("Enter the key: ");
scanf("%s",key);
//printf("key: %s",key);
k=strlen(key);
//printf("\nKey length: %d",k);
}
void senderText()
{
printf("\n\n\t*****SENDER-ENCODING*****\n");
char text[max];
int t,i,j=0;
int aci_ct[max];
printf("\nEnter the text: ");
scanf("%s",text);
//printf("Entered text is: %s",text);
t=strlen(text);
//printf("\nText length: %d",t);
enterKey();
for(i=0;i<t;i++)
{
aci_ct[i]=(((text[i]-97)+(key[j]-97))%26)+97;
j++;
if(j>=k)
j=0;
}
for(i=0;i<t;i++)
{
CT[i]=aci_ct[i];
}
printf("\n\tCipher Text: %s",CT);
}
void receiverText()
{
printf("\n\n\t*****RECEIVER-DECODING*****\n");
char PT[max];
int t,i,j=0;
int aci_pt[max];
t=strlen(CT);
//printf("\nText length: %d",t);
for(i=0;i<t;i++)
{
aci_pt[i]=(((CT[i]-97)-(key[j]-97)+26)%26)+97;
j++;
if(j>=k)
j=0;
}
for(i=0;i<t;i++)
{
PT[i]=aci_pt[i];
}
printf("\n\tPlain Text: %s",PT);
}
main()
{
printf("\n\n\t\t\t.........VIGENERE-CIPHER.........\n");
senderText();
receiverText();
printf("\n\n");
}
Output:
.........VIGENERE-CIPHER.........
*****SENDER-ENCODING*****
Enter the text: welcometounicoderz
Enter the key: unicoderz
Cipher Text: qrtecpiknoaqecgiiy
*****RECEIVER-DECODING*****
Plain Text: welcometounicoderz
.........VIGENERE-CIPHER.........
*****SENDER-ENCODING*****
Enter the text: welcometounicoderz
Enter the key: unicoderz
Cipher Text: qrtecpiknoaqecgiiy
*****RECEIVER-DECODING*****
Plain Text: welcometounicoderz
0 Comments