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.csdn.net/tobe_numberone/article/details/80633384 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM