含蓄表白器 (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 )
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:你是我生命里的一枝花