Programming

Gilbert Sandford Vernam ciphertext in Java

Gilbert Sandford Vernam ciphertext in Java is implemented as:

Download Its Perfect Copy in .txt Format

Instruction to run the below program in windows OS:

1.save the program as   .java in bin folder of jdk.
2.compile the program using ” javac “in cmd prompt
3.run the file using java command.

INPUT is:   .java file :

SOURCE CODE: 

/*Aim:To implement vernam cipher*/
import java.io.*;
import java.math.*;
class vernam
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the string”);
String st = br.readLine();
System.out.println(“enter the padding code”);
int pd[]=new int[7];
int j=0,i=0;
for(i=0;i<7;i++)
pd[i]=Integer.parseInt(br.readLine());
char ch[]=new char[st.length()];
ch=st.toCharArray();
int num;
int send[][]=new int[st.length()][7];
int receive[][]=new int[st.length()][7];
int con[]=new int[7];
System.out.println(“Send code:”);
for(i=0;i
{
j=6;
while((int)(ch[i])!=0)
{
con[j]=(int)(ch[i])%2;
ch[i]=(char)((int)(ch[i])/2);
send[i][j]=con[j]^pd[j];
System.out.print(send[i][j]);
j–;
}
System.out.println();
}
System.out.println(“Received code:”);
for(i=0;i
{
j=6;
while(j>-1)
{
receive[i][j]=send[i][j]^pd[j];
System.out.print(receive[i][j]);
j–;
}
System.out.println();
}
int sum;
System.out.println(“Original data:”);
for(i=0;i
{
sum=0;
j=0;
for(int k=6;k>=0;k–)
{
sum+=Math.pow(2,k)*receive[i][j];
j++;
}
System.out.print((char)(sum));
}
}
}
/*OUTPUT:
C:\jdk1.3\bin>javac vernam.java
C:\jdk1.3\bin>java vernam
Enter the string
sharvari
enter the padding code
1111111
Send code:
0011000
1110100
0111100
1011000
1001000
0111100
1011000
0110100
Received code:
1100111
0001011
1000011
0100111
0110111
1000011
0100111
1001011
Original data:
sharvari*/

		
Advertisements

One thought on “Gilbert Sandford Vernam ciphertext in Java”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s