Cryptography Reference
In-Depth Information
and
t 1 is the three rightmost bits:
t 1 = 011.
This is -ed with the first plaintext block to yield the first ciphertext block.
c 1 = t 1 101 = 011 101 = 110
We now form the next value I 2 by shifting I 1 to the left three bits, and appending c 1 . The
three most significant bits of I 1 are lost.
I 2 = 10011110.
From here on out, the process goes exactly the same way:
U 2 I 2 e
111101111 (mod
p
)
t 2 = 111
c 2 = t 2 110 = 001
I 3 = 11110111
U 3 I 3 e 1011100100 (mod p )
t 3 = 100
c 3 =
t 3
011 = 111
The final ciphertext message (in 3-bit blocks) is:
c 1 = 110, c 2 = 001, c 3 = 111
Java Algorithm Using the BigInteger class in Java, it is easy to write code to perform
Pohlig-Hellman exponentiation encryption/decryption. Here, we add a couple of methods,
pohligHellmanEncipher() and pohligHellmanDecipher(), to our Ciphers class. It calls the
same pad(), block(), unPad() and unBlock() methods we defined earlier, but it does not use
salt, or CFB. You will be asked to do CFB in the exercises.
import java.math.*;
public class Ciphers {
public static byte[] pohligHellmanEncipher(byte[] msg,BigInteger e,BigInteger p)
{
//Compute the plaintext block size
int blockSize=(p.bitLength()-1)/8;
//Check the enciphering exponent
if (!(p.subtract(BigIntegerMath.ONE).gcd(e).equals(BigIntegerMath.ONE)))
throw new IllegalArgumentException
(“Enciphering key is not relatively prime to (modulus minus one).”);
byte ba[][]=block(pad(msg,blockSize),blockSize);
//Begin the enciphering
Search WWH ::




Custom Search