Find us on Google+ Kill the code: Rail
Showing posts with label Rail. Show all posts
Showing posts with label Rail. Show all posts

Sunday, 24 February 2013

Rail Fence Cipher in JAVA

In the rail fence cipher, the plaintext is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. When we reach the top rail, the message is written downwards again until the whole plaintext is written out. The message is then read off in rows.
 
This is program for Rail Fence Cipher JAVA.

public class railfence {
    public static void main(String args[])
    {
        String input = "inputstring";
        String output = "";
        int len = input.length(),flag = 0;

        System.out.println("Input String : " + input);
        for(int i=0;i<len;i+=2) {
           
            output += input.charAt(i);
        }
        for(int i=1;i<len;i+=2) {
           
            output += input.charAt(i);
        }
       
        System.out.println("Ciphered Text : "+output);
    }
}







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();
}