JavaのRSAアルゴリズム

  • RSAアルゴリズムの
    pとqの場合:最初に、十分に大きい2つの素数pとq
    取ります。N:N = p qとします
    。L:Lは(p-1)と(q-1)の最小公倍数です。
    E:EとLをコプライムにし、1 <E <L
    D:(D * E)%L = 1にし、1 <D <L
    (N、E)は公開鍵、(N、D​​)は秘密鍵
    暗号化プロセス:ciphertext =(Plaintext ^ E)%N、つまりy = x ^ e%(q
    p)
    復号化プロセス:Plaintext =(ciphertext ^ D)%N

質問の例次に
、JAVAを使用し、RSA値P = 17、q = 13、e = 7、x = 65を使用し、暗号化後にYの値を見つけてください

public class rsa {
    
    
	public static void main(String[] args) {
    
    
		BigInteger p=new BigInteger("17");
		BigInteger q=new BigInteger("13");
		BigInteger e=new BigInteger("7");
		BigInteger x=new BigInteger("65");
		BigInteger y;
		BigInteger s;
		//p.multiply(q)表示 p与q相乘
		//modpow表示幂函数模,x^e% [p.multiply(q)]
		//密文y=(明文x^e)% p与q相乘n
		y=x.modPow(e,p.multiply(q));
		System.out.println(y);
	}
}

おすすめ

転載: blog.csdn.net/weixin_44931166/article/details/103741724