python加密程序_Python-ASCII加密程序

再见

我创建了一个简单的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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值