This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |