Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中查找ElGamal算法的子组生成器?_Java_Random_Cryptography_Rsa_Generator - Fatal编程技术网

在java中查找ElGamal算法的子组生成器?

在java中查找ElGamal算法的子组生成器?,java,random,cryptography,rsa,generator,Java,Random,Cryptography,Rsa,Generator,我正试图找到一个小于1024位的发生器 p是一个随机的1024位素数 q是除以p-1的随机160位素数 我已经找到了p和q的值。但生成器最终总是为0或1 非常感谢你的帮助 BigInteger alpha=new BigInteger(1022,rand);//finding a biginteger smaller than 1024 bits BigInteger modInverseQ= q.modInverse(p); // (q^-1) mod(p) BigI

我正试图找到一个小于1024位的发生器

p是一个随机的1024位素数

q是除以p-1的随机160位素数


我已经找到了p和q的值。但生成器最终总是为0或1

非常感谢你的帮助

BigInteger alpha=new BigInteger(1022,rand);//finding a biginteger smaller than 1024 bits

    BigInteger modInverseQ= q.modInverse(p); // (q^-1) mod(p)   
    BigInteger y = p.subtract(one);  //p-1
    BigInteger z = y.multiply(modInverseQ);  //(p-1)*(q^-1)
    BigInteger g = alpha.modPow(z, p);  // a^(p-1)*(q^-1) mod(p)

    int comp = g.compareTo(one);  // checking if generator is equal to 1

    while(comp == 0)    //if generator is 1 find a new generator
    {   
        alpha=new BigInteger(1022,rand);
        g = alpha.modPow(z, p); 
        comp = g.compareTo(one);

    }

您可以查看以下类的实现:
org.bouncycastle.crypto.generators.dsapaParametersGenerator

它是Bouncy Castle()的一个类,是一个Java加密提供者


在它里面,有几个私有方法对于您的需要非常有用

我会亲自编写
(g.compareTo(one)==0)