Python加密/解密
Posted 淡怀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python加密/解密相关的知识,希望对你有一定的参考价值。
""" -*- coding:utf-8 -*- @Time :2020/11/4 19:02 @Author : @File :jar_encryption_util.py @Version:1.0 """ class JarEncryptionUtil: @staticmethod def str_encryption_ascii(str_1: str, salt=0): """ 字符串转ASCII码 :param str_1: 字符串 :param salt: 盐 :return: ASCII码列表 """ ascii_list = [] for i in range(len(str_1)): # 字符串 —> ASCII ascii_list.append(ord(str_1[i]) + salt) return ascii_list @staticmethod def ascii_encryption_str(ascii_1: list, salt=0): """ ASCII码转字符串 :param ascii_1: ASCII列表 :param salt: 盐 :return: 字符串 """ result = \'\' for i in range(len(ascii_1)): # ASCII —> 字符串 result += chr(ascii_1[i] - salt) return result if __name__ == \'__main__\': # 加密字符串 str1 = \'测,,@aA试测试测试\' # 盐 salt = 12345 # 加密 print(\'加密后:{}\'.format(JarEncryptionUtil.str_encryption_ascii(str1, salt))) # 解密 ascii_1 = [40324, 12389, 77637, 12409, 12442, 12410, 48142, 40324, 48142, 40324, 48142] print(\'解密后:{}\'.format(JarEncryptionUtil.ascii_encryption_str(ascii_1, salt)))
以上是关于Python加密/解密的主要内容,如果未能解决你的问题,请参考以下文章