SlideShare una empresa de Scribd logo
1 de 24
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
IMPLEMENTING DIFFIE-HELMAN 
The Diffie-Hellman protocol is a method for two computer users to generate a shared private key with 
which they can then exchange information across an insecure channel. Let the users be named Alice and 
Bob. First, they agree on two prime numbers and , where is large (typically at least 512 bits) 
and is a primitive root modulo . (In practice, it is a good idea to choose such that is also 
prime.) The numbers and need not be kept secret from other users. Now Alice chooses a large 
random number as her private key and Bob similarly chooses a large number . Alice then 
computes , which she sends to Bob, and Bob computes , which he sends to 
Alice. 
Now both Alice and Bob compute their shared key , which Alice computes as 
and Bob computes as 
Alice and Bob can now use their shared key to exchange information without worrying about other 
users obtaining this information. In order for a potential eavesdropper (Eve) to do so, she would first 
need to obtain knowing only , , and . 
This can be done by computing from and from . This is the discrete 
logarithmproblem, which is computationally infeasible for large . Computing the discrete logarithm of 
a number modulo takes roughly the same amount of time as factoring the product of two primes the 
same size as , which is what the security of the RSA cryptosystem relies on. Thus, the Diffie-Hellman 
protocol is roughly as secure as RSA 
The following java program shows the implementation of Diffie-Helman algorithm 
import java.util.*; 
import java.io.*; 
public class Diffe 
{ 
public static void main(String[] ar) 
{ 
double a,b,k1,k2,x,y,n,g; 
System.out.println("Enter Two Prime No:"); 
Scanner input = new Scanner(System.in); 
System.out.print("N="); 
n=input.nextDouble(); 
System.out.print("G="); 
g=input.nextDouble(); 
System.out.println("Enter Random Number Of Allice And Bob:"); 
System.out.print("X="); 
x=input.nextDouble(); 
System.out.print("Y="); 
y=input.nextDouble(); 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 1 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
a=Math.pow(g,x)%n; 
b=Math.pow(g,y)%n; 
System.out.println("A:"+a); 
System.out.println("B:"+b); 
System.out.println("-------The Key Generated by Allice & Bob-------"); 
k1=Math.pow(b,x)%n; 
System.out.println("K1:"+k1); 
k2=Math.pow(a,y)%n; 
System.out.println("K2:"+k2); 
} 
} 
OUTPUT : 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 2 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
PRACTICAL NO.2 
import java.io.*; 
import java.lang.*; 
import java.util.*; 
class RSA 
{ 
public static void main(String[] args) 
{ 
int p,q; 
Scanner sc=new Scanner(System.in); 
System.out.println("Prime Number"); 
p=sc.nextInt(); 
q=sc.nextInt(); 
int i=2; 
for(i=2;i<=p-q;i++) 
{ 
if(p-1.i==0) 
{ 
System.out.println("Not a Prime Number"); 
break; 
} 
} 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 3 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
if(i==p) 
System.out.println("No: is a Prime Number"); 
for(i=2;i<=q-1;i++) 
{ 
if(q%i==0) 
{ 
System.out.println("Not a Prime Number"); 
break; 
} 
} 
if(1==q) 
System.out.println("No: is a Prime Number"); 
int n=(p*q); 
System.out.println("Multiply"+n); 
int fact=[(p-1)*(q-1)]; 
System.out.println(fact); 
System.out.println("Enter e for RSA"); 
int e=sc.nextInt(); 
while(fact % e==0) 
{ 
e=sc.nextInt(); 
} 
System.out.println("fact is divisible by"+e); 
int d; 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 4 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
for(d=1;d<=fact;d++) 
{ 
if((d*e)% fact==1) 
{ 
System.out.println(d); 
break; 
} 
} 
System.out.println("Plain Text"); 
double pt=sc.nextInt(); 
double ct=(Math.Pow(pt,e)%n); 
System.out.println(ct); 
System.out.println("Send"+ct+"to receiver"); 
double ans= (Math.Pow(ct,d)%n); 
System.out.println("pt"+ans); 
} 
} 
OUTPUT 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 5 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
IMPLEMENTING CAESAR CIPHER 
In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's 
code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type 
of substitution cipherin which each letter in the plaintext is replaced by a letter some fixed number of 
positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would 
become B, and so on. The method is named after Julius Caesar, who used it in his private 
correspondence. 
The following java program shows the implementation of Caesar Cipher 
import java.util.*; 
class CaesarCipher 
{ 
private final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; 
public String encrypt(String plainText,int shiftKey) 
{ 
plainText = plainText.toLowerCase(); 
String cipherText=""; 
for(int i=0;i<plainText.length();i++) 
{ 
int charPosition = ALPHABET.indexOf(plainText.charAt(i)); 
int keyVal = (shiftKey+charPosition)%26; 
char replaceVal = this.ALPHABET.charAt(keyVal); 
cipherText += replaceVal; 
} 
return cipherText; 
} 
public String decrypt(String cipherText, int shiftKey) 
{ 
cipherText = cipherText.toLowerCase(); 
String plainText=""; 
for(int i=0;i<cipherText.length();i++) 
{ 
int charPosition = this.ALPHABET.indexOf(cipherText.charAt(i)); 
int keyVal = (charPosition-shiftKey)%26; 
if(keyVal<0) 
{ 
keyVal = this.ALPHABET.length() + keyVal; 
} 
char replaceVal = this.ALPHABET.charAt(keyVal); 
plainText += replaceVal; 
} 
return plainText; 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 6 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
class CaesarDemo 
{ 
public static void main(String args[]) 
{ 
Scanner sc=new Scanner(System.in); 
System.out.print("Enter Plain Text :"); 
String plainText =sc.nextLine(); 
int shiftKey=3; 
CaesarCipher cc = new CaesarCipher(); 
String cipherText = cc.encrypt(plainText,shiftKey); 
System.out.println("Your Cipher Text :" + cipherText); 
String cPlainText = cc.decrypt(cipherText,shiftKey); 
System.out.println("Your Plain Text :" + cPlainText); 
} 
} 
OUTPUT : 
PRACTICAL NO.4 
class RC4 
{ 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 7 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
string str PlainText; 
static char cipher[]; 
RC4(String str PlainText,int []key) 
{ 
this.str PlainText=str PlainText; 
int s[]=new int[255]; 
cipher =new char[str Plaintext.length()]; 
for(int i=0;i<s.length;i++) 
{ 
s[i]=i; 
} 
int i=0;int j=0; 
for(int k=0;k<str PlainText.length();k++) 
{ 
int mod k=(k% key.length); 
int kc= key[mod k]; 
j=(s[i]+j+kc)% 256+1; 
int temp=s[i]; 
s[i]=s[j]; 
s[j]=temp; 
int sc=(s[i]+s[j]%256); 
int ck =(sc); 
cipher[k]=(char)(ck^(int)str PlainText.charAt(k)); 
i=i+1; 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 8 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
} 
public static void main(String []args) 
{ 
int K[]={1,2,3,4,5,6}; 
string str Original="HELLO WORLD"; 
System.out.println("Original String-->>"+str Original); 
new RC4 (str Original,K); 
for(int i=0;i<cipher.length i++) 
{ 
System.out.println(""+cipher[i]); 
} 
} 
} 
} 
IMPLEMENTING MONO-ALPHABETIC CIPHER 
A mono-alphabetic cipher is a simple substitution cipher wherein each letter of the plaintext is replaced by 
another letter in the ciphertext. An example of a mono-alphabetic cipher key follows: 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
j r s q x z o e w n d y v p f a t b c i l h g k m u 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 9 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
This key means that any 'j' in the plaintext will be replaced by an 'A' in the ciphertext, any 'r' in the 
plaintext will be replaced by a 'B' in the ciphertext, and so on. 
The following java program shows the implementation of Mono-alphaetic Cipher 
class MonoAlphabetic { 
private final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; 
private String newKey = ""; 
private static int isGenerated = 0; 
private void generateKey(String userKey) 
{ 
// removing duplicate charaters from user key 
userKey = userKey.toLowerCase(); 
for(int i=0;i<userKey.length();i++) 
{ 
int flag = 0; 
for(int j=0;j<this.newKey.length();j++) 
{ 
if(userKey.charAt(i)==newKey.charAt(j)) 
{ 
flag = 1; 
break; 
} 
} 
if(flag==0) 
this.newKey += userKey.charAt(i); 
} 
if(isGenerated==0){ 
isGenerated = 1; 
this.generateKey(this.newKey+""+this.ALPHABET); 
} 
} 
public String encrypt(String plainText, String userKey) 
{ 
this.generateKey(userKey); 
String cipherText = ""; 
String tmpStr = plainText; 
for(int i=0;i<plainText.length();i++) 
{ 
char replaceVal = this.newKey.charAt(this.ALPHABET.indexOf(plainText.charAt(i))); 
tmpStr = tmpStr.replace(tmpStr.charAt(i),replaceVal); 
} 
cipherText = tmpStr; 
return cipherText; 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 10 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
public String decrypt(String cipherText, String userKey) 
{ 
this.generateKey(userKey); 
String plainText = ""; 
String tmpStr = cipherText; 
for(int i=0;i<cipherText.length();i++) 
{ 
char replaceVal = this.ALPHABET.charAt(this.newKey.indexOf(cipherText.charAt(i))); 
tmpStr = tmpStr.replace(tmpStr.charAt(i),replaceVal); 
} 
plainText = tmpStr; 
return plainText; 
} 
} 
class MonoAlphabeticDemo { 
public static void main(String args[]) 
{ 
MonoAlphabetic ma = new MonoAlphabetic(); 
String en = ma.encrypt("hihowareyou","studentitzone"); 
String de = ma.decrypt(en,"studentitzone"); 
System.out.println(en + " - " + de); 
} 
} 
OUTPUT: 
IMPLEMENTING MODIFIED CAESAR CIPHER 
In cryptography, a substitution cipher is a method of encoding by which units of plaintext are replaced 
with cipher text, according to a regular system; the "units" may be single letters (the most common), pairs 
of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by 
performing an inverse substitution. 
In Caesar cipher technique we displace the alphabets 3 places down the line, we can use a variant of 
Caesar cipher where we can move any places up or down the line. 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 11 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
The following java program shows the implementation of Modified Caesar Cipher 
import java.util.Scanner; 
import java.awt.*; 
import javax.swing.*; 
import java.awt.event.*; 
public class Caesar 
{ 
public static void main(String[] args){ 
String cip=Caesar.encrypt(); 
Caesar.decrypt(cip); 
} 
private static String encrypt() { 
char alphanum[]= 
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4', '5','6','7','8','9',' 
!','@','#','$','%','^','&','(',')','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y',' 
Z','+','-','*','/','[',']','{','}','=','<','>','?','_'}; 
String empty = "empty"; 
Scanner input = new Scanner(System.in); 
System.out.println("Enter the plaintext"); 
String plainText = input.nextLine(); 
String cipher = null; 
char[] plain = plainText.toCharArray(); 
for(int i = 0;i<plain.length;i++){ 
for(int j = 0 ; j<85;j++){ 
if(j<=80){ 
if(plain[i]==alphanum[j]){ 
plain[i] = alphanum[j+5]; 
break; 
} 
} 
else if(plain[i] == alphanum[j]){ 
plain[i] = alphanum [j-81]; 
} 
} 
} 
cipher = String.valueOf(plain); 
System.out.println(" cipher text is "+cipher); 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 12 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
Scanner in = new Scanner(System.in); 
System.out.println("To Decrypt plaintext enter 1"); 
int choice = in.nextInt(); 
if(choice == 1) 
{ 
return cipher; 
} 
else 
{ 
System.out.println("Thank you"); 
} 
return empty; 
} 
private static String decrypt(String cip) 
{ 
char alphanum[] 
={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9' 
,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','!','@','#','$','%', '^','&','(' 
,')','+','-','*','/','[',']','{','}','=','<','>','?','_'}; 
String cipher = null; 
String empty = "empty"; 
char[] cipher1 = cip.toCharArray(); 
if(cip .equals(empty)) 
{ 
System.out.println(" No text is Decrypted"); 
} 
else 
{ 
for(int i = 0;i<cipher1.length;i++) 
{ 
for(int j = 0 ; j<85;j++) 
{ 
if(j>=5 && cipher1[i]==alphanum[j]) 
{ 
cipher1[i] = alphanum[j-5]; 
break; 
} 
if(cipher1[i] == alphanum[j] && j<5){ 
cipher1[i] = alphanum[81+j]; 
break; 
} 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 13 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
} 
cipher=String.valueOf(cipher1); 
System.out.println(" Plain text is "+cipher); 
return cipher; 
} 
} 
OUTPUT : 
IMPLEMENTING POLY-ALPHABETIC CIPHER 
In a polyalphabetic cipher, multiple cipher alphabets are used. To facilitate encryption, all the alphabets 
are usually written out in a largetable, traditionally called a tableau. The tableau is usually 26×26, so that 
26 full ciphertext alphabets are available. The method of filling the tableau, and of choosing which 
alphabet to use next, defines the particular polyalphabetic cipher. All such ciphers are easier to break 
than once believed, as substitution alphabets are repeated for sufficiently large plaintexts. 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 14 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
The following java program shows the implementation of Poly-alphabetic Cipher 
package polyciipher; 
import java.util.*; 
public class PolyCiipher { 
public static void main(String[] args) { 
int[] j = new int[100]; 
int[] s = new int[100]; 
String test=""; 
try{ 
Scanner in = new Scanner(System.in); 
System.out.println("Enter the plain text(STRING SHOULD BE IN UPPERCASE AND DONT GIVE SPACE 
BETWEEN WORDS)::"); 
test = in.nextLine(); 
for ( int i = 0; i < test.length(); ++i ) { 
char c = test.charAt( i );// "c" holds the individual character of the string 
s[i] = (int) c-65; 
} 
for(int i=0;i<test.length()-1;i++){ 
j[i+1]=s[i]; 
} 
System.out.println("Enter the key::"); 
int k = Integer.parseInt(in.nextLine()); 
j[0]=k; 
System.out.println(); 
System.out.println("The position of the character in the cipher text::"); 
for(int i=0;i<test.length();i++){ 
j[i]=j[i]+s[i]; 
j[i]=j[i]%26; 
System.out.print(j[i]); 
} 
System.out.println(); 
System.out.println("The cipher text::"); 
for(int i=0;i<test.length();i++){ 
char c=(char) (j[i]+65); 
System.out.print(c); 
} 
System.out.println(); 
} 
catch(Exception er){ 
System.out.println("--YOU HAVE TYPE INVALID DATA--"); 
} 
} 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 15 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
OUTPUT : 
IMPLEMENTING RAIL-FENCE CIPHER 
Rail Fence Cipher" (also called a zigzag cipher) generally refers to a form of transposition cipher. It 
derives its name from the way in which it is encoded. 
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 
The following java program shows the implementation of Rail-fence Cipher 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 16 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
import java.util.*; 
public class railfence { 
public static void main(String args[]) 
{ 
Scanner sc=new Scanner(System.in); 
System.out.println("Enter Plain Text:"); 
String input =sc.nextLine(); 
String output = ""; 
int len = input.length(),flag = 0; 
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); 
} 
} 
OUTPUT: 
IMPLEMENTING SIMPLE COLUMNAR CIPHER 
In cryptography, a transposition cipher is a method of encryption by which the positions held by units 
of plaintext (which are commonly characters or groups of characters) are shifted according to a regular 
system, so that the ciphertext constitutes apermutation of the plaintext. That is, the order of the units is 
changed. Mathematically a bijective function is used on the characters' positions to encrypt and 
an inverse function to decrypt. 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 17 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
In a columnar transposition, the message is written out in rows of a fixed length, and then read out 
again column by column, and the columns are chosen in some scrambled order. Both the width of the 
rows and the permutation of the columns are usually defined by a keyword. For example, the 
word ZEBRAS is of length 6 (so the columns are of length 6), and the permutation is defined by the 
alphabetical order of the letters in the keyword. In this case, the order would be "6 3 2 4 1 5". 
In a regular columnar transposition cipher, any spare spaces are filled with nulls; in an irregular 
columnar transposition cipher, the spaces are left blank. Finally, the message is read off in columns, in 
the order specified by the keyword. 
The following java program shows the implementation of Simple columnar Cipher 
import java.io.*; 
public class Play 
{ 
static String s1,st,d; 
static StringBuffer s; 
static int m,n,c,choice,p,q,k; 
static int z[]=new int[10]; 
static char a[][]; 
public static void dis() 
{ 
System.out.println(); 
System.out.println("Matrix :"); 
System.out.println(); 
for(int i=0;i<m;i++) 
{ 
for(int j=0;j<n;j++) 
{ 
if(a[i][j]!='$') 
System.out.print(a[i][j]+" "); 
else 
System.out.print(" "); 
} 
System.out.println(); 
} 
System.out.println(); 
} 
public static void enc(DataInputStream dis)throws Exception 
{ 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 18 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
while(true) 
{ 
c=0; 
s1=""; 
System.out.println("------------------------------------------------------------------------ "); 
System.out.print("Enter columns Sequence between 1 to "+n+" : "); 
st=dis.readLine(); 
d=st+d; 
System.out.println(); 
for(int i=0;i<n;i++) 
{ 
c=(int)st.charAt(i)-49; 
for(int j=0;j<m;j++) 
{ 
if(a[j][c]!='$') 
s1=s1+a[j][c]; 
} 
} 
s1.trim(); 
c=0; 
for(int i=0;i<m;i++) 
for(int j=0;j<n;j++) 
if(c<s1.length()) 
a[i][j]=s1.charAt(c++); 
else 
a[i][j]='$'; 
dis(); 
System.out.println(); 
System.out.println(); 
System.out.print("Do You want to continue(yes(1)/no(0)) : "); 
choice=Integer.parseInt(dis.readLine()); 
if(choice==0) 
{ 
System.out.println("****************************************************************"); 
System.out.println(); 
System.out.println("Ecryption results in the ciphertext : "+s1); 
System.out.println(); 
//System.exit(0); 
return; 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 19 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
} 
public static void dec() 
{ 
k=0; 
p=s1.length()/n; 
q=s1.length()%n; 
//System.out.println("p = "+p+" q = "+q+" d = "+d); 
for(int i=0;i<m;i++) 
for(int j=0;j<n;j++) 
a[i][j]='$'; 
for(int i=0;i<d.length();i++) 
{ 
c=(int)d.charAt(i)-49; 
//System.out.println("c = "+c); 
if(c>=q) 
{ 
for(int j=0;j<p;j++) 
{ 
a[j][c]=s1.charAt(k++); 
} 
} 
else 
{ 
for(int j=0;j<p+1;j++) 
{ 
a[j][c]=s1.charAt(k++); 
} 
} 
dis(); 
if(k==s1.length()) 
{ 
s1=""; 
k=0; 
for(int x=0;x<m;x++) 
for(int j=0;j<n;j++) 
if(a[x][j]!='$') 
{ 
s1=s1+a[x][j]; 
a[x][j]='$'; 
} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 20 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
} 
System.out.println("Decryption results in the plaintext : "+s1); 
} 
public static void main(String[] args) 
{ 
try 
{ 
DataInputStream dis=new DataInputStream(System.in); 
System.out.print("Enter Plain text : "); 
s1=dis.readLine(); 
s=new StringBuffer(s1); 
//REMOVING WIDE-SPACES 
for(int i=0;i<s.length();i++) 
if(s.charAt(i)==' ') 
s.deleteCharAt(i); 
s1=new String(s); 
d=""; 
System.out.println("Enter size of the array "); 
System.out.print("Enter no of rows = "); 
m=Integer.parseInt(dis.readLine()); 
System.out.print("Enter no of columns = "); 
n=Integer.parseInt(dis.readLine()); 
a=new char[m][n]; 
c=0; 
//ENTERING IN THE ARRAY 
for(int i=0;i<m;i++) 
for(int j=0;j<n;j++) 
if(c<s1.length()) 
a[i][j]=s1.charAt(c++); 
else 
a[i][j]='$'; 
dis(); 
System.out.println("------------------------------------------------------------------------"); 
enc(dis); 
System.out.println("-------------------------------Decryption-------------------------------"); 
dec(); 
} 
catch(Exception e) 
{} 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 21 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
} 
} 
OUTPUT : 
IMPLEMENTING VERNAM CIPHER 
The Vernam Cipher is based on the principle that the plain text of a message is 'mixed' with random text 
from a One Time Pad (OTP). Because the resulting cipher text is still truely random, it can safely be sent 
over the air, without the risk of being deciphered by an interceptor. At the receiving end, the same OTP is 
used to 'unmix' the random text from the cipher text, which results in the original plain text. One only 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 22 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
has to guarantee that the OTP is safe, that there are only two copies of it, and that both copies are 
destroyed immediately after use 
The following java program shows the implementation of Vernam Cipher 
//VernamCipher.java - cipher based on random pad 
import java.io.*; 
import java.util.*; //random number methods 
class VernamCipher{ 
public static void main(String[] args) 
throws IOException 
{ 
if (args.length < 3) { 
System.out.println("Usage: " + 
"java VernamCipher clearFile codeFile key(an int)"); 
System.exit(1); 
} 
// open the input and output files 
Scanner in = Scanner.create(new File(args[0])); 
PrintWriter out = new PrintWriter(args[1]); 
// use the key to start the pseudo-random sequence 
Random r = new Random(Integer.parseInt(args[2])); 
// encrypt one line at a time 
while (in.hasNext()){ 
out.println(encrypt(in.nextLine(), r)); 
} 
in.close(); 
out.close(); 
} 
/** 
Encrypt one string using a Vernam cipher. 
@param message - a string to be encrypted 
@param r - the source of random characters for 
the encryption 
@return the encrypted string 
*/ 
public static String encrypt(String message, 
Random r) 
{ 
// for monitoring purposes print the unencrypted string 
System.out.println(message); 
char c; 
// for efficiency use a StringBuffer instead of a String 
StringBuffer cipher = 
new StringBuffer(message.length()); 
for (int i = 0; i < message.length(); i++){ 
c = message.charAt(i); 
if (Character.isLetter(c)) { 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 23 
Roll No of Student: 31 Date: __________
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS 
T. Y. B. Sc. IT Network Security - Journal 2014-15 
// for simplicity we only handle upper case letters 
cipher.append( (char) 
((Character.toUpperCase(c) - 'A' + 
(int)(r.nextDouble() * 26)) % 26 + 'A')); 
} 
else { 
// don't change non-letters 
cipher.append(c); 
} 
} 
String result = cipher.toString(); 
// for monitoring purposes print the encrypted string 
System.out.println(result); 
return result; 
} 
} 
OUTPUT : 
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 24 
Roll No of Student: 31 Date: __________

Más contenido relacionado

La actualidad más candente

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processingIntro C# Book
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queuesIntro C# Book
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Sónia
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handlingIntro C# Book
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
Keygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT SolverKeygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT Solverextremecoders
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variablesIntro C# Book
 
Java simple programs
Java simple programsJava simple programs
Java simple programsVEERA RAGAVAN
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classesIntro C# Book
 
julia-Latest Programming language
julia-Latest Programming  languagejulia-Latest Programming  language
julia-Latest Programming languageNithya Prakasan
 

La actualidad más candente (20)

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
OOP v3
OOP v3OOP v3
OOP v3
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
 
C Basics
C BasicsC Basics
C Basics
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Keygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT SolverKeygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT Solver
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
julia-Latest Programming language
julia-Latest Programming  languagejulia-Latest Programming  language
julia-Latest Programming language
 

Similar a Network Security

Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teamscentralohioissa
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxShad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxSonu62614
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdfIT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdfDhanuskarSankar1
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
information Security.docx
information Security.docxinformation Security.docx
information Security.docxSouravKarak1
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diplomamustkeem khan
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020Joseph Kuo
 

Similar a Network Security (20)

IT6712 lab manual
IT6712 lab manualIT6712 lab manual
IT6712 lab manual
 
Lecture 2 java.pdf
Lecture 2 java.pdfLecture 2 java.pdf
Lecture 2 java.pdf
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teams
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxShad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdfIT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
information Security.docx
information Security.docxinformation Security.docx
information Security.docx
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
CGI.ppt
CGI.pptCGI.ppt
CGI.ppt
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 

Más de Fahad Shaikh

Revealation of Glorious Qur'an
Revealation of Glorious Qur'anRevealation of Glorious Qur'an
Revealation of Glorious Qur'anFahad Shaikh
 
Operating Systems
Operating Systems Operating Systems
Operating Systems Fahad Shaikh
 
Sunnahs of Prophet Mohammed SAW
Sunnahs of Prophet Mohammed SAWSunnahs of Prophet Mohammed SAW
Sunnahs of Prophet Mohammed SAWFahad Shaikh
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
Cryptography & Network Security
Cryptography & Network SecurityCryptography & Network Security
Cryptography & Network SecurityFahad Shaikh
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - PraticalsFahad Shaikh
 
The great book of best quotes of all time.
The great book of best quotes of all time.The great book of best quotes of all time.
The great book of best quotes of all time.Fahad Shaikh
 
Sound - Acoustics & Psychoacoustics
Sound - Acoustics & Psychoacoustics Sound - Acoustics & Psychoacoustics
Sound - Acoustics & Psychoacoustics Fahad Shaikh
 

Más de Fahad Shaikh (10)

Revealation of Glorious Qur'an
Revealation of Glorious Qur'anRevealation of Glorious Qur'an
Revealation of Glorious Qur'an
 
Operating Systems
Operating Systems Operating Systems
Operating Systems
 
Sunnahs of Prophet Mohammed SAW
Sunnahs of Prophet Mohammed SAWSunnahs of Prophet Mohammed SAW
Sunnahs of Prophet Mohammed SAW
 
Islamic Names
Islamic NamesIslamic Names
Islamic Names
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Cryptography & Network Security
Cryptography & Network SecurityCryptography & Network Security
Cryptography & Network Security
 
Ubuntu Handbook
Ubuntu HandbookUbuntu Handbook
Ubuntu Handbook
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
The great book of best quotes of all time.
The great book of best quotes of all time.The great book of best quotes of all time.
The great book of best quotes of all time.
 
Sound - Acoustics & Psychoacoustics
Sound - Acoustics & Psychoacoustics Sound - Acoustics & Psychoacoustics
Sound - Acoustics & Psychoacoustics
 

Último

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 

Último (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Network Security

  • 1. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 IMPLEMENTING DIFFIE-HELMAN The Diffie-Hellman protocol is a method for two computer users to generate a shared private key with which they can then exchange information across an insecure channel. Let the users be named Alice and Bob. First, they agree on two prime numbers and , where is large (typically at least 512 bits) and is a primitive root modulo . (In practice, it is a good idea to choose such that is also prime.) The numbers and need not be kept secret from other users. Now Alice chooses a large random number as her private key and Bob similarly chooses a large number . Alice then computes , which she sends to Bob, and Bob computes , which he sends to Alice. Now both Alice and Bob compute their shared key , which Alice computes as and Bob computes as Alice and Bob can now use their shared key to exchange information without worrying about other users obtaining this information. In order for a potential eavesdropper (Eve) to do so, she would first need to obtain knowing only , , and . This can be done by computing from and from . This is the discrete logarithmproblem, which is computationally infeasible for large . Computing the discrete logarithm of a number modulo takes roughly the same amount of time as factoring the product of two primes the same size as , which is what the security of the RSA cryptosystem relies on. Thus, the Diffie-Hellman protocol is roughly as secure as RSA The following java program shows the implementation of Diffie-Helman algorithm import java.util.*; import java.io.*; public class Diffe { public static void main(String[] ar) { double a,b,k1,k2,x,y,n,g; System.out.println("Enter Two Prime No:"); Scanner input = new Scanner(System.in); System.out.print("N="); n=input.nextDouble(); System.out.print("G="); g=input.nextDouble(); System.out.println("Enter Random Number Of Allice And Bob:"); System.out.print("X="); x=input.nextDouble(); System.out.print("Y="); y=input.nextDouble(); Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 1 Roll No of Student: 31 Date: __________
  • 2. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 a=Math.pow(g,x)%n; b=Math.pow(g,y)%n; System.out.println("A:"+a); System.out.println("B:"+b); System.out.println("-------The Key Generated by Allice & Bob-------"); k1=Math.pow(b,x)%n; System.out.println("K1:"+k1); k2=Math.pow(a,y)%n; System.out.println("K2:"+k2); } } OUTPUT : Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 2 Roll No of Student: 31 Date: __________
  • 3. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 PRACTICAL NO.2 import java.io.*; import java.lang.*; import java.util.*; class RSA { public static void main(String[] args) { int p,q; Scanner sc=new Scanner(System.in); System.out.println("Prime Number"); p=sc.nextInt(); q=sc.nextInt(); int i=2; for(i=2;i<=p-q;i++) { if(p-1.i==0) { System.out.println("Not a Prime Number"); break; } } } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 3 Roll No of Student: 31 Date: __________
  • 4. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 if(i==p) System.out.println("No: is a Prime Number"); for(i=2;i<=q-1;i++) { if(q%i==0) { System.out.println("Not a Prime Number"); break; } } if(1==q) System.out.println("No: is a Prime Number"); int n=(p*q); System.out.println("Multiply"+n); int fact=[(p-1)*(q-1)]; System.out.println(fact); System.out.println("Enter e for RSA"); int e=sc.nextInt(); while(fact % e==0) { e=sc.nextInt(); } System.out.println("fact is divisible by"+e); int d; Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 4 Roll No of Student: 31 Date: __________
  • 5. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 for(d=1;d<=fact;d++) { if((d*e)% fact==1) { System.out.println(d); break; } } System.out.println("Plain Text"); double pt=sc.nextInt(); double ct=(Math.Pow(pt,e)%n); System.out.println(ct); System.out.println("Send"+ct+"to receiver"); double ans= (Math.Pow(ct,d)%n); System.out.println("pt"+ans); } } OUTPUT Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 5 Roll No of Student: 31 Date: __________
  • 6. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 IMPLEMENTING CAESAR CIPHER In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipherin which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence. The following java program shows the implementation of Caesar Cipher import java.util.*; class CaesarCipher { private final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; public String encrypt(String plainText,int shiftKey) { plainText = plainText.toLowerCase(); String cipherText=""; for(int i=0;i<plainText.length();i++) { int charPosition = ALPHABET.indexOf(plainText.charAt(i)); int keyVal = (shiftKey+charPosition)%26; char replaceVal = this.ALPHABET.charAt(keyVal); cipherText += replaceVal; } return cipherText; } public String decrypt(String cipherText, int shiftKey) { cipherText = cipherText.toLowerCase(); String plainText=""; for(int i=0;i<cipherText.length();i++) { int charPosition = this.ALPHABET.indexOf(cipherText.charAt(i)); int keyVal = (charPosition-shiftKey)%26; if(keyVal<0) { keyVal = this.ALPHABET.length() + keyVal; } char replaceVal = this.ALPHABET.charAt(keyVal); plainText += replaceVal; } return plainText; } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 6 Roll No of Student: 31 Date: __________
  • 7. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } class CaesarDemo { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter Plain Text :"); String plainText =sc.nextLine(); int shiftKey=3; CaesarCipher cc = new CaesarCipher(); String cipherText = cc.encrypt(plainText,shiftKey); System.out.println("Your Cipher Text :" + cipherText); String cPlainText = cc.decrypt(cipherText,shiftKey); System.out.println("Your Plain Text :" + cPlainText); } } OUTPUT : PRACTICAL NO.4 class RC4 { Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 7 Roll No of Student: 31 Date: __________
  • 8. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 string str PlainText; static char cipher[]; RC4(String str PlainText,int []key) { this.str PlainText=str PlainText; int s[]=new int[255]; cipher =new char[str Plaintext.length()]; for(int i=0;i<s.length;i++) { s[i]=i; } int i=0;int j=0; for(int k=0;k<str PlainText.length();k++) { int mod k=(k% key.length); int kc= key[mod k]; j=(s[i]+j+kc)% 256+1; int temp=s[i]; s[i]=s[j]; s[j]=temp; int sc=(s[i]+s[j]%256); int ck =(sc); cipher[k]=(char)(ck^(int)str PlainText.charAt(k)); i=i+1; Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 8 Roll No of Student: 31 Date: __________
  • 9. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } } public static void main(String []args) { int K[]={1,2,3,4,5,6}; string str Original="HELLO WORLD"; System.out.println("Original String-->>"+str Original); new RC4 (str Original,K); for(int i=0;i<cipher.length i++) { System.out.println(""+cipher[i]); } } } } IMPLEMENTING MONO-ALPHABETIC CIPHER A mono-alphabetic cipher is a simple substitution cipher wherein each letter of the plaintext is replaced by another letter in the ciphertext. An example of a mono-alphabetic cipher key follows: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z j r s q x z o e w n d y v p f a t b c i l h g k m u Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 9 Roll No of Student: 31 Date: __________
  • 10. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 This key means that any 'j' in the plaintext will be replaced by an 'A' in the ciphertext, any 'r' in the plaintext will be replaced by a 'B' in the ciphertext, and so on. The following java program shows the implementation of Mono-alphaetic Cipher class MonoAlphabetic { private final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; private String newKey = ""; private static int isGenerated = 0; private void generateKey(String userKey) { // removing duplicate charaters from user key userKey = userKey.toLowerCase(); for(int i=0;i<userKey.length();i++) { int flag = 0; for(int j=0;j<this.newKey.length();j++) { if(userKey.charAt(i)==newKey.charAt(j)) { flag = 1; break; } } if(flag==0) this.newKey += userKey.charAt(i); } if(isGenerated==0){ isGenerated = 1; this.generateKey(this.newKey+""+this.ALPHABET); } } public String encrypt(String plainText, String userKey) { this.generateKey(userKey); String cipherText = ""; String tmpStr = plainText; for(int i=0;i<plainText.length();i++) { char replaceVal = this.newKey.charAt(this.ALPHABET.indexOf(plainText.charAt(i))); tmpStr = tmpStr.replace(tmpStr.charAt(i),replaceVal); } cipherText = tmpStr; return cipherText; } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 10 Roll No of Student: 31 Date: __________
  • 11. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 public String decrypt(String cipherText, String userKey) { this.generateKey(userKey); String plainText = ""; String tmpStr = cipherText; for(int i=0;i<cipherText.length();i++) { char replaceVal = this.ALPHABET.charAt(this.newKey.indexOf(cipherText.charAt(i))); tmpStr = tmpStr.replace(tmpStr.charAt(i),replaceVal); } plainText = tmpStr; return plainText; } } class MonoAlphabeticDemo { public static void main(String args[]) { MonoAlphabetic ma = new MonoAlphabetic(); String en = ma.encrypt("hihowareyou","studentitzone"); String de = ma.decrypt(en,"studentitzone"); System.out.println(en + " - " + de); } } OUTPUT: IMPLEMENTING MODIFIED CAESAR CIPHER In cryptography, a substitution cipher is a method of encoding by which units of plaintext are replaced with cipher text, according to a regular system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution. In Caesar cipher technique we displace the alphabets 3 places down the line, we can use a variant of Caesar cipher where we can move any places up or down the line. Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 11 Roll No of Student: 31 Date: __________
  • 12. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 The following java program shows the implementation of Modified Caesar Cipher import java.util.Scanner; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Caesar { public static void main(String[] args){ String cip=Caesar.encrypt(); Caesar.decrypt(cip); } private static String encrypt() { char alphanum[]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4', '5','6','7','8','9',' !','@','#','$','%','^','&','(',')','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y',' Z','+','-','*','/','[',']','{','}','=','<','>','?','_'}; String empty = "empty"; Scanner input = new Scanner(System.in); System.out.println("Enter the plaintext"); String plainText = input.nextLine(); String cipher = null; char[] plain = plainText.toCharArray(); for(int i = 0;i<plain.length;i++){ for(int j = 0 ; j<85;j++){ if(j<=80){ if(plain[i]==alphanum[j]){ plain[i] = alphanum[j+5]; break; } } else if(plain[i] == alphanum[j]){ plain[i] = alphanum [j-81]; } } } cipher = String.valueOf(plain); System.out.println(" cipher text is "+cipher); Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 12 Roll No of Student: 31 Date: __________
  • 13. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 Scanner in = new Scanner(System.in); System.out.println("To Decrypt plaintext enter 1"); int choice = in.nextInt(); if(choice == 1) { return cipher; } else { System.out.println("Thank you"); } return empty; } private static String decrypt(String cip) { char alphanum[] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9' ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','!','@','#','$','%', '^','&','(' ,')','+','-','*','/','[',']','{','}','=','<','>','?','_'}; String cipher = null; String empty = "empty"; char[] cipher1 = cip.toCharArray(); if(cip .equals(empty)) { System.out.println(" No text is Decrypted"); } else { for(int i = 0;i<cipher1.length;i++) { for(int j = 0 ; j<85;j++) { if(j>=5 && cipher1[i]==alphanum[j]) { cipher1[i] = alphanum[j-5]; break; } if(cipher1[i] == alphanum[j] && j<5){ cipher1[i] = alphanum[81+j]; break; } } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 13 Roll No of Student: 31 Date: __________
  • 14. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } } cipher=String.valueOf(cipher1); System.out.println(" Plain text is "+cipher); return cipher; } } OUTPUT : IMPLEMENTING POLY-ALPHABETIC CIPHER In a polyalphabetic cipher, multiple cipher alphabets are used. To facilitate encryption, all the alphabets are usually written out in a largetable, traditionally called a tableau. The tableau is usually 26×26, so that 26 full ciphertext alphabets are available. The method of filling the tableau, and of choosing which alphabet to use next, defines the particular polyalphabetic cipher. All such ciphers are easier to break than once believed, as substitution alphabets are repeated for sufficiently large plaintexts. Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 14 Roll No of Student: 31 Date: __________
  • 15. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 The following java program shows the implementation of Poly-alphabetic Cipher package polyciipher; import java.util.*; public class PolyCiipher { public static void main(String[] args) { int[] j = new int[100]; int[] s = new int[100]; String test=""; try{ Scanner in = new Scanner(System.in); System.out.println("Enter the plain text(STRING SHOULD BE IN UPPERCASE AND DONT GIVE SPACE BETWEEN WORDS)::"); test = in.nextLine(); for ( int i = 0; i < test.length(); ++i ) { char c = test.charAt( i );// "c" holds the individual character of the string s[i] = (int) c-65; } for(int i=0;i<test.length()-1;i++){ j[i+1]=s[i]; } System.out.println("Enter the key::"); int k = Integer.parseInt(in.nextLine()); j[0]=k; System.out.println(); System.out.println("The position of the character in the cipher text::"); for(int i=0;i<test.length();i++){ j[i]=j[i]+s[i]; j[i]=j[i]%26; System.out.print(j[i]); } System.out.println(); System.out.println("The cipher text::"); for(int i=0;i<test.length();i++){ char c=(char) (j[i]+65); System.out.print(c); } System.out.println(); } catch(Exception er){ System.out.println("--YOU HAVE TYPE INVALID DATA--"); } } } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 15 Roll No of Student: 31 Date: __________
  • 16. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 OUTPUT : IMPLEMENTING RAIL-FENCE CIPHER Rail Fence Cipher" (also called a zigzag cipher) generally refers to a form of transposition cipher. It derives its name from the way in which it is encoded. 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 The following java program shows the implementation of Rail-fence Cipher Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 16 Roll No of Student: 31 Date: __________
  • 17. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 import java.util.*; public class railfence { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter Plain Text:"); String input =sc.nextLine(); String output = ""; int len = input.length(),flag = 0; 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); } } OUTPUT: IMPLEMENTING SIMPLE COLUMNAR CIPHER In cryptography, a transposition cipher is a method of encryption by which the positions held by units of plaintext (which are commonly characters or groups of characters) are shifted according to a regular system, so that the ciphertext constitutes apermutation of the plaintext. That is, the order of the units is changed. Mathematically a bijective function is used on the characters' positions to encrypt and an inverse function to decrypt. Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 17 Roll No of Student: 31 Date: __________
  • 18. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 In a columnar transposition, the message is written out in rows of a fixed length, and then read out again column by column, and the columns are chosen in some scrambled order. Both the width of the rows and the permutation of the columns are usually defined by a keyword. For example, the word ZEBRAS is of length 6 (so the columns are of length 6), and the permutation is defined by the alphabetical order of the letters in the keyword. In this case, the order would be "6 3 2 4 1 5". In a regular columnar transposition cipher, any spare spaces are filled with nulls; in an irregular columnar transposition cipher, the spaces are left blank. Finally, the message is read off in columns, in the order specified by the keyword. The following java program shows the implementation of Simple columnar Cipher import java.io.*; public class Play { static String s1,st,d; static StringBuffer s; static int m,n,c,choice,p,q,k; static int z[]=new int[10]; static char a[][]; public static void dis() { System.out.println(); System.out.println("Matrix :"); System.out.println(); for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { if(a[i][j]!='$') System.out.print(a[i][j]+" "); else System.out.print(" "); } System.out.println(); } System.out.println(); } public static void enc(DataInputStream dis)throws Exception { Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 18 Roll No of Student: 31 Date: __________
  • 19. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 while(true) { c=0; s1=""; System.out.println("------------------------------------------------------------------------ "); System.out.print("Enter columns Sequence between 1 to "+n+" : "); st=dis.readLine(); d=st+d; System.out.println(); for(int i=0;i<n;i++) { c=(int)st.charAt(i)-49; for(int j=0;j<m;j++) { if(a[j][c]!='$') s1=s1+a[j][c]; } } s1.trim(); c=0; for(int i=0;i<m;i++) for(int j=0;j<n;j++) if(c<s1.length()) a[i][j]=s1.charAt(c++); else a[i][j]='$'; dis(); System.out.println(); System.out.println(); System.out.print("Do You want to continue(yes(1)/no(0)) : "); choice=Integer.parseInt(dis.readLine()); if(choice==0) { System.out.println("****************************************************************"); System.out.println(); System.out.println("Ecryption results in the ciphertext : "+s1); System.out.println(); //System.exit(0); return; } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 19 Roll No of Student: 31 Date: __________
  • 20. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } } public static void dec() { k=0; p=s1.length()/n; q=s1.length()%n; //System.out.println("p = "+p+" q = "+q+" d = "+d); for(int i=0;i<m;i++) for(int j=0;j<n;j++) a[i][j]='$'; for(int i=0;i<d.length();i++) { c=(int)d.charAt(i)-49; //System.out.println("c = "+c); if(c>=q) { for(int j=0;j<p;j++) { a[j][c]=s1.charAt(k++); } } else { for(int j=0;j<p+1;j++) { a[j][c]=s1.charAt(k++); } } dis(); if(k==s1.length()) { s1=""; k=0; for(int x=0;x<m;x++) for(int j=0;j<n;j++) if(a[x][j]!='$') { s1=s1+a[x][j]; a[x][j]='$'; } Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 20 Roll No of Student: 31 Date: __________
  • 21. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } } System.out.println("Decryption results in the plaintext : "+s1); } public static void main(String[] args) { try { DataInputStream dis=new DataInputStream(System.in); System.out.print("Enter Plain text : "); s1=dis.readLine(); s=new StringBuffer(s1); //REMOVING WIDE-SPACES for(int i=0;i<s.length();i++) if(s.charAt(i)==' ') s.deleteCharAt(i); s1=new String(s); d=""; System.out.println("Enter size of the array "); System.out.print("Enter no of rows = "); m=Integer.parseInt(dis.readLine()); System.out.print("Enter no of columns = "); n=Integer.parseInt(dis.readLine()); a=new char[m][n]; c=0; //ENTERING IN THE ARRAY for(int i=0;i<m;i++) for(int j=0;j<n;j++) if(c<s1.length()) a[i][j]=s1.charAt(c++); else a[i][j]='$'; dis(); System.out.println("------------------------------------------------------------------------"); enc(dis); System.out.println("-------------------------------Decryption-------------------------------"); dec(); } catch(Exception e) {} Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 21 Roll No of Student: 31 Date: __________
  • 22. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 } } OUTPUT : IMPLEMENTING VERNAM CIPHER The Vernam Cipher is based on the principle that the plain text of a message is 'mixed' with random text from a One Time Pad (OTP). Because the resulting cipher text is still truely random, it can safely be sent over the air, without the risk of being deciphered by an interceptor. At the receiving end, the same OTP is used to 'unmix' the random text from the cipher text, which results in the original plain text. One only Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 22 Roll No of Student: 31 Date: __________
  • 23. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 has to guarantee that the OTP is safe, that there are only two copies of it, and that both copies are destroyed immediately after use The following java program shows the implementation of Vernam Cipher //VernamCipher.java - cipher based on random pad import java.io.*; import java.util.*; //random number methods class VernamCipher{ public static void main(String[] args) throws IOException { if (args.length < 3) { System.out.println("Usage: " + "java VernamCipher clearFile codeFile key(an int)"); System.exit(1); } // open the input and output files Scanner in = Scanner.create(new File(args[0])); PrintWriter out = new PrintWriter(args[1]); // use the key to start the pseudo-random sequence Random r = new Random(Integer.parseInt(args[2])); // encrypt one line at a time while (in.hasNext()){ out.println(encrypt(in.nextLine(), r)); } in.close(); out.close(); } /** Encrypt one string using a Vernam cipher. @param message - a string to be encrypted @param r - the source of random characters for the encryption @return the encrypted string */ public static String encrypt(String message, Random r) { // for monitoring purposes print the unencrypted string System.out.println(message); char c; // for efficiency use a StringBuffer instead of a String StringBuffer cipher = new StringBuffer(message.length()); for (int i = 0; i < message.length(); i++){ c = message.charAt(i); if (Character.isLetter(c)) { Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 23 Roll No of Student: 31 Date: __________
  • 24. AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 // for simplicity we only handle upper case letters cipher.append( (char) ((Character.toUpperCase(c) - 'A' + (int)(r.nextDouble() * 26)) % 26 + 'A')); } else { // don't change non-letters cipher.append(c); } } String result = cipher.toString(); // for monitoring purposes print the encrypted string System.out.println(result); return result; } } OUTPUT : Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 24 Roll No of Student: 31 Date: __________