def interactive_testing(): """Interactive testing""" # %% # noinspection PyUnresolvedReferences runfile("test.py") # pylint: disable=undefined-variable redis_conn = redis.Redis(host='localhost', port=6379, db=0) # %% col = cocktail_col(redis_conn) # %% populate_cocktails(col) # %% sexpr1 = sch.FacetEq(f("ingredients"), "vodka") sexpr2 = sch.FacetEq(f("ingredients"), "rum") # %% sch.run_search(col, sexpr1) # %% or_expr = sch.Or(sexpr1, sexpr2) results = sch.run_search(col, or_expr) print(results) # %% and_expr = sch.And(sexpr1, sexpr2) print(sch.run_search(col, and_expr)) # %% print( sch.run_search( col, sch.And(sch.FacetEq(f("ingredients"), "vodka"), sch.FacetEq(f("ingredients"), "cointreau"))))
def get_root(interval): c, x = interval old_x = x step = 0 while step < MAX_ITERATIONS: step += 1 x = (c * f(x) - x * f(c)) / (f(x) - f(c)) if abs(f(x)) < EPSILON or abs(x - old_x) < EPSILON: return x old_x = x
def get_root(interval): a, b = interval step = 0 while step < MAX_ITERATIONS: step += 1 c = (a + b) / 2.0 if abs(f(c)) < EPSILON and abs(f(b) - f(a)) < EPSILON: return c if same_sign(f(c), f(a)): a = c else: b = c
def get_root(interval): x_n_minus_1, x_n = interval x_n = x_n_minus_1 + 0.2 # fixes decimal stuff step = 0 while step < MAX_ITERATIONS: step += 1 x_n_plus_1 = ((x_n_minus_1) * f(x_n) - x_n * f(x_n_minus_1)) / (f(x_n) - f(x_n_minus_1)) if x_n_plus_1 < interval[0] or interval[1] < x_n_plus_1: print("wtf", x_n_plus_1, interval) if abs(f(x_n_plus_1)) < EPSILON: return x_n_plus_1 x_n_minus_1 = x_n x_n = x_n_plus_1
def verify(S, merch_ans, z, n, e, a_id): xi = [] yi = [] print(z) for i in range(len(z)): if z[i] == 1: yi += [merch_ans[i][0]] xi += [common.h(merch_ans[i][1], merch_ans[i][2])] else: xi += [merch_ans[i][0]] yi += [common.h(merch_ans[i][1], merch_ans[i][2])] f_prod = numpy.prod(list(map(lambda v: common.f(v[0], v[1]), zip(xi, yi)))) print("h(x) signed:\t{}".format((f_prod % n) % n)) print("decrypt:\t{}".format((S**e) % n)) return (f_prod % n) % n == (S**e) % n
def get_root(interval): a, b = interval old_c = 2**1000 step = 0 while step < MAX_ITERATIONS: step += 1 c = (a*f(b)-b*f(a)) / (f(b) - f(a)) if abs(f(c)) < EPSILON or abs(c-old_c) < EPSILON: return c if same_sign(f(c), f(a)): a = c else: b = c old_c = c
def get_root(interval): a, b = interval old_c = 2**1000 step = 0 while step < MAX_ITERATIONS: step += 1 c = (a * f(b) - b * f(a)) / (f(b) - f(a)) if abs(f(c)) < EPSILON or abs(c - old_c) < EPSILON: return c if same_sign(f(c), f(a)): a = c else: b = c old_c = c
def verify(self): xi = [] yi = [] for i in range(len(self.z)): if self.z[i] == 0: xi.append(self.z_answer[i][0]) yi.append(common.h(self.z_answer[i][1], self.z_answer[i][2])) else: xi.append(common.h(self.z_answer[i][1], self.z_answer[i][2])) yi.append(self.z_answer[i][0]) #This is done merchant! f_prod = numpy.prod( list(map(lambda v: common.f(v[0], v[1]), zip(xi, yi)))) hx = f_prod % self.n dec_hx = (self.serial**self.e) % self.n print("Done by merchant! h(x) signed:\t{}".format(hx)) print("Done by merchant! decrypt:\t{}".format(dec_hx)) return hx == dec_hx
def correct_interval(interval): return not same_sign(f(interval[0]), f(interval[1]))