📄 elgamalverify.java
字号:
package elgamal;import java.math.BigInteger;public class ElGamalVerify { private boolean accept; public ElGamalVerify(Parameter params,PublicKey y,byte[]M,BigInteger r,BigInteger s){ sha256 sh=new sha256(M); int[]sha=sh.getHash(); byte[]hash=new byte[32]; int i=0; for(int j=0;j<8;j++){ hash[i++]=(byte)(sha[j] & 0xFF); hash[i++]=(byte)((sha[j]>>>8) & 0xFF); hash[i++]=(byte)((sha[j]>>>16) & 0xFF); hash[i++]=(byte)((sha[j]>>>24) & 0xFF); } BigInteger m=new BigInteger(hash); BigInteger p1=params.getP(); if(r.compareTo(p1)>=0)accept=false; else{ BigInteger u1=y.getY().modPow(r, params.getP()).multiply(r.modPow(s, params.getP())).mod(params.getP()); BigInteger u2=params.getG().modPow(m, params.getP()); if(u1.compareTo(u2)==0)accept=true; else accept=false; } } public boolean getVerify(){ return accept; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -