Skip to content

N1ghtF1re/Public-Key-Ciphers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Public-Key-Ciphers

Stars Total Downloads Latest Stable Version License

About the library

The library contains one public key ciphers: Elgamal

Class Elgamal:

Constructors:

  • Elgamal(long p, long x, long k) . p - prime number, x - Private key, number of range (1; p - 1), Session key, mutually prime with p number of range (1; p - 1)

Methods:

  • encrypt(byte[] plaintext) - Encodes an array of bytes
    • One byte of source array turns into two elements of the array of ints.
      • CIPHERTEXT[i] = g^k mod p
      • CIPHERTEXT[i+1] = (y^k * PlAINTEXT[i/2]) mod p
  • decrypt(byte[]) - Decodes an array of ints
    • Two elements of ciphertext array (int[]) turns into one byte of plaintext array
      • (b = ciphertext[i + 1], a = ciphertext[i])
      • PLAINTEXT[i/2] = ( b * (a^x)^-1 ) mod p = (b * (a^x)^(phi(p) - 1)) mod p, phi - Euler function
  • getPublicKey() - return Public Key object (p, g, y)