Sunday, 28 October 2012
Monday, 8 October 2012
Rail Fence Cipher with Decryption
RAIL FENCE Cipher with Decryption
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k=0,l=0,m=0;
char s[20],a[10],b[10],s1[10],s2[10];
char decry[20];
clrscr();
printf("enter a string:");
scanf("%s",s);
for(i=0;i<strlen(s);i++)
{
if(i%2==0)
{
a[k]=s[i];
k++;
}
else
{
b[l]=s[i];
l++;
}
}
for(i=0;i<k;i++)
{
printf("%c ",a[i]);
s[m]=a[i];
m++;
}
for(i=0;i<l;i++)
{
printf(" %c",b[i]);
s[m]=b[i];
m++;
}
printf("\n");
k=0;
printf("\n\ncipher text is %s",s);
//DEVCRYPTION CODE...
printf("\n\nTaking above string as input to this code...\n\n");
l=0;
//s1[];
//s2[];
for(i=0;i<strlen(s)/2;i++) //FOR s1
{
s1[k++]=s[i];
}
k=0;
for(;i<strlen(s);i++) s2[k++]=s[i];
k=0;
l=0;
for(i=0;i<strlen(s1)+strlen(s2);i++)
{
if(i%2==0)
{
s[i]=s1[k];
k++;
}
else
{
s[i]=s2[l];
l++;
}
}
printf("\nFINAL OUTPUT : %s",s);
getch();
}
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k=0,l=0,m=0;
char s[20],a[10],b[10],s1[10],s2[10];
char decry[20];
clrscr();
printf("enter a string:");
scanf("%s",s);
for(i=0;i<strlen(s);i++)
{
if(i%2==0)
{
a[k]=s[i];
k++;
}
else
{
b[l]=s[i];
l++;
}
}
for(i=0;i<k;i++)
{
printf("%c ",a[i]);
s[m]=a[i];
m++;
}
for(i=0;i<l;i++)
{
printf(" %c",b[i]);
s[m]=b[i];
m++;
}
printf("\n");
k=0;
printf("\n\ncipher text is %s",s);
//DEVCRYPTION CODE...
printf("\n\nTaking above string as input to this code...\n\n");
l=0;
//s1[];
//s2[];
for(i=0;i<strlen(s)/2;i++) //FOR s1
{
s1[k++]=s[i];
}
k=0;
for(;i<strlen(s);i++) s2[k++]=s[i];
k=0;
l=0;
for(i=0;i<strlen(s1)+strlen(s2);i++)
{
if(i%2==0)
{
s[i]=s1[k];
k++;
}
else
{
s[i]=s2[l];
l++;
}
}
printf("\nFINAL OUTPUT : %s",s);
getch();
}
Subscribe to:
Posts (Atom)