[python]写一个含蓄表白器加密神器,拿去试试?

含蓄表白器 (ps: 学习struct)

just used to encode Chinese characters to Hexadecimal string then use XOR to encode again

支持以下场景:

  • 你:我有一个秘密告诉你,这是我向对你说的话:\x8b\xbe\xcd\xf5\x81\x8f\xce\xc8\x8c\xa1\xc7\xdd\xfa\x99\xd5\x89\x99\xfb\xbc\x9a
  • 你的暗恋对象:这是什么呀?
  • 你:钥匙在这:\x4f\x5d\a2
  • 你的暗恋对象:怎么解开呢?
  • 你:XOR
  • 你的暗恋对象:这是啥?表情包吗?
  • 你:百度一下,你就知道
  • 你的暗恋对象:那我试试~
import struct
from ctypes import create_string_buffer

class EncodeYourDeclaration:
    def __init__(self, your_declaration_to_your_love_girl: str):
        self.declaration = your_declaration_to_your_love_girl
        self.key = list(b'\x4f\x5d\a2') * (int(len(self.declaration) / 2) + 1)  # XOR掩码
        self.patter = "{}s".format(len(self.declaration) * 2)
        self.buf = self.create_empty_buf()
        self.load_your_declaration()
        self.encoded_declaration = self.encode_your_declaration_through_xor()
        print("your declaration has been encoded:{}".format(self.encoded_declaration))

    def create_empty_buf(self):
        return create_string_buffer(struct.calcsize(self.patter))

    def load_your_declaration(self):
        struct.pack_into(self.patter, self.buf, 0, self.declaration.encode('GBK'))

    def encode_your_declaration_through_xor(self):
        res = []
        for k, v in enumerate(list(self.buf.raw)):
            res.append(v ^ self.key[k])
        return bytes(res)

    def decode__your_declaration(self):
        de_res = []
        for k, v in enumerate(list(self.encoded_declaration)):
            de_res.append(v ^ self.key[k])
        print("decode success:{}".format(bytes(de_res).decode('GBK')))


if __name__ == '__main__':
    engine = EncodeYourDeclaration(your_declaration_to_your_love_girl="你是我生命里的一枝花")

    # 解密
    engine.decode__your_declaration()

your declaration has been encoded:b'\x8b\xbe\xcd\xf5\x81\x8f\xce\xc8\x8c\xa1\xc7\xdd\xfa\x99\xd5\x89\x99\xfb\xbc\x9a'
decode sucess:你是我生命里的一枝花

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值