The following are examples of simulation programs ElGamal cryptography. This program is made with JAVA programming language, and its design interface with Net bean. You can download the project files (Indonesian version) here.
click here to downloadGenerate Trigger NumbersIn ElGamal fruit numbers are 2 triggers, namely g and k. both must be excellent and worth less than the range of data or p. Numbers g are constants or fixed. So in this final project in the initial g value 13. The value of k is a variable or change 1 change for each plain text character.In this final project in the form k do in a class GenerateK. Program listing is
public class GenerateK {
double kb ; double kx = 0;
public double setK (){ int prima =0;
while(prima == 0){
kx = (Math.random()*221)+1; prima = cekprima (kx); } return kx; }
public double getK (){
kb = setK(); return kb; }
private static int cekprima(double ky){
int ky1 = (int)ky; int sip =1;
int batas = (int) Math.ceil(ky/2);
if((ky1==1)||(ky1==2)){
sip=1;}
else{
for(int i=2;i <= batas;i++){
int tes = ky1 % i;
if(tes==0){sip = 0; break;}
else sip =1;} }
return sip;}}
call class is conducted generateK random integer value between 1 and 222. Then the numbers k will be test in prime testing. Prime test is testing whether an integer k prime or not, by way Modulo operations with numbers number k 2 to k \ 2. If the modulation is always not equal to zero, k can be considered prime. But if one Modulo operations produce zero, k is not prime. If it does not fit the random re-done to produce a prime k.
To get the number k, after GenerateK create a new object, do the calling method getK (). The following example program listing: 800x600 GenerateK bikink = new GenerateK ();
double kd = Math.ceil(bikink.getK());
int k = (int) kd - 1;
in decrypt and encrypt process you can lean more in the file download