from playcrypt.primitives import * from playcrypt.tools import * from playcrypt.ideal.function_family import * from playcrypt.games.game_kr import GameKR from playcrypt.simulator.kr_sim import KRSim from playcrypt.ideal.block_cipher import BlockCipher keyLen = 1 # measured in bytes blockLen = 1 #measured in bytes def A(fn): r""" The adversary attacking the block cipher. This adversary may run in exponential time, so we use short keys. :param fn: a function pointer that allows the adverseary to make queries to the block cipher. The challenger will respond to query x by evaluating the block cipher, using the secret key k: :return the string representing the secret key. """ x = random_string(blockLen) y = fn(x) keyList = [] return keyList[0] # DO NOT EDIT THIS FUNCTION # def encrypt(k, x): r""" The encryption algorithm used in the fn queries. """ return b.encode(k, x) # Use this block for any printing/testing, do not leave stray print # statements outside this block. if __name__ == "__main__": keyLen= 1 blockLen = 1 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1)) keyLen = 2 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1)) blockLen = 2 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1)) keyLen = 3 blockLen =1 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1)) blockLen = 2 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1)) blockLen = 3 b = BlockCipher(keyLen, blockLen) g = GameKR(encrypt, keyLen, blockLen) s = KRSim(g, A) print("------------", "keyLen: ", keyLen, "blockLen: ", blockLen, "------------------------") print(s.compute_success_ratio(1))