Vigenere Cipher Using Java - Crypto Lab
Vigenere Cipher Using Java - Crypto Lab
NAVEEN KUMAR
I Aim:
To implement the Vignere cipher encryption and decryption using server/client programming using
java.
1. ENCRYPTION 2. DECRYPTION
Plain text : NAVEEN Cipher text : NBVFEO
Key : AB Key : AB
Thus, Thus,
NAVEEN NBVFEO
ABABAB + ( mod 26) ABABAB - ( mod 26)
_________ _________
NBVFEO NAVEEN
_________ _________
Therefore, Therefore,
Cipher Text : NBVFEO Plain Text : NAVEEN
1|Page
15IT10 - CRYPTOGRAPHY LABORATORY
IV Java Code:
Server class ( MyServer.java )
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
/* DECRYPTION
e.g
Text : NBVFEO
Generated key: ABABAB - (mod 26)
___________________
Cipher : NAVEEN
*/
2|Page
15IT10 - CRYPTOGRAPHY LABORATORY
3|Page
15IT10 - CRYPTOGRAPHY LABORATORY
/* KEY GENERATION
e.g
Text: NAVEEN
Key: AB
Generated key: ABABAB
*/
static String generateKey(String str, String key)
{
int x = str.length();
for (int i = 0; ; i++)
{
// For repeating key in cyclic
if (x == i)
i = 0;
// When key and plain text has same length - End
condition
if (key.length() == str.length())
break;
key+=(key.charAt(i));
return key;
}
/* ENCRYPTION
e.g
Text : NAVEEN
Generated key: ABABAB + (mod 26)
___________________
Cipher : NBVFEO
*/
return cipher_text;
}
4|Page
15IT10 - CRYPTOGRAPHY LABORATORY
{
String messconf;
String key;
Scanner sc = new Scanner(System.in);
Socket cli = new Socket("127.0.0.1",3456);
Scanner sc1 = new Scanner(cli.getInputStream());
messconf = sc1.nextLine();
System.out.println("The received message is:");
System.out.println(messconf);
}
}
}
5|Page
15IT10 - CRYPTOGRAPHY LABORATORY
V Output:
V Result:
Thus, the server / client program for Vignere cipher is successfully executed and the output is
verified.
6|Page