100% found this document useful (2 votes)
10K views2 pages

Rail - Fence Cipher

The document is a student assignment that encrypts the plaintext "WE ARE DISCOVERED FLEE AT ONCE" using a 3-rail Rail Fence cipher. The student provides the cipher text produced and includes the Java code used to implement the Rail Fence cipher encryption.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
10K views2 pages

Rail - Fence Cipher

The document is a student assignment that encrypts the plaintext "WE ARE DISCOVERED FLEE AT ONCE" using a 3-rail Rail Fence cipher. The student provides the cipher text produced and includes the Java code used to implement the Rail Fence cipher encryption.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Dil Prasad Kuwor Date: 9/27/2010

Roll no. : 064/02


Subject: Cryptography
Assignment no. : Lab No. 2

Q.5 Encrypt the text “WE ARE DISCOVERED FLEE AT ONCE”, to Rail – Fence Cipher, using 3
rails.

Cipher Text: - WECRL TEERD SOEEF EAOCA IVDEN

Java Code:

import java.util.*;
class RailFenceCipher
{
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
int i=0,j,l,r,s,c=0,t=0;
String plainText=" ",cipherText="";
System.out.println("******RAIL-FENCE CIPHER******");
System.out.println("Enter the plaintext:");
plainText=in.nextLine();
System.out.println("Enter the Rails:");
r=in.nextInt();
l=plainText.length()/r;
s=2*l;
char ct[][]=new char [r][s];
while(i<r)
{
ct[i][c]=plainText.charAt(t);
t++;
if(i==r-1&&t<=plainText.length()-1)
{
c=c+1;
for(j=r-2;j>=0;j--)
{
ct[j][c]=plainText.charAt(t);
t++;
if(j==0&&t<=plainText.length()-1)
{
c++;
i=0;
}
}
}
i=i+1;
}
for(i=0;i<r;i++)
{
for(j=0;j<ct[i].length;j++)

1
{
char d=ct[i][j];
if(d=='\0')
{
continue;
}
else
{
cipherText=cipherText+ct[i][j];
}
}
}
System.out.println("The Cipher text is:\n"+cipherText);
System.out.println(cipherText.length());
}
}

Output:

The End 

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy