Python密码学

破解RSA密码

破解RSA密码操作教程
使用较小的质数可以破解RSA密码,但是如果将其与较大的质数一起使用,则认为不可能。指定为什么很难破解RSA密码的原因如下-
蛮力攻击将不起作用,因为可能要使用的钥匙太多。另外,这会花费很多时间。 字典攻击在RSA算法中不起作用,因为密钥是数字,并且其中不包含任何字符。 很难对字符进行频率分析,因为单个加密块代表各种字符。 没有破解RSA密码的特定数学技巧。
RSA解密公式为-
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-28
M = C^d mod n
借助小质数,我们可以尝试破解RSA密码,并且下面提到了相同的示例代码-
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-28
def p_and_q(n):
   data = []
   for i in range(2, n):
      if n % i == 0:
         data.append(i)
   return tuple(data)
def euler(p, q):
   return (p - 1) * (q - 1)
def private_index(e, euler_v):
   for i in range(2, euler_v):
      if i * e % euler_v == 1:
         return i
def decipher(d, n, c):
   return c ** d % n
def main():
      e = int(input("input e: "))
      n = int(input("input n: "))
      c = int(input("input c: "))
      # t = 123
      # private key = (103, 143)
      p_and_q_v = p_and_q(n)
      # print("[p_and_q]: ", p_and_q_v)
      euler_v = euler(p_and_q_v[0], p_and_q_v[1])
      # print("[euler]: ", euler_v)
      d = private_index(e, euler_v)
      plain = decipher(d, n, c)
      print("plain: ", plain)
if __name__ == "__main__":
   main()

输出

上面的代码产生以下输出-
破解RSA密码
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4