Can someone explain this code?
Hello there.. This code was developed to implement the EL Gamal algorithm. Can someone explain to me why the input is "beef"?
Code:
package chapter4;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import javax.crypto.Cipher;
/**
* El Gamal example with random key generation.
*/
public class RandomKeyElGamalExample
{
public static void main(String[] args) throws Exception
{
byte[] input = new byte[] { (byte)0xbe, (byte)0xef };
Cipher cipher = Cipher.getInstance(
"ElGamal/None/NoPadding", "BC");
KeyPairGenerator generator = KeyPairGenerator.getInstance("ElGamal", "BC");
SecureRandom random = Utils.createFixedRandom();
// create the keys
generator.initialize(256, random);
KeyPair pair = generator.generateKeyPair();
Key pubKey = pair.getPublic();
Key privKey = pair.getPrivate();
System.out.println("input : " + Utils.toHex(input));
// encryption step
cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);
byte[] cipherText = cipher.doFinal(input);
System.out.println("cipher: " + Utils.toHex(cipherText));
// decryption step
cipher.init(Cipher.DECRYPT_MODE, privKey);
byte[] plainText = cipher.doFinal(cipherText);
System.out.println("plain : " + Utils.toHex(plainText));
}
}
Re: Can someone explain this code?
Quote:
Originally Posted by
Akirien
Hello there.. This code was developed to implement the EL Gamal algorithm. Can someone explain to me why the input is "beef"?
The entire algorithm runs as follows: first some mumbo jumbo, next it creates the keys, followed by the encryption step and finally the program does the decryption step. Its output is (probably) 0xbeef again.
kind regards,
Jos
Re: Can someone explain this code?
Quote:
Originally Posted by
JosAH
The entire algorithm runs as follows: first some mumbo jumbo, next it creates the keys, followed by the encryption step and finally the program does the decryption step. Its output is (probably) 0xbeef again.
kind regards,
Jos
Thx Jos for the explanation.. yeah.. its output is beef. :D
Re: Can someone explain this code?
This may be related: jargon, node: DEADBEEF
Also, Java class files are identified by their first four bytes, which are 0xCAFEBABE. :-P