Skip to content

Instantly share code, notes, and snippets.

class ByteSearch:
def __init__(self, oracle, confidence_threshold=0.9, quiet=True):
self._counter = 0
self.oracle = oracle
self.queries = [[] for _ in range(256)]
self.confidences = [1/256]*256
self.confidence_threshold = confidence_threshold
self.quiet = quiet
def update_confidences(self, index, result):
@staticmethod
def bayes(h, e_given_h, e_given_not_h):
"""Update the posterior probability of h given e.
e: evidence
h: hypothesis
e_given_h: probability of e given h
e_given_not_h: probability of e given not h
"""
return e_given_h * h / (e_given_h * h + e_given_not_h * (1 - h))
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from random import random, seed, randrange
from math import log2
KEY = bytes(16)
IV = bytes(range(16))
PT = b'Plaintext!'