AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15 Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 1 Roll No of Student: 31 Date: __________ 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();
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 1
Roll No of Student: 31 Date: __________
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=");
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
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 10
Roll No of Student: 31 Date: __________
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
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 11
Roll No of Student: 31 Date: __________
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.
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 15
Roll No of Student: 31 Date: __________
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--"); } } }
AKBAR PEERBHOY COLLEGE OF COMMERCE AND ECONOMICS T. Y. B. Sc. IT Network Security - Journal 2014-15
Name of Student: Fahad Shaikh Subject Teachers Sign: _____________ Page 16
Roll No of Student: 31 Date: __________
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