RSA算法的简单实现,RSA算法简单实现,[Python]代码#!
RSA算法的简单实现,RSA算法简单实现,[Python]代码#!
[Python]代码
#!/usr/bin/env python #-*-coding: utf-8-*- # author: "SK (skxiaonan@gmail.com)" # date: "Date: 2009/05/22 09:10:10" import math def isPrime(number): i=2 sqrtNumber=int(math.sqrt(number)) for i in range(2, sqrtNumber+1): if number%i == 0: return False i = i+1 return True if __name__=="__main__": print "*"*77 Flag = False while Flag == False: p = int(raw_input("Please input a prime(P): ")) Flag = isPrime(p) if Flag == False: print "What you input is not a prime!" print "The P is: ", p Flag = False while Flag == False: q = int(raw_input("Please input a prime(Q): ")) if p == q: continue Flag = isPrime(q) if Flag == False: print "What you input is not a prime!" print "The Q is: ", q n = p*q print "The N is: ", n t = (p-1)*(q-1) print "The T is: ", t print "*"*77 Flag = False while Flag == False: e = int(raw_input("Please input a number(E): ")) if (e<1 or e>t): continue d=0 while (((e*d)%t) != 1): d+=1 Flag = True print "The E is: ", e print "The D is: ", d print "The Public Key(E, N) is:", e, n print "The Private Key(D, N) is:", d, n print "*"*77 Flag = False while Flag == False: plainText = int(raw_input("Please input a plaintext: ")) if (plainText < n): Flag = True print "The plaintext is: ", plainText print "Encrypt"+"."*7 cipherText = (plainText**e)%n print "cipherText is: ", cipherText print "Decrypt"+"."*7 plain = (cipherText**d)%n print "The plain is: ", plain print "*"*77 if plainText == plain: print "RSA Test success." else: print "RSA Test unsuccess!"
相关内容
- 用python+PYQT4写的一个俄罗斯方块游戏,pythonpyqt4,[Pytho
- python实现DES加密算法,pythondes加密算法,[Python]代码
- python获得磁盘剩余空间 statvfs,pythonstatvfs,[Python]代码
- python写的群发邮件系统 有点瑕疵 为了大家讨论下~~~,
- 整数/分数四则运算表达式分析并给出详细运算过程,四
- 仿内置用法 按key分组成嵌套字典,key嵌套,在日常开发
- webpy的form 元素radio单选框bug修复,webpyradio,class Radio(
- 用Python生成目录树,Python生成目录树,[Python]代码#
- Inverse power method applied to a tridiagonal matrix in Python,inve
- 把图片列表合成一个GIF动画图片,图片列表gif动画,[P
评论关闭