Chinaunix首页 | 论坛 | 博客
  • 博客访问: 81322
  • 博文数量: 12
  • 博客积分: 126
  • 博客等级: 入伍新兵
  • 技术积分: 190
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-13 22:53
文章分类

全部博文(12)

文章存档

2015年(1)

2014年(2)

2013年(4)

2012年(2)

2011年(3)

我的朋友

分类: 网络与安全

2015-12-19 21:31:05

维吉尼亚密码表

=============================================

#维吉尼亚密码  加密

key='helloworld'

plaintext='whereisthekey'


#key='relations'

#plaintext='tobeornottobeth'


ascii='abcdefghijklmnopqrstuvwxyz'

keylen=len(key)

ptlen=len(plaintext)

ciphertext = ''

i = 0

while i < ptlen:

    j = i % keylen

    k = ascii.index(key[j])

    m = ascii.index(plaintext[i])

    ciphertext += ascii[(m+k)%26]

    i += 1


print ciphertext

===================================================================

#维吉尼亚加密算法 解密

key='helloworld'

ciphertext='dlpcsegkshrij'


#key='relations'

#ciphertext='ksmehzbblk'


ascii='abcdefghijklmnopqrstuvwxyz'

keylen=len(key)

ctlen=len(ciphertext)

plaintext = ''

i = 0

while i < ctlen:

    j = i % keylen

    k = ascii.index(key[j])

    m = ascii.index(ciphertext[i])

    if m < k:

        m += 26

    plaintext += ascii[m-k]

    i += 1


print plaintext


阅读(4705) | 评论(0) | 转发(0) |
0

上一篇:lcx的使用方法

下一篇:没有了

给主人留下些什么吧!~~