#!/usr/bin/python # For simplicity, the message space and the key space consists of 32-bit integers # And the ciphertext space of integers (possibly longer) import random # A bad encryption scheme def enc(key,msg): return key*msg # The IND-OT-CPA game def indotcpa_game(enc,adv1,adv2): ??? # The adversary breaking the above encryption scheme # (Consisting of two functions, since the adversary is invoked twice by the game) def adv1(): ??? def adv2(c): ??? def test_indotcpa(enc,adv1,adv2): num_true = 0 num_tries = 100000 for i in range(num_tries): if indotcpa_game(enc,adv1,adv2): num_true += 1 ratio = float(num_true)/num_tries print ratio # An output near 0.5 means no attack # An output neat 0.0 or 1.0 means a successful attack test_indotcpa(enc,adv1,adv2)