⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elgamalcrypt.java

📁 ElGamal method is an aymetric method to crypt message. You can use ElGamal to crypt the key session
💻 JAVA
字号:
package elgamal;import java.math.BigInteger;import java.util.Random;public class ElGamalCrypt {        Parameter params;    int pLength;    BigInteger un=BigInteger.ONE;    public ElGamalCrypt(Parameter params){        this.params=params;        pLength=params.getP().bitLength();    }        public BigInteger []chiffre(BigInteger m,PublicKey y){        BigInteger c1,c2;        BigInteger k=new BigInteger(pLength-1,new Random());        c1=params.getG().modPow(k, params.getP());        c2=y.getY().modPow(k, params.getP()).multiply(m).mod(params.getP());        BigInteger []ret={c1,c2};        return ret;    }        public BigInteger dechiffre(BigInteger []c,PrivateKey x){        BigInteger c1=c[0];        BigInteger c2=c[1];        BigInteger tmp=c1.modPow(params.getP().subtract(x.getX()).subtract(un), params.getP());        BigInteger m=tmp.multiply(c2).mod(params.getP());        return m;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -