作业3 RSA(草稿纸)

请添加图片描述
请添加图片描述

请添加图片描述

9.4 In an RSA system, the public key of a given user is e=65, n=2881.What is the private key of this user? Hint: First use trial-and-error to determine p and q; then use the extended Euclidean algorithm to find the multiplicative inverse of 31 modulo ϕ ( n ) \phi(n) ϕ(n)
这道题目的提示似乎有些错误,我这里直接只计算到结果私钥 d = 725 d=725 d=725
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RSA是一种非对称加密算法,用于数据的加密和解密。在Python3中,可以使用`cryptography`库来实现RSA加密和解密。 首先,你需要安装`cryptography`库。可以使用以下命令来安装: ``` pip install cryptography ``` 接下来,我们可以使用以下代码来生成RSA密钥对、进行加密和解密操作: ```python from cryptography.hazmat.primitives.asymmetric import rsa, padding from cryptography.hazmat.primitives import serialization # 生成RSA密钥对 private_key = rsa.generate_private_key( public_exponent=65537, key_size=2048 ) public_key = private_key.public_key() # 将密钥保存为PEM格式 private_pem = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption() ) public_pem = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ) # 加密 message = b"Hello, World!" ciphertext = public_key.encrypt( message, padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) # 解密 plaintext = private_key.decrypt( ciphertext, padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) # 打印结果 print("加密后的密文:", ciphertext) print("解密后的明文:", plaintext) ``` 这段代码首先生成了一个RSA私钥和对应的公钥,然后使用公钥对消息进行加密,再使用私钥对密文进行解密。最后打印出加密后的密文和解密后的明文。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值