def generate(pwd, stat): config.generate_r() pwd = mpz(crypt.get_bit_str_from_byte(pwd), base=2) global table table = [] # clear the table for i in xrange(config.max_features): x_0 = crypt.p(mpz((i + 1) << 1), config.r) # calculate x0, x1 and y0, y1 x_1 = crypt.p(mpz(((i + 1) << 1) + 1), config.r) y_0 = gmpy2.add(poly.calculate(x_0), crypt.g(mpz((i + 1) << 1), config.r ^ pwd)) # use r xor pwd as the key y_1 = gmpy2.add(poly.calculate(x_1), crypt.g(mpz(((i + 1) << 1) + 1), config.r ^ pwd)) if reader.if_init(): table.append((y_0, y_1)) # if in initialization phase, add correct value else: if stat[i][0] is None: table.append((y_0, y_1)) # if no statistic information is derived elif (stat[i][1] + stat[i][0] * config.k) < config.ti: # if fast rand_value = gmpy2.t_mod(config.generate_rand(), config.q) table.append((y_0, rand_value)) elif (stat[i][1] - stat[i][0] * config.k) > config.ti: # if slow rand_value = gmpy2.t_mod(config.generate_rand(), config.q) table.append((rand_value, y_1)) else: table.append((y_0, y_1))
f = open('error.txt', 'w') f.write(features_str) f.write('\n') f.write(features_str_arr[i]) f.write('\n') f.write(feature_str[j]) f.write('\n') f.close() raise features.append(feature) return features if __name__ == "__main__": config.init_random() config.generate_r() config.generate_prime() config.max_features = 10 # test init() init() print decrypt(config.h_pwd) # test add_feature() test_feature = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print "statistics: ", add_feature(test_feature) print "history features: ", history_features print decrypt(config.h_pwd) print "statistics: ", add_feature(test_feature[::-1]) print "history features: ", history_features print decrypt(config.h_pwd)