您的位置:首页 > 财经 > 金融 > 今天秦皇岛最新通知_浙江平台网站建设设计_石家庄seo代理商_北京seo做排名

今天秦皇岛最新通知_浙江平台网站建设设计_石家庄seo代理商_北京seo做排名

2024/10/31 15:21:32 来源:https://blog.csdn.net/m0_72827793/article/details/142532374  浏览:    关键词:今天秦皇岛最新通知_浙江平台网站建设设计_石家庄seo代理商_北京seo做排名
今天秦皇岛最新通知_浙江平台网站建设设计_石家庄seo代理商_北京seo做排名

Basic steps of RSA algorithm

  1. The steps to generate the public key PK and private key SK are as
    follows:

  2. Randomly choose two large prime numbers P and Q. P is not equal to
    Q.

  3. Multiply the two prime numbers P and Q to get an N, that is, N=PQ

  4. Subtract one from P and Q respectively, and then multiply them
    together to get a number T, that is, T = (Q-1) * (P-1)

  5. Choose an integer E as a key so that E and T are relatively prime (
    the greatest common divisor of E and T is 1), and E must be less
    than T

  6. According to the formula DE mod T = 1, the value of D is calculated
    as another key

  7. Through the above steps, the three data N, E, and D can be found,
    where (N, E) is the public key and (N, D) is the private key.

Encrypt information with public key

Plain text: M
Encryption:在这里插入图片描述

Cipher text: C

Decrypt message with private key

Cipher text: C
Decryption: 在这里插入图片描述

Plain text: M

In a public-key system using RSA, you intercept the cipher text C = 10 sent lo a user whose public key is e = 5,n = 35. What is the plain text M

answer:
We know that 35 is relatively small, and we can decompose the prime numbers into 5 and 7
Then we can get T=(5-1)X(7-1)=24,24 and 5 are relatively prime
We can use the formula DE mod T=1 to get the value of D which is the private key

在这里插入图片描述
We can know the private key from the picture (n,D)=(35,5)
Decrypt
在这里插入图片描述
M=5,so the plain text is 5

#include<iostream>
int candp(int b,int p, int k) //b--明文或密文   p--指数(e/d)    k--模数
{if (p == 1){return b % k;}if (p == 2){return b * b % k;}if (p % 2 == 0){int  sum = candp(b, p / 2, k);return sum * sum % k;}if (p % 2 == 1){int sun = candp(b, p / 2, k);return sun * sun * b % k;}
}
int main()
{int d = 1;//求e的乘法逆int e = 5;int t = 24;while (((e * d) % t) != 1){d++;}std::cout <<d<<std::endl;int  n=35, x=0, y=10;x = candp(y, d, n);std::cout << "明文为:" << x << std::endl;return 0;}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com