Ejemplo n.º 1
0
def main():
    setup_oracle()
    ct = encryption_oracle("A" * 32)
    cut = ct[16:32]
    paste = common.xor_strings(
        common.xor_strings("BBBB;admin=true;", "A" * 16), cut)
    print decryption_oracle(ct[0:16] + paste + ct[32:])
Ejemplo n.º 2
0
    def post(self):
        expected = ['pb1', 'pb2', 'pb3', 'mg', 'he']
        data = {}
        del qlog.buf[:]
        locs = {}

        for item in expected:
            i = request.json.get(item)
            if i:
                x, y = i.split(',')
                locs[item] = Cell(int(x), int(y))

        if len(locs.keys()) != len(expected):
            error = {"code": "MISSING_SOMETHING"}
            return jsonify({'error': error}), 400

        pirate_band = [Unit(pirate_basetype) for _ in range(3)]
        locations = [locs[item] for item in ['pb1', 'pb2', 'pb3']]
        unit_locations = {pirate_band[i]: locations[i] for i in range(3)}
        unit_locations[Unit(mud_golem_basetype)] = locs['mg']
        dun = Dungeon(unit_locations, 8, 8, hero_entrance=locs['he'])
        test_game = DreamGame.start_dungeon(dun, Unit(demohero_basetype))
        all_units = test_game.print_all_units()
        xprint(all_units)
        hero_turns = test_game.loop(player_berserk=True)
        xprint("hero has made {} turns.".format(hero_turns))
        message = json.dumps({'log': qlog.buf})
        key = genkey(len(message))
        ciphertext = xor_strings(bytes(message, "ascii"), key)
        byt1 = base64.standard_b64encode(ciphertext)
        byt2 = base64.standard_b64encode(key)
        data['b1'] = byt1.decode('ascii')
        data['b2'] = byt2.decode('ascii')
        output = json.dumps(data)
        return output, 200
def solve_block(curblock, prevblock):
    intermediate = [""] * 16
    bytes_recovered = ""
    nextpad = ""
    for i in range(15, -1, -1):
        # print i
        # print bytes_recovered
        # print nextpad
        slide = "A" * i
        candidates = []
        for t in range(0x100):
            if decryption_oracle(curblock, slide + chr(t) + nextpad):
                candidates.append(chr(t))
        if len(candidates) != 1:
            print "unlucky!"
            # print candidates
            exit(1)
        else:
            match = candidates[0]
            intermediate[i] = chr(ord(match) ^ (16 - i))
            bytes_recovered = chr(ord(match) ^ ord(prevblock[i])
                                  ^ (16 - i)) + bytes_recovered
            nextpad = common.xor_strings((chr(16 - i + 1) * (16 - i)),
                                         intermediate[i:])

    return bytes_recovered
Ejemplo n.º 4
0
def aes_ctr_encrypt(pt, key, nonce):
    ctr = 0
    ct = ""
    for i in range(0, len(pt), 16):
        # little endian ctr string
        keystream_input = struct.pack("<QQ", nonce, ctr)
        keystream = common.aes_encrypt_block(keystream_input, key)
        ct += common.xor_strings(keystream[:len(pt[i:i + 16])], pt[i:i + 16])
        ctr = (ctr + 1) % (2**64)

    return ct
def aes_ctr_encrypt(pt, key, nonce):
        ctr = 0
        ct = ""
        for i in range(0, len(pt), 16):
                # little endian ctr string
                keystream_input = struct.pack("<QQ", nonce, ctr)
                keystream = common.aes_encrypt_block(keystream_input, key)
                ct += common.xor_strings(keystream[:len(pt[i:i+16])], pt[i:i+16])
                ctr = (ctr + 1) % (2 ** 64)

        return ct
Ejemplo n.º 6
0
def demo():
    data = {}
    del qlog.buf[:]
    test_game = demo_game()
    all_units = test_game.print_all_units()
    xprint(all_units)
    hero_turns = test_game.loop(player_berserk=True)
    xprint("hero has made {} turns.".format(hero_turns))
    message = json.dumps({'log': qlog.buf})
    key = genkey(len(message))
    byt1 = base64.standard_b64encode(xor_strings(bytes(message, "ascii"), key))
    byt2 = base64.standard_b64encode(key)
    data['b1'] = byt1.decode('ascii')
    data['b2'] = byt2.decode('ascii')
    output = json.dumps(data)
    return output, 200
def solve_block(curblock, prevblock):
        intermediate = [""] * 16
        bytes_recovered = ""
        nextpad = ""
        for i in range(15, -1, -1):
                # print i
                # print bytes_recovered
                # print nextpad
                slide = "A" * i 
                candidates = []
                for t in range(0x100):
                        if decryption_oracle(curblock, slide + chr(t) + nextpad):
                                candidates.append(chr(t))
                if len(candidates) != 1:
                        print "unlucky!"
                        # print candidates
                        exit(1)
                else:
                        match = candidates[0]
                        intermediate[i] = chr(ord(match) ^ (16 - i))
                        bytes_recovered = chr(ord(match) ^ ord(prevblock[i]) ^ (16 - i)) + bytes_recovered
                        nextpad = common.xor_strings((chr(16 - i + 1) * (16 - i)), intermediate[i:])

        return bytes_recovered
def main():
        setup_oracle()
        ct = encryption_oracle("A" * 32)
        cut = ct[16:32]
        paste = common.xor_strings(common.xor_strings("BBBB;admin=true;", "A" * 16), cut)
        print decryption_oracle(ct[0:16] + paste + ct[32:])