B = [621, 835, 247, 356, 785] C = [436, 368, 637, 79, 395] S = [95, 121, 254, 657, 781] def my_func(eb, db, nb, ec, dc, nc, num_sec_b, num_sec_c): const = pow(2, 10)-1 x1 = pow(C[num_sec_b], eb) % nb FBI_B = x1 & C[num_sec_b] x2 = pow(B[num_sec_c], ec) % nc FBI_C = x2 & B[num_sec_c] print 'FBI from Bob - ', bin(FBI_B) print 'FBI from Carrol - ', bin(FBI_C) b_shtrih = [] c_shtrih = [] for b in B: b_shtrih.append(b ^ (const ^ FBI_B)) for c in C: c_shtrih.append(c ^ (const ^ FBI_C)) print 'b_shtrih - ', b_shtrih, 'c_shtrih - ', c_shtrih for_bob = [] for_carrol = [] i = 0 for c_s in c_shtrih: for_bob.append(pow(c_s, db) % nb ^ S[i]) i += 1 i = 0 for b_s in b_shtrih: for_carrol.append(pow(b_s, dc) % nc ^ S[i]) i += 1 print 'for_bob - ', for_bob, 'for_carrol - ', for_carrol S_for_bob = C[num_sec_b] ^ for_bob[num_sec_b] S_for_carrol = B[num_sec_c] ^ for_carrol[num_sec_c] print "Bob's Secret - ", S_for_bob, "Carrol's Secret - ", S_for_carrol my_func(13, 61, 851, 17, 2477, 3953, 2, 3)