【发布时间】:2018-08-26 17:50:13
【问题描述】:
早安,
我创建了一个简单的 ASCII 加密程序,但我只有 3 个问题:
- 如何检查密钥是否输入错误,并告诉我的程序在输入错误时不要尝试解密。
- 为什么加密后的文本比原文长?
- 如果我想加密 ASCII 文本以外的其他内容,会有多难?
谢谢,下面是我的代码和结果:
import time
key = "This■isôthe╝key¦b££glkHPAfgbm(*&%$$*(■ô▀"
string = "Encryption the hell out of me, even if I repeatttttttt lettersssss you can't tell"
entext = ""
detext = ""
keycnt=0
print("Displaing Text to be Encrypted")
time.sleep(1)
print(string)
time.sleep(5)
#Loops through the string and the key and adds the ascii values together to create a Encrypted character
for sLetter in string:
entext += chr(ord(sLetter) + ord(key[keycnt]))
keycnt += 1
if keycnt == len(key):
keycnt =0
print("Displaying encrypted Text")
time.sleep(1)
print(entext)
#Resetting key position
keycnt=0
#Loops through the string and the key and subtracts the ascii values together to create a decrypted character
for sLetter in entext:
detext += chr(ord(sLetter) - ord(key[keycnt]))
keycnt += 1
if keycnt == len(key):
keycnt =0
time.sleep(2)
print("Displaying decrypted Text")
time.sleep(1)
print(detext)
time.sleep(1)
【问题讨论】:
标签: python encryption cryptography ascii