python 简单字符串字典加密

1

def crypt(source,key):
    from itertools import cycle
    result=''
    temp=cycle(key)
    for ch in source:
        result=result+chr(ord(ch)^ord(next(temp)))
    return result

source='Jiangxi Insstitute of Busiess and Technology'
key='zWrite'

print('Before Encrypted:'+source)
encrypted=crypt(source,key)
print('After Encrypted:'+encrypted)
decrypted=crypt(encrypted,key)
print('After Decrypted:'+decrypted)
# Before Encrypted:Jiangxi Insstitute of Busiess and Technology
# After Encrypted:0>w;>Z8I6    >E9I ?
# .
# After Decrypted:Jiangxi Insstitute of Busiess and Technology

https://www.cnblogs.com/cmnz/p/6962500.html

2

#字符串自带的简单加密  
encode = str.maketrans('eilouvy','1234567')#加密方式  
words = 'iloveyou'  
encode_words = words.translate(encode)#按encode加密方式加密  
print(encode_words) #输出23461745  
dedoed = str.maketrans('1234567','eilouvy')#解密方式  
dedoed_words = encode_words.translate(dedoed)#按decode解密方式解密  
print(dedoed_words)#输出iloveyou 
--------------------- 
原文:https://blog.youkuaiyun.com/tobe_numberone/article/details/80633384 

 

转载于:https://www.cnblogs.com/xiaoniu-666/p/10818765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值