하지만, 동일한 값이 중간에 나오므로 이상한 문자가 나오면 따로 분리하여 결과물을 확인 해야함.
import hashlib import string
def encode(input_string): h = hashlib.md5(input_string[:4]).hexdigest() table = { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 0 } out = "" prev = "" stage1 = [] stage2 = [] stage3 = "" passbyte = -1 for ch in input_string: if ch in table.keys(): stage1.append(table[ch]) else: stage1.append(ch)
for index, ch in enumerate(stage1): if len(stage1) <= index+1: if index != passbyte: stage2.append(ch) break if passbyte != -1 and passbyte == index: continue if type(ch) == int and type(stage1[index+1])==int: tmp = ch << 4 tmp |= stage1[index+1] stage2.append(tmp) passbyte = index+1 else: stage2.append(ch)
for ch in stage2: if type(ch) == int: stage3 += chr(ch) else: stage3 += ch
for index, ch in enumerate(stage3): if index >= len(h): choice = 0 else: choice = index
out += chr(ord(ch) ^ ord(h[choice]))
encoded = "~u/" if out == encoded[0:len(out)]: print "[%s] match" % input_string return True def main(): for index in string.ascii_letters: for index1 in string.ascii_letters: for index2 in string.ascii_letters: for index3 in string.ascii_letters: encode(index+index1+index2+index3)
if __name__ == "__main__" : main()
E:\Temp>python codegate_compress_v.0.1.py [dhdj] match [diad] match [FLag] match [MAaf] match
import hashlib import string
def encode(input_string): h = hashlib.md5(input_string[:4]).hexdigest() table = { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 0 } out = "" prev = "" stage1 = [] stage2 = [] stage3 = "" passbyte = -1 for ch in input_string: if ch in table.keys(): stage1.append(table[ch]) else: stage1.append(ch)
for index, ch in enumerate(stage1): if len(stage1) <= index+1: if index != passbyte: stage2.append(ch) break if passbyte != -1 and passbyte == index: continue if type(ch) == int and type(stage1[index+1])==int: tmp = ch << 4 tmp |= stage1[index+1] stage2.append(tmp) passbyte = index+1 else: stage2.append(ch)
for ch in stage2: if type(ch) == int: stage3 += chr(ch) else: stage3 += ch
for index, ch in enumerate(stage3): if index >= len(h): choice = 0 else: choice = index
while count < len(encoded): for index in string.printable: if encode(input_str+index) == True: input_str += index break count += 1 if __name__ == "__main__" : main()
E:\Temp>python codegate_compress_v.0.1.py string : FLag [FLag ] match [FLag i] match [FLag is] match [FLag is ] match [FLag is {] match [FLag is {c] match [FLag is {co] match [FLag is {com] match [FLag is {comp] match [FLag is {compr] match [FLag is {compre] match [FLag is {compres] match [FLag is {compress] match [FLag is {compress_] match [FLag is {compress_i] match [FLag is {compress_is] match [FLag is {compress_is_] match [FLag is {compress_is_a] match [FLag is {compress_is_al] match [FLag is {compress_is_alw] match [FLag is {compress_is_alwa] match [FLag is {compress_is_alway] match
for index, ch in enumerate(stage1): if len(stage1) <= index+1: if index != passbyte: stage2.append(ch) break if passbyte != -1 and passbyte == index: continue if type(ch) == int and type(stage1[index+1])==int: tmp = ch << 4 tmp |= stage1[index+1] stage2.append(tmp) passbyte = index+1 else: stage2.append(ch)
for ch in stage2: if type(ch) == int: stage3 += chr(ch) else: stage3 += ch
for index, ch in enumerate(stage3): if index >= len(h): choice = 0 else: choice = index
out += chr(ord(ch) ^ ord(h[choice]))
#if out == "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc": if out == "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E"[0:len(out)]: print "[%s] match" % input_string print "encode count : %d" % len(out) return True encoded = "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E" input_str = "FLag is {compress_is_always_" loop = len(input_str)
while loop < len(encoded): for index in string.printable: for index1 in string.printable: if encode(input_str+index+index1) == True: input_str += index+index1 loop += 2 print "decode string length : %d" % loop print "encode string length : %d" % len(encoded)
E:\Temp>python _codegate_compress.py [FLag is {compress_is_always_he] match encode count : 28 [FLag is {compress_is_always_help] match encode count : 30 [FLag is {compress_is_always_helpfu] match encode count : 32 [FLag is {compress_is_always_helpful!] match encode count : 34