Programming/Programming Talk

오시오키나마이키갸루 암호화 루틴

포레 2015. 8. 31. 18:16

 

 

 

"""

 Python 2.7 pseudo-code

 Present by FORE

 http://foreblog.tistory.com/

"""

 

decode_key = []


def create_key_map(adlr):
 if len(decode_key):
  del decode_key[:]
 adlr = adlr&0x7FFFFFFF
 adlr |= (adlr<<0x1F)
 for i in range(0x1F):
  decode_key.append(adlr&0xFF)
  adlr = (adlr>>0x08) | ((adlr&0xFFFFFFFE)<<0x17)

 

def decode(buf,adlr):
 create_key_map(adlr)
 buf = list(struct.unpack('B'*len(buf),buf))
 j = 0
 for i in range(len(buf)):
  buf[i] ^= decode_key[j%0x1F]
  j += 1
 buf = struct.pack('B'*len(buf),*buf)
 return buf