El Gamal Problem 2
import java.math.BigInteger;
import java.math.*;
import java.util.*;
class ElGamel2
{
BigInteger p =new BigInteger("0");
BigInteger x =new BigInteger("10");//works if x devides by 10
BigInteger k =new BigInteger("7331");
//BigInteger g = new BigInteger("1173");
//BigInteger msg = new BigInteger("666");
BigInteger y =new BigInteger("0");
BigInteger a =new BigInteger("0");
BigInteger b =new BigInteger("0");
BigInteger temp =new BigInteger("0");
BigInteger t2 =new BigInteger("1");
int t1 = 0;
public BigInteger GetA(BigInteger g){
p = g.pow(150).add(t2);
t1 = x.intValue();
g = g.pow(t1);
y = g.mod(p);
a = g.modPow(k,p);
return a;
}
public BigInteger getB(BigInteger g, BigInteger eMsg){
p = g.pow(150).add(t2);
t1 = k.intValue();
y = y.pow(t1);
b = (y.multiply(eMsg)).mod(p);
return b;
}
public BigInteger decryptElGamel(BigInteger y1, BigInteger y2){
BigInteger msg =new BigInteger("0");
t1 = x.intValue();
y1 = y1.pow(t1);
//a = a.mod(p);
//a = a.mod(p);
msg = (y1.divide(y1)).mod(p);
//msg = msg.mod(p);
return msg;
}
}
import java.math.*;
class ElGamelMain
{
publicstaticvoid main(String[] args)
{
BigInteger teller1y1 =new BigInteger("0");
BigInteger teller1y2 =new BigInteger("0");
BigInteger g =new BigInteger("131");
BigInteger a =new BigInteger("0");
BigInteger b =new BigInteger("0");
BigInteger u =new BigInteger("0");
BigInteger msg =new BigInteger("111");
a = ElGamel2.GetA(g);
System.out.println(a);
b = ElGamel2.GetB(g,msg);
System.out.println(b);
msg = ElGamel2.decryptElGamel(a,b);
System.out.println(msg);
}
}
I'm getting the following error
- Compile -
ElGamelMain.java:17: non-static method GetA(java.math.BigInteger) cannot be referenced from a static context
BigInteger a1 = ElGamel2.GetA(g);
^
ElGamelMain.java:20: cannot resolve symbol
symbol : method GetB (java.math.BigInteger,java.math.BigInteger)
location: class ElGamel2
b = ElGamel2.GetB(g,msg);
^
ElGamelMain.java:23: non-static method decryptElGamel(java.math.BigInteger,java.math.BigInteger) cannot be referenced from a static context
msg = ElGamel2.decryptElGamel(a,b);
^
3 errors
Output completed (0 sec consumed) - Normal Termination
What have i done wrong? can anyone help me out please? I just want to call the method from the first class and passing the value of bigInteger.

