网站优化的灵魂――内容的重要性
2012-02-14 09:54
246 查看
我们的网络安全试验,需用任一语言实现rsa算法,我就用python实现了。
用python来实现,相对于c来说,代码较短,但是速度明显没有c的快。
RSA算法描述见:wiki
代码如下:
用python来实现,相对于c来说,代码较短,但是速度明显没有c的快。
RSA算法描述见:wiki
代码如下:
#!/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!"
相关文章推荐
- 几种不同类型网站内容优化切入点
- 网站seo优化做好内容页优化终将成为新时期的行业霸主
- 高质量原创内容在网站优化中起到的作用
- Yahoo!团队实践分享:网站性能优化的34条黄金守则(一)—内容
- 注意网站内部链接优化的重要性
- 小河谈网站运营中核心内容的重要性
- 网站内容对搜索引擎优化的影响
- 优化网站设计(十五):尽可能早地发送缓冲区内容
- 优化网站设计(十七):延迟或按需加载内容
- 龙光SEO:网站内容优化
- SEO看法:谈谈对网站优化中内容和外链的理解
- 网站内容和外链在优化中的占比
- 去掉网站低劣内容更加有利于优化排名
- Seo人员工具,seo内容与结构工具|seo页面相似度检测工具|网站优化
- 网站建设工作室浅谈网站优化之内容篇
- 高性能网站优化之一内容部分
- 网站性能优化的34条黄金守则(一)—内容
- 优化网站设计(十八):预加载内容
- 网站内容页优化排名分析
- 优化网站设计(十八):预加载内容