【发布时间】:2019-11-17 14:22:44
【问题描述】:
userPhrase = input('Enter a single word phrase to be encrypted: ')
userPhrase = userPhrase.lower()
key = int(input('Enter a key: '))
encryptedPhrase = ''
for character in userPhrase:
x = ord(character) - 97
x += key
x = x % 26
encryptedPhrase += chr(x + 97)
print('Encrypted phrase is ' + encryptedPhrase)
我在上面编写了一个简单的加密程序,主要遵循在线指南,但是我阅读的所有材料都没有充分解释为什么加密字符的 ASCII 值被 A 的 ASCII 值减去/减少(97)。如行中所示:
x = ord(character) - 97
任何解释都会很棒,提前谢谢!
【问题讨论】:
-
检查
chr(97)的输出。
标签: python encryption ascii