我想用python构建一个密码,它通过从左到右然后从右到左反复遍历移位器的数字来解码文本,并将字母表中的字母移动相应的数字。
例子:
- 变速杆:123
- 文本:
i like python
- 过程:i+1=j,空间,l+2=n,i+3=l,k+3=n,e+2=g,空间,p+1=q,y+1=z,t+ 2=v, h+3=j, o+3=q, n+2=p
- 结果:
j nlng qzvjqp
到目前为止的代码:
import string
numbers = ""
x = 3
while x < 10000:
numbers = numbers + str(x)
x += 1
shift = 221
#string.ascii_lowercase
letters = string.ascii_letters + string.punctuation + numbers
text = (raw_input("Please enter text"))
encoded = ''
for letter in text:
if letter == ' ':
encoded = encoded + ' '
else:
x = letters.index(letter) + shift
encoded = encoded + letters[x]
print encoded
它使用迄今为止的基本编码方法。我很想知道如何在代码中实现上述编码系统。