Algorithm/Steps:
For the signing process, A signs a message m
by the following procedure:
1.
Select a random, secret integer k, such that 0 < k < q − 1.
2.
Compute r = (α^k(mod p)) (mod q)
3.
Compute s = (k^(−1)(m + ar)) (mod q)
4. A
sends the signature (m, r, s) for m to B.
For
the verification process, B verifies the signature by the following procedure:
1. B
can use A’s public information (p, q, α, β) = (23929, 997, 20424, 1483).
2.
Compute u1 ≡ s^(−1) m (mod q), and u2 ≡ s−1 r (mod q). 3. Compute v =
(α^u1*β^u2(mod p)) (mod q) 4. B accepts the signature iff v = r. Steps: 1.
select public keys (p, q, α, β) 2. sign a message m (0 < m < q − 1) with
a random k and report (m, r, s).
3.
verifies (m, r, s) for m based on the public key (p, q, α, β).
Code:
import java.math.*;
import java.util.*;
import java.security.*;
import java.io.*;
public class dsa
{
public static void
main(String[] args) throws IOException
{
Scanner sca = new Scanner(System.in);
BigInteger p, b, c, secretKey;
Random sc = new
SecureRandom();
secretKey = new
BigInteger("12345678901234567890");
System.out.println("secretKey = " +
secretKey);
p = BigInteger.probablePrime(64, sc);
b = new BigInteger("3");
c = b.modPow(secretKey, p);
System.out.println("p = " + p);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.print("Enter your Big Number message
-->");
String s = sca.nextLine();
BigInteger X = new BigInteger(s);
BigInteger r = new BigInteger(64, sc);
BigInteger EC = X.multiply(c.modPow(r, p)).mod(p);
BigInteger brmodp = b.modPow(r, p);
System.out.println("Plaintext = " + X);
System.out.println("r = "
+ r);
System.out.println("EC = "
+ EC);
System.out.println("b^r mod p =
" + brmodp);
BigInteger crmodp =
brmodp.modPow(secretKey, p);
BigInteger d = crmodp.modInverse(p);
BigInteger ad =
d.multiply(EC).mod(p);
System.out.println("\n\nc^r mod
p = " + crmodp);
System.out.println("d = "
+ d);
System.out.println("A decodes:
" + ad);
}
}
No comments:
Post a Comment