zoukankan      html  css  js  c++  java
  • 【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)))

  • 相关阅读:
    家庭记账本开发记录2
    家庭记账本开发记录1
    构建之法阅读笔记——具体职位、用户和行业篇
    构建之法阅读笔记——团队篇
    js学习17
    js学习15
    js学习14
    js学习13
    js学习12
    js学习11
  • 原文地址:https://www.cnblogs.com/danhuai/p/13940645.html
Copyright © 2011-2022 走看看