Documente Academic
Documente Profesional
Documente Cultură
ASSIGMENT 1
import java.util.Scanner;
2) Monoalphabetic Cipher:
Steps:
1) Open netbeans ➝ create new project ➝ select java ➝ give a project name as
“Monoalphabetic_Cipher” ➝finish
2) Open project ➝Source Packages ➝ Monoalphabetic_Cipher ➝ Monoalphabetic_Cipher.java
and write a code:
package Monoalphabetic_Cipher;
import java.util.Scanner;
O/P:
ASSIGMENT 2
1) Vernam Cipher:
Steps:
1) Open netbeans ➝ create new project ➝ select java ➝ give a project name as “Vernam_Cipher”
➝finish
2) Open project ➝Source Packages ➝ Vernam_Cipher ➝ Vernam_Cipher.java and write a code:
package Vernam_Cipher;
2) Playfair Cipher:
Steps:
1) Open netbeans ➝ create new project ➝ select java ➝ give a project name as
“Playfair_Cipher” ➝finish
2) Open project ➝Source Packages ➝ Playfair_Cipher ➝ Playfair_Cipher.java and write a code:
package Playfair_Cipher;
import java.util.Scanner;
}
String a1=s1.substring(k, j);
if(f2=="i"){
f2="j";
}
if(f1=="i"){
f1="j";
}
if(f1.equals(f2)){
f2="x";
k+=1;
j+=1;
}
k+=2;
j+=2;
s1=s1.substring(k, s1.length());
int r1=0,col1=0,r2=0,col2=0;
for(int r=0;r<5;r++){
for(int col=0;col<5;col++){
if(m[r][col].equals(f1)){
r1=r;
col1=col;
}
if(m[r][col].equals(f2)){
r2=r;
col2=col;
}
}
}
if(r1==r2){
col1=(col1+1)%5;
col2=(col2+1)%5;
System.out.print(m[r1][col1]+""+m[r2][col2]);
}
else{
if(col1==col2){
r1=(r1+1)%5;
r2=(r2+1)%5;
System.out.print(m[r1][col1]+""+m[r2][col2]);
}else{
System.out.print(m[r1][col2]+""+m[r2][col1]);
}
}
}
}
}
ASSIGMENT no 3
Source Code:
import java.util.*;
class RailFenceBasic{
int depth;
int r=depth,len=plainText.length();
int c=len/depth;
int k=0;
String cipherText="";
if(k!=len)
mat[j][i]=plainText.charAt(k++);
else
mat[j][i]='X';
cipherText+=mat[i][j];
return cipherText;
int r=depth,len=cipherText.length();
int c=len/depth;
int k=0;
String plainText="";
mat[i][j]=cipherText.charAt(k++);
plainText+=mat[j][i];
return plainText;
class RailFence{
int depth;
String plainText,cipherText,decryptedText;
plainText=scn.nextLine();
depth=scn.nextInt();
cipherText=rf.Encryption(plainText,depth);
decryptedText=rf.Decryption(cipherText, depth);
Output:
Source Code:-
package columnar;
import java.util.Scanner;
plain = sc.next();
p = plain.toCharArray();
intctn = 0;
if (ctn<p.length) {
mat[i][j] += p[ctn];
ctn++;
System.out.println("\n");}
c[i][j] = mat[j][i];}
System.out.println("Encrypted text");
System.out.print(c[i][j]);
System.out.println("\n");
//--------------------------------------DECRYPTION-------------------------------------
d[i][j] = c[j][i];}}
System.out.println("Decrypted Text");
Output:-
ASSIGNMENT NO 4
DES ALGORITHM:
Source Code:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.swing.JOptionPane;
// create a key
cip.init(Cipher.ENCRYPT_MODE, secretkey);
cip.init(Cipher.DECRYPT_MODE, secretkey);
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
System.exit(0);
OUTPUT:
AES Algorithm:
package aes;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.swing.JOptionPane;
// create a key
cip.init(Cipher.ENCRYPT_MODE, secretkey);
cip.init(Cipher.DECRYPT_MODE, secretkey);
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"encrypted:"+new
String(encrypted)+"\n"+"decrypted:"+new String(decrypted));
System.exit(0);
OUTPUT:
ASSIGNMENTASSIGMENT NO 5
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
BigInteger n = p.multiply(q);
BigInteger d = e.modInverse(phi);
System.out.println("CipherText:" + cipherText);
OUTPUT:
ASSIGNMENT -6
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.io.IOException;
try {
} catch (ArithmeticException e) {
System.out.println(e);
} catch (IOException e) {
Output:
353
97
233
ASSIGNMENT -7
Write a program to implement the MD5 algorithm compute the message digest.
Step:
Create a new java Application and write the code:
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5{
public static String getMd5(String input)
{
try{
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}}
public static void main(String args[]) throws NoSuchAlgorithmException {
String s = "Hello world";
System.out.println("Your HashCode Generated by MD5 is: " + getMd5(s));
}}
ASSIGNMENT -8
Step:
Create a new java Application and write the code:
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class GFG {
public static String encryptThisString(String input) {
try{
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}}
public static void main(String args[]) throws NoSuchAlgorithmException {
System.out.println("HashCode Generated by SHA-1 for: ");
String s1 = "GeeksForGeeks";
System.out.println("\n" + s1 + " : " + encryptThisString(s1));
String s2 = "hello world";
System.out.println("\n" + s2 + " : " + encryptThisString(s2));
}}
ASSIGNMENT 9
Write a Program to Implement SSl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
/etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
Find the SSLEngine line and make sure they match the Extension and Write the
Directory module
Step15:Click on Details
Step16:Click on Issuer
SERVER:
package javasslserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLServerSocketFactory;
SSLServerSocketFactory sslServerSocketFactory =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
try {
ServerSocket sslServerSocket =
sslServerSocketFactory.createServerSocket(port);
System.out.println(sslServerSocket.toString());
System.out.println("ServerSocket accepted");
new BufferedReader(
new InputStreamReader(socket.getInputStream()))) {
String line;
System.out.println(line);
out.println(line);
System.out.println("Closed");
Logger.getLogger(JavaSSLServer.class.getName())
OUTPUT:
Copy the Build jar file path from the output window and run in the terminal
CLIENT:
package javasslclient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLSocketFactory;
SSLSocketFactory sslSocketFactory =
(SSLSocketFactory)SSLSocketFactory.getDefault();
try {
new BufferedReader(
new InputStreamReader(socket.getInputStream()))) {
while(true){
System.out.println("Enter something:");
if(inputLine.equals("q")){
break;
out.println(inputLine);
System.out.println(bufferedReader.readLine());
Logger.getLogger(JavaSSLClient.class.getName())
}}}
OUTPUT:
Copy the Build jar file path from the output window and run in the terminal
STEPS:
U will not have any content there u have to create keytool under /usr/bin
"/home/labpc-64/NetBeansProjects/JavaSSLServer/dist/JavaSSLServer.jar"
ASSIGNMENT 10
Configure Windows Firewall to block: - A port - An Program - A website
Steps :-
Go to Control Panel □ System & Security □ Windows Firewall
Advance Settings