Chronomex 3233 py code

From otp22 db
Jump to: navigation, search
#!/usr/bin/python
 
import mmap
 
def test_op(str1, str2, fun):
    trial = map(fun, str1, str2)
    def printable(char): return ((char > " ") and (char < "~"))
 
    printed = filter(printable, trial)
    if len(printed) > (len(trial) - 3):
        # if there are up to 3 nonprintable characters, it's ok
        return "".join(trial)
    else:
        return False
 
def xor(e1, e2): return chr(ord(e1) ^ ord(e2))
def add(e1, e2): return chr((ord(e1) + ord(e2)) % 255)
def sub(e1, e2): return chr((ord(e1) - ord(e2)) % 255)
 
with open("data.bin", "rb") as f:
    mapped = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    off = 0
    string1 = "\x32\x33\x0A"
    string2 = "\x7F\xFE\xCA\x26\xB6\x3E\xD8\xD5\x61\x8E\x59\x95\x69\x6F\x8C\xC8\xE5\xB5\xDF\xBD\xFA\x84\x9C"
    off = 520000000
    while (off <= (mapped.size() - len(string2))):
        mapped.seek(off)
        key_string = mapped.read(len(string2))
        _add = test_op(string2, key_string, add)
        _sub = test_op(string2, key_string, sub)
        _xor = test_op(string2, key_string, xor)
 
        if (_add):
            print off, "add", _add
        if (_sub):
            print off, "sub", _sub
        if (_xor):
            print off, "xor", _xor
 
        if off % 1000000 == 0:
            print off
 
        off += 1


Main Page