common
Class Cipher

java.lang.Object
  extended by common.Cipher

public class Cipher
extends java.lang.Object

Provides encryption and decryption operations.

The used encryption scheme is

\f$y=E(x)=b\cdot{}(r\cdot{}q+x)\bmod{p}\f$

The decryption is done by

\f$x=D(y)=b^{-1}\cdot{}y\bmod{p}\bmod{q}\f$

If an encrypted value is known to contain b of a degree k greater than 1, the decryption is instead done by \f$x=D(y,k)=b^{-k}\cdot{}y\bmod{p}\bmod{q}\f$

Before using, the Cipher object needs to be initialized with either a parameters file (see initialize(String)) or a stream (see initialize(InputStream)) containing the parameters.

Author:
vohuudtr

Constructor Summary
Cipher()
           
 
Method Summary
static java.math.BigInteger decrypt(java.math.BigInteger c)
          Decrypts an encrypted value to the original integer value.
static java.math.BigInteger decrypt(java.math.BigInteger c, int degree)
          Decrypts an encrypted value of a specified degree of b to the original integer value.
static java.math.BigInteger encrypt(java.math.BigInteger x)
          Encrypts an integer x to E(x).
static void initialize(java.io.InputStream is)
          Initializes the cipher with parameters in a stream.
static void initialize(java.lang.String paramfile)
          Initializes the cipher with parameters in a given file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cipher

public Cipher()
Method Detail

initialize

public static void initialize(java.lang.String paramfile)
Initializes the cipher with parameters in a given file.

Parameters:
paramfile - parameters filename.

initialize

public static void initialize(java.io.InputStream is)
Initializes the cipher with parameters in a stream.

Parameters:
is - stream containing the parameters.

encrypt

public static java.math.BigInteger encrypt(java.math.BigInteger x)
Encrypts an integer x to E(x).

Parameters:
x - integer to be encrypted.
Returns:
encrypted integer.

decrypt

public static java.math.BigInteger decrypt(java.math.BigInteger c)
Decrypts an encrypted value to the original integer value.

Parameters:
c - encrypted value.
Returns:
plain-text integer.

decrypt

public static java.math.BigInteger decrypt(java.math.BigInteger c,
                                           int degree)
Decrypts an encrypted value of a specified degree of b to the original integer value.

Parameters:
c - encrypted value.
degree - known degree of b in the encrypted value.
Returns:
plain-text integer.