yzk_wechat_event/utils/encryptor.py

22 lines
998 B
Python
Raw Normal View History

2023-12-13 11:41:22 +08:00
class StringEncryptor:
encrypted_list = ['8', 'h', 'b', '1', '9', 'f', 'p', '0', 'y', 'u', 's', 'i', 'c', 't', '5', 'q', 'e', 'j', 'g',
'v', 'm', '3', 'x', 'a', '6', 'o', '2', '4', 'k', 'n', 'r', 'z', 'd', '7', 'l', 'w']
decrypted_list = ['d', '1', 'r', 'b', '5', 'k', 'f', '9', '7', '8', 'j', 's', '3', '2', 'h', 'w', 'y', 'l', '6',
'4', 'c', 'a', 'v', 'n', 'm', 'o', 'p', 'e', 'q', 'z', '0', 'g', 't', 'i', 'x', 'u']
@classmethod
def encrypt(cls, string):
hashed_string = ''
for s in string:
encrypted_index = cls.encrypted_list.index(s)
hashed_string += cls.decrypted_list[encrypted_index]
return hashed_string
@classmethod
def decrypt(cls, hashed_string):
decrypted_string = ''
for s in hashed_string:
decrypted_index = cls.decrypted_list.index(s)
decrypted_string += cls.encrypted_list[decrypted_index]
return decrypted_string