def assign_key(id, p, q): p = fc.hex_to_int(p) q = fc.hex_to_int(q) M = p * q a = compute_a_value(id, M) r = pow(int(a, 16), (M + 5 - (p + q)) // 8, M) return fc.int_to_hex(r)[2:]
def main(nazir_ip, mix_ip, nbr_partners, data): testcap = open(data, 'rb') capfile = savefile.load_savefile(testcap, layers=2, verbose=True) all_sets, distinct_sets = learn(nazir_ip, mix_ip, capfile, nbr_partners) ips = exclude(distinct_sets, all_sets) print("Found the following partners of Nazir:") sum = 0 for ip_set in ips: ip = ip_set.pop() print("IP: {}".format(ip)) sum += fc.hex_to_int(fc.ip_to_hex(ip)) print("Sum of IPs: {}".format(sum))
import format_converter as fc __author__ = "Marcus Rodan" if __name__ == "__main__": print("Question 1: {}".format(fc.int_to_hex(2897))) print("Question 2: {}".format(fc.hash_int(2897, 4))) print("Question 3: {}".format(fc.hex_to_int("0123456789abcdef"))) print("Question 4: {}".format( fc.hex_to_int(fc.hash_int(fc.hex_to_int("0123456789abcdef"), 8))))
def compute_shared_secret(dh_secret, shared_password): g_x1x2_bytes = fc.int2bytearray(dh_secret) sp_bytes = bytearray(shared_password.encode('utf-8')) return fc.hex_to_int(fc.hash_bytearray(g_x1x2_bytes + sp_bytes))
def test_hex_to_int(self): self.assertEqual(format_converter.hex_to_int("000001f4"), 500)
def test_hash_ex2(self): nbr = format_converter.hex_to_int("fedcba9876543210") hash_hex = format_converter.hash_int(nbr, 8) hash_int = format_converter.hex_to_int(hash_hex) self.assertEqual(hash_int, 946229717077375328329532411653585908948565005770)
def f(x_i, y_i): x_bytearray = fc.hex_to_bytearray(x_i) y_bytearray = fc.hex_to_bytearray(y_i) return fc.hex_to_int(fc.hash_bytearray(x_bytearray + y_bytearray))
def decrypt(msg, d, n): return fc.bytearray_to_hex(fc.int2bytearray((fc.hex_to_int(msg)**d) % n))
def f(x_i, y_i): #return fc.bytearray_to_int(fc.hash_bytearray(fc.hex_to_bytearray(x_i) + fc.hex_to_bytearray(y_i))) x_bytearray = fc.hex_to_bytearray(x_i) y_bytearray = fc.hex_to_bytearray(y_i) return fc.hex_to_int(fc.hash_bytearray(x_bytearray + y_bytearray))
def ha(x): return fc.hex_to_int(fc.hash_int(x))
def ip_to_int(ip): return fc.hex_to_int(fc.ip_to_hex(ip))