#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
char input[20],cipher[20];
// Public Numbers p and g...
int i,p=23, g=9;
// 1st person's private key
int a=4;
// 2nd person's private key
int b=3;
// 1st person computes public value...
double x = (int)pow(g,a)%p;
// 2nd person computes public value...
double y = (int)pow(g,b)%p;
// 1st person creates the Secret key for himself
double encKey1 = (int)pow(y,a)%p;
int encKey = (int)encKey1;
// 2nd person creates the Secret key for himself
double decKey1 = (int)pow(x,b)%p;
int decKey = (int)decKey1;
// Vernam Cipher
printf("Enter Text : ");
scanf("%s",input);
printf("\nEncrypted : ");
for(i=0;i<strlen(input);i++)
{
cipher[i]=input[i]^encKey;
printf("%c",cipher[i]);
}
cipher[i]='\0';
// 2nd person decrypts the ciphertext using decKey
printf("\nDecrypted : ");
for(i=0; i< strlen(cipher); i++ )
{
input[i] = (int)cipher[i]^decKey; // using decKey
printf("%c",input[i]);
}
}
/*output */
{
if(no[i]==j)
{
for(z=1;z<10;z++)
{
if(isalpha(mat[z][j]))
{
printf("%c",mat[z][j]);
ct[a]=mat[z][j];
a++;
}
}
}
}
}
printf("\n\nDecrypted Ciphertext is:\n");
for(a=0;a<30;a++)
{
if(isalpha(ct[a]) || isspace(ct[a]))
c++;
}
for(i=1;i<c;i++)
{
for(j=0;j<strlen(key);j++)
{
if(isalpha(mat[i][j]))
printf("%c",mat[i][j]);
else
break;
}
}
// getch();
}
/* Output */