Skip to content

hedinasr/Cryptology

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptosystem

Java implementation of RSA & ElGamal cryptosystems

RSA

Security of RSA depends on the difficulty of factoring large integers.

Key generation

  1. Choose the size key (integer)
  2. Construct two random prime integer p and q as :
    • 2[k/2]-1p, q ≤ 2[k/2]-1 - 1
  3. N = p * q
  4. φ(N) = (p - 1)(q - 1) (Indicatrice d'Euler)
  5. Choose e in (Z/φ(N)Z)* and compute d as :
    • ed ≡ 1 (mod φ(N))
public key secret key
(N, e) (d, p, q)

Encryption

A message m is in Z/NZ (the size of the message is less or equal to the size key)

  • Alice has the public key (N, e)
  • c = me (mod N)

Decryption

  • Bob has the private key (d, p, q)
  • cd (mod N) = m

ElGamal

Security of the ElGamal algorithm depends on the difficulty of computing discrete logs in a large prime modulus

Key generation

  1. Choose a random prime integer p as p = 2 p' + 1 with p' is prime
  2. Choose a random integer in (Z/pZ)* of order p'
  3. Choose a random integer x in [0, p' - 1]
  4. Compute h = gx in Z/pZ
public key secret key
(p, g, h) (p, x)

Encryption

  1. Choose a random r in [1, p' - 1]
  2. The encrypted message is (gr, m*hr)

ElGamal encryption is probabilistic, meaning that a single plaintext can be encrypted to many possible ciphertexts (but ElGamal encryption produces a 2:1 expansion in size from plaintext to ciphertext).

Decryption

  • Entry : (gr, m*hr)
    • h = gx 1
    • (gr)x = (gx)r = hr
    • message = m*hr/hr

Footnotes:

1
Cf. 4. of Key generation

About

Java implementation of RSA & Elgamal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published