0% found this document useful (0 votes)
10 views

Cryptography and Network Security Lab

cryptography and network security lab

Uploaded by

ramuk612001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Cryptography and Network Security Lab

cryptography and network security lab

Uploaded by

ramuk612001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Ex.No.

: 1a CAESAR CIPHER

Date :

AIM:

To implement a Caesar cipher substitution technique inJava.

ALGORITHM:

1. Assign the 26 letters in alphabet to the variable named ALPHABET.

2. Convert the plaintext letters into lowercase.

3. To encrypt a plaintext letter, the first set of plaintext letters and slides it to LEFT by

the Number of positions of the secret shift.

4. The plaintext letter is then encrypted to the ciphertext letter on the sliding

ruler Underneath.

5. On receiving the ciphertext, the receiver who also knows the secret shift, positions

his Sliding ruler underneath the ciphertext alphabet and slides it to RIGHT by the agreed shift

Number, 3 in this case.

6. Then replaces the ciphertext letter by the plaintext letter on the sliding ruler underneath.

PROGRAM:

Import java.util.Scanner;

Public class ceasercipher

Public static final String ALPHABET=”abcdefghijklmnopqrstuvwxyz”;

Public static 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=ALPHABET.charAt(keyVal);

cipherText+=replaceVal;

Return cipherText;

Public static String decrypt(String cipherText,int shiftKey)

cipherText = cipherText.toLowerCase();

String plainText = “”;

For(int i=0;i<cipherText.length();i++)

Int charPosition= ALPHABET. indexOf(cipherText. charAt(i));

Int keyVal=(charPosition-shiftKey)%26;

If (keyVal< 0)

keyVal=ALPHABET.length()+keyVal;

Char replaceVal=ALPHABET.charAt(keyVal);
plainText+=replaceVal;

return plainText;
}

Public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println(“Enter the Plain text for Encryption:

“); String message=new String();

Message=sc.next();

System.out.println(“Encrypted message:Cipher Text=”+encrypt(message,3));

System.out.println(“Decrypted message:Plain Text=”+decrypt (encrypt(

Message,3),3));

Sc.close();

OUTPUT:

F:\bin>javac ceasercipher.java

F:\bin>java ceasercipher

Enter the Plain text for Encryption:

Covid

Encrypted message:Cipher

Text=frylg Decrypted message:Plain

Text=covid RESULT:

Thus the Caesar cipher substitution technique was implemented and executed successfully
Ex.No. : 2 PLAYFAIR CIPHER

Date :

AIM:

To implement a Playfair cipher substitution technique inJava.

ALGORITHM:

1. Read the keyword.

2. Then create the key table of 5x5 grid of alphabets.

3. Read the word to encrypt.

4. Ifthe input word should be even and then process it.

5. Then the plaintext message is split into pairs of two letters (digraphs).

6. Ifboth the letters are in the same column, take the letter below each one.

7. Ifboth letters are in the same row, take the letter to the right of each one.

8. If neither of the preceding two rules are true, form a rectangle with the two letters and

Take the letters on the horizontal opposite corner of the rectangle.

PROGRAM:

Import java.util.Scanner;

Public class Playfair1

Public static void main(String[] args)


{

Scanner in=new Scanner(System.in);

System.out.print(“Enter keyword:

“); String key=in.nextLine();

System.out.print(“Enter message to encrypt:

“); String msg=in.nextLine();

PFEncryption pfEncryption=new PFEncryption();

pfEncryption.makeArray(key);

msg=pfEncryption.manageMessage(msg);

pfEncryption.doPlayFair(msg, “Encrypt”);

String en=pfEncryption.getEncrypted();

System.out.println(“Encrypting. ..\n\nThe encrypted text is: “ + en);

System.out.println(“=============================”);

pfEncryption.doPlayFair(en, “Decrypt”);

System.out.print(“\nDecrypting… \n\nThe encrypted text is: “ +

pfEncryption.getDecrypted());

Class PFEncryption

Private char [][] alphabets= new char[5]

[5]; Private char[] uniqueChar= new

char[26];

Private String ch=”ABCDEFGHIKLMNOPQRSTUVWXYZ”;

Private String encrypted=””;


Private String decrypted=””;

Void makeArray(String keyword)

Keyword=keyword.toUpperCase().replace(“J”,”I”);

Boolean present, terminate=false;

Int val=0;

Int uniqueLen;

For (int i=0; i<keyword.length(); i++)

Present=false;

uniqueLen=0;

if (keyword.charAt(i)!= ‘ ‘)

For (int k=0; k<uniqueChar.length; k++)

If (Character.toString(uniqueChar[k])==null)

Break;

uniqueLen++;

For (int j=0; j<uniqueChar.length; j++)

If (keyword.charAt(i)==uniqueChar[j])
{

Present=true;

If (!present)

uniqueChar[val]=keyword.charAt(i);

val++;

Ch=ch.replaceAll(Character.toString(keyword.charAt(i)), “”);

For (int i=0; i<ch.length(); i++)

Val=0;

uniqueChar[val]=ch.charAt(i);

val++;

for (int i=0; i<5; i++)

For (int j=0; j<5; j++)

Alphabets[i][j]=uniqueChar[val];

Val++;
System.out.print(alphabets[i][j] + “\t”);

System.out.println();

String manageMessage(String msg)

Int val=0;

Int len=msg.length()-2;

String newTxt=””;

String intermediate=””;

While (len>=0)

Intermediate=msg.substring(val, val+2);

If (intermediate.charAt(0)==intermediate.charAt(1))

newTxt=intermediate.charAt(0) + “x” + intermediate.charAt(1);

msg=msg.replaceFirst(intermediate, newTxt);

len++;

Len-=2;

Val+=2;

If (msg.length()%2!=0)
{

Msg=msg+’x’;

Return msg.toUpperCase().replaceAll(“J”,”I”).replaceAll(“ “,””);

Void doPlayFair(String msg, String tag)

Int val=0;

While (val<msg.length())

searchAndEncryptOrDecrypt(msg.substring(val,val+2),tag);

val+=2;

}}

Void searchAndEncryptOrDecrypt(String doubblyCh, String tag)

Char ch1=doubblyCh.charAt(0);

Char ch2=doubblyCh.charAt(1);

Int row1=0, col1=0, row2=0,

col2=0; For (int i=0; i<5; i++)

For (int j=0; j<5; j++)

If (alphabets[i][j]==ch1)

{
Row1=I;

Col1=j;

Else if (alphabets[i][j]==ch2)

{ Row2=

I;

Col2=j;

}}}

If (tag==”Encrypt”)

Encrypt(row1, col1, row2,

col2); Else if(tag==”Decrypt”)

Decrypt(row1, col1, row2, col2);

Void encrypt(int row1, int col1, int row2, int col2)

If (row1==row2)

Col1=col1+1;

Col2=col2+1;

If (col1>4)

Col1=0;

If (col2>4)

Col2=0;

Encrypted+=(Character.toString(alphabets[row1][col1])+
Character.toString(alphabets[row1][col2]));

Else if(col1==col2)

Row1=row1+1;

Row2=row2+1;

If (row1>4)

Row1=0;

If (row2>4)

Row2=0;

Encrypted+=(Character.toString(alphabets[row1][col1])+

Character.toString(alphabets[row2][col1]));

Else

{ encrypted+=(Character.toString(alphabets[row1][col2])+

Character.toString(alphabets[row2][col1]));

}}

Void decrypt(int row1, int col1, int row2, int col2)

If (row1==row2)

Col1=col1-1;

Col2=col2-1;

If (col1<0)
Col1=4;

If (col2<0)

Col2=4;

Decrypted+=(Character.toString(alphabets[row1][col1])+

Character.toString(alphabets[row1][col2]));

Else if(col1==col2)

Row1=row1-1;

Row2=row2-1;

If (row1<0)

Row1=4;

If (row2<0)

Row2=4;

Decrypted+=(Character.toString(alphabets[row1][col1])+

Character.toString(alphabets[row2][col1]));

Else

Decrypted+=(Character.toString(alphabets[row1][col2])+

Character.toString(alphabets[row2][col1]));

}}

String getEncrypted( )

{
Return encrypted;

String getDecrypted( )

Return decrypted;

}}

OUTPUT:

F:\bin>javac Playfair1.java

F:\bin>java Playfair1

Enter keyword: INFOSEC

Enter message to encrypt:

cryptography I N F O S

ECABD

GHKLM

PQRTU

VWXYZ

Encrypting….

The encrypted text is: AQVTYBKPERLW

Decrypting….

The encrypted text is:

CRYPTOGRAPHY RESULT:

Thus the Playfair cipher substitution technique was implemented and executed successfully
Ex.No. : 3 DATA ENCRYPTION STANDARD (DES)

Date :

AIM:

To apply Data Encryption Standard (DES) Algorithm for a practical application like

User Message Encryption.

ALGORITHM:

1. Create a DES Key.

2. Create a Cipher instance from Cipher class, specify the following information

And separated by a slash (/).

Algorithm name

Mode (optional)

Padding scheme (optional)

3. Convert String into Byte[] array format.

4. Make Cipher inencrypt mode, and encrypt it with Cipher.doFinal() method.

5. Make Cipher indecrypt mode, and decrypt it withCipher.doFinal() method.

PROGRAM:

Import javax.swing.*;

Import java.security.SecureRandom;

Import javax.crypto.Cipher;

Import javax.crypto.KeyGenerator;

Import javax.crypto.SecretKey;
Import javax.crypto.spec.SecretKeySpec;

Import java.util.Random;

Class DES

Byte[] skey=new byte[1000];

String skeystring;

Static byte[] raw;

String inputmessage,encryptedata,decryptedmessage;

Public DES()

Try

Generatesymmetrickey();

Inputmessage=JOptionPane.showInputDialog(null,”Enter message to

Encrypt:”);

Byte[] ibyte =inputmessage.getBytes();

Byte[] ebyte=encrypt(raw, ibyte);

String encrypteddata=new String(ebyte);

System.out.println(“Encrypted message:”+encrypteddata);

JOptionPane.showMessageDialog(null,”Encrypted

Data”+”\n”+encrypteddata);

Byte[] dbyte=decrypt(raw,ebyte);

String decryptedmessage=new String(dbyte);

System.out.println(“Decrypted message:”+decryptedmessage);
OptionPane.showMessageDialog(null,”Decrypted Data

“+”\n”+decryptedmessage);

Catch(Exception e)

System.out.println€;

Void generatesymmetrickey()

Try

Random r = new

Random(); Int

num=r.nextInt(10000);

String knum=String.valueOf(num);

Byte[] knumb=knum.getBytes();

Skey=getRawKey(knumb);

Skeystring=new String(skey);

System.out.println(“DES

SymmerticKey=”+skeystring);

Catch(Exception e)

System.out.println€;
}

Private static byte[] getRawKey(byte[] seed) throws Exception

KeyGenerator kgen=KeyGenerator.getInstance(“DES”);

SecureRandom sr

=SecureRandom.getInstance(“SHA1PRNG”);

Sr.setSeed(seed);

Kgen.init(56,sr);

SecretKey skey=kgen.generateKey();

Raw=skey.getEncoded();

Return raw;

Private static byte[] encrypt(byte[] raw,byte[] clear) throws Exception

SecretKey seckey = new SecretKeySpec(raw,

“DES”); Cipher cipher = Cipher.getInstance(“DES”);

Cipher.init(Cipher.ENCRYPT_MODE,seckey);

Byte[] encrypted=cipher.doFinal(clear);

Return encrypted;

Private static byte[] decrypt(byte[] raw,byte[] encrypted) throws Exception

SecretKey seckey = new SecretKeySpec(raw,


“DES”); Cipher cipher = Cipher.getInstance(“DES”);

Cipher.init(Cipher.DECRYPT_MODE,seckey);
Byte[] decrypted =

cipher.doFinal(encrypted); Return decrypted;

Public static void main(String args[])

DES des=new DES();

OUTPUT:

RESULT:

Thus the java program for applying Data Encryption Standard (DES) Algorithm for a Practical application
of User Message Encryption is written and executed successfully.
Ex.No. : 4 AES ALGORITHM

Date :

AIM:

To apply Advanced Encryption Standard (AES) Algorithm for a practical application

Like URL Encryption.

ALGORITHM:

1. AES is based on a design principle known as a substitution–permutation.

2. AES does not use a Feistel network like DES, it uses variant of Rijndael.

3. It has a fixed block size of128 bits, and a key size of 128, 192, or 256 bits.

4. AES operates on a 4 × 4 column-major order array of bytes, termed the state

PROGRAM:

Import java.io.UnsupportedEncodingException;

Import java.security.MessageDigest;

Import java.security.NoSuchAlgorithmException;

Import java.util.Arrays;

Import java.util.Base64;

Import javax.crypto.Cipher;

Import javax.crypto.spec.SecretKeySpec;

Public class AES

Private static SecretKeySpec

secretKey; Private static byte[] key;


Public static void setKey(String myKey)

{ MessageDigest sha = null;

Try {

Key = myKey.getBytes(“UTF-8”);

Sha = MessageDigest.getInstance(“SHA-

1”); Key = sha.digest(key);

Key= Arrays.copyOf(key, 16);

secretKey= new SecretKeySpec(key, “AES”);

} catch (NoSuchAlgorithmException e)

{ e.printStackTrace();

} catch (UnsupportedEncodingException e)

{ e.printStackTrace();

Public static String encrypt(String strToEncrypt, String secret)

{ Try {

setKey(secret);

Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5Padding”);

Cipher.init(Cipher.ENCRYPT_MODE, secretKey);

Return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes

(“UTF-8”)));

} catch (Exception e) {

System.out.println(“Error while encrypting: “ + e.toString());


}
Return null;
}

Public static String decrypt(String strToDecrypt, String secret)

{ Try {

setKey(secret);

Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5PADDING”);

Cipher.init(Cipher.DECRYPT_MODE, secretKey);

Return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));

} catch (Exception e) {

System.out.println(“Error while decrypting: “ + e.toString());

Return null;

Public static void main(String[] args) {

System.out.println(“Enter the secret key: “);

String secretKey= System.console().readLine();

System.out.println(“Enter the original URL: “);

String originalString= System.console().readLine();

String encryptedString = AES.encrypt(originalString, secretKey);

String decryptedString = AES.decrypt(encryptedString,

secretKey);

System.out.println(“URL Encryption Using AES Algorithm\n---------“);

System.out.println(“Original URL : “ + originalString);

System.out.println(“Encrypted URL : “ + encryptedString);

System.out.println(“Decrypted URL : “ +

decryptedString);

}
}

OUTPUT:

C:\Security Lab New\programs>java

AES Enter the secret key:

annaUniversity

Enter the original URL:

www.annauniv.edu

URL Encryption Using AES Algorithm

Original URL : www.annauniv.edu

Encrypted URL : vibpFJW6Cvs5Y+L7t4N6YWWe07+JzS1d3CU2h3mEvEg=

Decrypted URL : www.annauniv.edu

RESULT:

Thus the java program for applying Advanced EncryptionStandard (AES) Algorithm

For a practical application of URL encryption is written and executed successfully.

Ex.No. : 5 RSA ALGORITHM

Date :

AIM:

To implement a RSA algorithm using HTML and Javascript.


ALGORITHM:

1. Choose two prime number p and q.

2. Compute the value of n and t.

3. Find the value of public key e.

4. Compute the value of private key d.

5. Do the encryption and decryption

a. Encryption is given as,

C=t

E mod n

b. Decryption is given as,

T=c

D mod n

PROGRAM:

Rsa.html

<html>

<head>

<title>RSA Encryption</title>

<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>

</head>

<body>

<center>

<h1>RSA Algorithm</h1>
<h2>Implemented Using HTML & Javascript</h2>

<hr>

<table>

<tr>

<td>Enter First Prime Number:</td>

<td><input type=”number” value=”53” id=”p”></td>

</tr>

<tr>

<td>Enter Second Prime Number:</td>

<td><input type=”number” value=”59” id=”q”></p> </td>

</tr>

<tr>

<td>Enter the Message(cipher text):<br>[A=1, B=2,…]</td>

<td><input type=”number” value=”89” id=”msg”></p> </td>

</tr>

<tr>

<td>Public Key:</td>

<td><p id=”publickey”></p> </td>

</tr>

<tr>

<td>Exponent:</td>

<td><p id=”exponent”></p> </td>


</tr>

<tr>

<td>Private Key:</td>
<td><p id=”privatekey”></p></td>

</tr>

<tr>

<td>Cipher Text:</td>

<td><p id=”ciphertext”></p> </td>

</tr>

<tr>

<td><button onclick=”RSA();”>Apply RSA</button></td>

</tr>

</table> </center>

</body>

<script type=”text/javascript”>

Function RSA()

Var gcd, p, q, no, n, t, e, I, x;

Gcd = function (a, b) { return (!b) ? a : gcd(b, a % b); };

P = document.getElementById(‘p’).value;

Q = document.getElementById(‘q’).value;

No = document.getElementById(‘msg’).value;

N = p * q;

T = (p – 1) * (q – 1);

For (e = 2; e < t; e++)

If (gcd(e, t) == 1)
{

Break;

For (I = 0; I < 10; i++)

X=1+I*t

If (x % e == 0)

D = x / e;

Break;

Ctt = Math.pow(no,

e).toFixed(0); Ct = ctt % n;

Dtt = Math.pow(ct,

d).toFixed(0); Dt = dtt % n;

Document.getElementById(‘publickey’).innerHTML = n;

Document.getElementById(‘exponent’).innerHTML = e;

Document.getElementById(‘privatekey’).innerHTML = d;

Document.getElementById(‘ciphertext’).innerHTML = ct;

</script>

</html>
OUTPUT:

RESULT:

Thus the RSA algorithm was implemented using HTML and Javascript and executed successfully

Ex.No. : 6 DIFFIE-HELLMAN KEY EXCHANGE ALGORITHM

Date :

AIM:

To implement a Diffie-Hellman Key Exchange

algorithm. ALGORITHM:

1. Sender and receiver publicly agree to use a modulus p and base g which is a

primitive Root modulo p.

2. Sender chooses a secret integer x then sends Bob R1 = g


X mod p

3. Receiver chooses a secret integer y, then sends Alice R2 =

g Y mod p

4. Sender computes k1 =

B X mod p

5. Receiver computes k2 =

A Y mod p

6. Sender and Receiver now share a secret key.

PROGRAM:

Import java.io.*;

Import java.math.BigInteger;

Class dh

Public static void main(String[]args)throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter prime number:”);

BigInteger p=new BigInteger(br.readLine());

System.out.print(“Enter primitive root of “+p+”:”);

BigInteger g=new BigInteger(br.readLine());

System.out.println(“Enter value for x less than “+p+”:”);

BigInteger x=new BigInteger(br.readLine());

BigInteger R1=g.modPow(x,p);

System.out.println(“R1=”+R1);
System.out.print(“Enter value for y less than

“+p+”:”); BigInteger y=new BigInteger(br.readLine());

BigInteger R2=g.modPow(y,p);

System.out.println(“R2=”+R2);

BigInteger k1=R2.modPow(x,p);

System.out.println(“Key calculated at Sender’s

side:”+k1); BigInteger k2=R1.modPow(y,p);

System.out.println(“Key calculated at Receiver’s side:”+k2);

System.out.println(“Diffie-Hellman secret key was calculated.”);


}
}

OUTPUT

C:\Security Lab New\programs>javac

dh.java C:\Security Lab New\programs>java

dh

Enter prime number:

11

Enter primitive root of 11:7

Enter value for x less than

11: 3

R1=2

Enter value for y less than

11:6 R2=4

Key calculated at Sender’s side:9

Key calculated at

Receiver’sside:9

Diffie-Hellman secret key was calculated.


RESULT:

Thus the Diffie-Hellman key exchange algorithm was implemented and executed successfully

Ex.No. : 7 SHA-1 ALGORITHM

Date :

AIM:

To calculate the message digest of a text using the SHA-1 algorithm in Java.

ALGORITHM:

1. Append Padding bits.

2. Append Length – 64 bits are appended to the end.

3. Prepare Processing Functions.

4. Prepare Processing Constants.

5. Initialize Buffers.

6. Processing Message in 512-bit blocks (L blocks in total message).

PROGRAM:

Import java.util.Scanner;

Import java.security.MessageDigest;

Import java.security.NoSuchAlgorithmException;
Public class sha1

Public static void main(String[] args)throws NoSuchAlgorithmException

Scanner sc = new Scanner(System.in);

System.out.println(“Enter the String:”);

String message = new String();

Message = sc.next();

System.out.println(“Message Digest is=”);

System.out.println(sha1(message));

Static String sha1(String input)throws NoSuchAlgorithmException

MessageDigest mDigest =

MessageDigest.getInstance(“SHA1”); Byte[] result =

mDigest.digest(input.getBytes());

StringBuffer sb = new

StringBuffer(); For(int I =

0;i<result.length;i++)

Sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));

Return sb.toString();

OUTPUT:
C:\Security Lab New\programs>java

sha1 Enter the String:

CORONA VIRUS DISEASE

Message Digest is=

7690b7ccb987f4b3f32d2b9e7e8a69db2d0ded02

RESULT:

Thus the Secure Hash Algorithm (SHA-1) has been implemented and executed successfully

Ex.No. : 8 DIGITAL SIGNATURE SCHEME

Date :

AIM:

To implement the signature scheme – Digital Signature Standard.

ALGORITHM:

1. Declare the class and required variables.

2. Create the object for the class in the main program.

3. Access the member functions using the objects.

4. Implement the SIGNATURE SCHEME – Digital Signature Standard.

5. It uses a hash function.

6. The hash code is provided as input to a signature function along with a random
Number K generated for the particular signature.

7. The signature function also depends on the sender„s private key.

8. The signature consists of two components.

9. The hash code of the incoming message is generated.

10.The hash code and signature are given as input to a verification

function. PROGRAM:

Import java.util.*;

Import java.math.BigInteger;

Class dsaAlg {

Final static BigInteger one = new BigInteger(“1”);

Final static BigInteger zero = new

BigInteger(“0”); Public static BigInteger

getNextPrime(String ans)

BigInteger test = new

BigInteger(ans); While (!

test.isProbablePrime(99))

E:

Test = test.add(one);

Return test;

Public static BigInteger findQ(BigInteger n)


{

BigInteger start = new

BigInteger(“2”); While (!

n.isProbablePrime(99))

While (!((n.mod(start)).equals(zero)))

Start = start.add(one);

N = n.divide(start);

Return n;

Public static BigInteger getGen(BigInteger p, BigInteger

q, Random r)

BigInteger h = new BigInteger(p.bitLength(),

r); H = h.mod(p);

Return h.modPow((p.subtract(one)).divide(q), p);

Public static void main (String[] args)

throws Java.lang.Exception

Random randObj = new Random();

BigInteger p = getNextPrime(“10600”); /* approximate


Prime */

BigInteger q =

findQ(p.subtract(one)); BigInteger g =

getGen(p,q,randObj);

System.out.println(“ \n simulation of Digital Signature Algorithm \n”);

System.out.println(“ \n global public key components are:\n”);

System.out.println(“\np is: “ +

p); System.out.println(“\nq is: “

+ q); System.out.println(“\ng is:

“ + g);

BigInteger x = new BigInteger(q.bitLength(),

randObj); X = x.mod(q);

BigInteger y= g.modPow(x,p);

BigInteger k = new BigInteger(q.bitLength(),

randObj); K = k.mod(q);

BigInteger r = (g.modPow(k,p)).mod(q);

BigInteger hashVal = new

BigInteger(p.bitLength(), randObj);

BigInteger kInv = k.modInverse(q);

BigInteger s = kInv.multiply(hashVal.add(x.multiply®));

S = s.mod(q);

System.out.println(“\nsecret information are:\n”);

System.out.println(“x (private) is:” + x);

System.out.println(“k (secret) is: “ +

k); System.out.println(“y (public) is: “

+ y);
System.out.println(“h (rndhash) is: “ + hashVal);
System.out.println(“\n generating digital signature:\

n”); System.out.println(“r is : “ + r);

System.out.println(“s is : “ + s);

BigInteger w =

s.modInverse(q);

BigInteger u1 =

(hashVal.multiply(w)).mod(q); BigInteger u2

= (r.multiply(w)).mod(q);

BigInteger v= (g.modPow(u1,p)).multiply(y.modPow(u2,p));

V = (v.mod(p)).mod(q);

System.out.println(“\nverifying digital signature (checkpoints)\n:”);

System.out.println(“w is : “ + w);

System.out.println(“u1 is : “ +

u1); System.out.println(“u2 is : “

+ u2); System.out.println(“v is : “

+ v);

If (v.equals®)
{

System.out.println(“\nsuccess: digital signature is verified!\n “ + r);

Else

System.out.println(“\n error: incorrect digitalsignature\n “);

}
OUTPUT:
C:\Security Lab New\programs>javac

dsaAlg.java C:\Security Lab New\programs>java

dsaAlg

Simulation of Digital Signature

Algorithm Global public key components

are:

P is: 10601

Q is: 53

G is: 6089

Secret information are:

X(private) is:6

K (secret) is: 3

Y (public) is: 1356

H (rndhash) is: 12619

Generating digitalsignature:

R is : 2

S is :41

Verifying digitalsignature (checkpoints):

W is : 22

U1 is : 4

U2 is :

44

V is : 2

Success: digital signature is

verified! 2

RESULT:
Thus the Digital Signature Standard Signature Scheme has been implemented and executed successfully

You might also like