Find us on Google+ Kill the code: Rail Fence Cipher in C

Friday 17 February 2012

Rail Fence Cipher in C



#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k=0,l=0,m=0;
char s[20],a[10],b[10];
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++;
}
printf("\n");
for(i=0;i<l;i++)
{
printf(" %c",b[i]);
s[m]=b[i];
m++;
}
printf("\n\ncipher text is %s",s);
getch();
}

9 comments:

  1. IT IS ENCRYPTION,
    WHAT IS THE CODE FOR DECRYPTION??

    ReplyDelete
  2. can u post decryption code

    ReplyDelete
    Replies
    1. Hey, here is your program with encryption and decryption... test it...
      http://killthecode.blogspot.in/2012/10/rail-fence-cipher-with-decryption.html

      Delete
  3. Thank you very much...

    ReplyDelete
    Replies
    1. no problem... any more queries and suggestion any time...

      Delete
  4. it is for only two level... wt about two or more level???

    ReplyDelete
    Replies
    1. Can you give me pattern of input n output ! ! !

      Delete