codeword = input('Enter codeword : ')
codeword = codeword.lower().replace(" ", "")
for i in codeword:
old = (Chr(ord(i)))
encrypt = input('Enter text to encrypt : ')
encrypt = encrypt.lower().replace(" ", "")
for i in encrypt:
new = (Chr(ord(i)))
value = new + old
for i in value:
print(Chr(ord(i)))
我正在为我的GCSE计算进行加密和解密,我已经制作了一个程序,可以成功地将文本加密到字母表中5个字母的值(' a'将成为' f&#39 ;)字母表,然后是解密它的程序。但是,我还必须编写一个程序,将代码字的值添加到文本中 并打印新信。因此,例如,如果代码字是' gcses'和文本“你好'它将打印o(7 + 8)h(3 + 5)e(19 + 12)q(5 + 12)h(19 + 15)
我认为现在的代码模糊地说是在正确的轨道上,但是,我想知道是否可以添加两个ord()函数的值来执行此程序。谢谢。任何帮助将不胜感激。
答案 0 :(得分:0)
最简单的方法可能是添加一个包含字母的查找字符串,以便找到字母数字......
alphabet = ' abcdefghijklmnopqrstuvwxyz'
print alphabet.find('b')
# prints '2'
print alphabet[alphabet.find('g') + alphabet.find('h')]
# prints 'o' as expected.
你需要处理溢出(%26会起作用)