// WAP to implement Vignere cipher in C.
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,b=65,c=65,d=65,t[20];
char s[20],a[26][26];
clrscr();
for(i=0;i<26;i++)
{
for(j=0;j<26;j++)
{
if(b<91)
{
a[i][j]=b;
b++;
}
else
{
a[i][j]=d;
d++;
}
}
c++;
b=c;
d=65;
}
for(i=0;i<26;i++)
{
for(j=0;j<26;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
printf("\nEnter the text : ");
gets(s);
for(i=0;i<strlen(s);i++)
{
t[i]=s[i]-65;
}
for(i=0;i<strlen(s);i++)
{
s[i]=(a[t[i]][i]);
}
for(i=0;i<strlen(s);i++)
{
printf("%c",s[i]);
}
getch();
}
/*OUTPUT :
Enter the text :
D E A R
| | | |
| | | |
| | | | // Cipher text is :
D F C V
| | | |
| | | |
| | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
*/
The code is wrong. The encryption logic itself is wrong. we use key in vigenere. plain text gives the column and key gives the row of the table.
ReplyDeleteCan you please send us INPUT and OUTPUT and the pattern the output is generated....
Delete