Esempio n. 1
0
 void encrypt(const uberzahl &m, uberzahl &r, uberzahl &s)
 {
     //Encrypts m,
     //Modifies r, s to the outputs of the encryption
     uberzahl low = 2;
     uberzahl high = prime - 2;
     uberzahl k = random(low, high);
     r = generator.expm(k, prime);
     s = m * y.expm(k,prime) % prime;
 }
Esempio n. 2
0
    uberzahl decrypt(const uberzahl &r, const uberzahl &s, uberzahl &m)
    {
        //Takes in r, s and decrypts them
        //modifies m to the decrypted ciphertext value
        uberzahl rx = r.expm(x, prime);
        m = s * rx.inverse(prime) % prime;

        return m;
    }
Esempio n. 3
0
 elGamal()
 {
     //Initializes all of the required values using a 128-bit prime
     srand(time(NULL));
     uberzahl temp = 2;
     minPrime = temp.exp(126);
     temp = 2;
     maxPrime = temp.exp(127);
     prime = getPrime(minPrime, maxPrime);
     uberzahl low = 2;
     uberzahl high = prime - 2;
     x = random(low, high);
     generator = gen(prime);
     y = generator.expm(x, prime);
 }