字符串加密
import base64
class StrEncrypt:
"""字符串加密"""
def __init__(self):
self._key = {'a', 'c', 'd', 'f', 'h', 'j', 'm', 'z'}
self._un_key = {'~', '!', ')', '$', '-', '_', '(', '*'}
self._character_table = {
'a': '~',
'~': 'a',
'c': '!',
'!': 'c',
'd': ')',
')': 'd',
'f': '$',
'$': 'f',
'h': '-',
'-': 'h',
'j': '_',
'_': 'j',
'm': '(',
'(': 'm',
'z': '*',
'*': 'z',
}
def _confuse(self):
pass
def encode(self, s: str):
_s = base64.b64encode(s.encode()).decode()
for k in set(_s):
if k in self._key:
_s = _s.replace(k, self._character_table[k])
return _s
def decode(self, s: str):
for k in set(s):
if k in self._un_key:
s = s.replace(k, self._character_table[k])
return base64.b64decode(s.encode()).decode()
标签:加密,self,key,._,字符串,table,def
From: https://www.cnblogs.com/yimeimanong/p/17627867.html