import json class EdCoding: def __init__(self, key): self.key = key def ende(self, data): """ :param data: type just dict and string :return: """ text = data if isinstance(data, dict): text = json.dumps(data, ensure_ascii=False) encoded = ''.join( chr(ord(c) ^ self.key) for c in text ) return encoded def read_file(self): pass coding = EdCoding(12) en = coding.ende({'key': 'value'}) de = coding.ende(en) print(en, de, sep='\n')