def str2hex(_str): """ the following function will be used to convert a strin chr message into hex-digits string """ str_bin = pad_to_block(string_to_bits(_str), ASCII_BITS) return hex(int(display_bits(str_bin), 2))[2:-1].zfill(len(str_bin) / 4)
def test_counter_block_function(): hex_nonce = ''.join('00 6C B6 DB'.split()) print hex_nonce hex_iv = ''.join('C0 54 3B 59 DA 48 D9 0B'.split()) print hex_iv bin_nonce = pad_to_block(convert_to_bits(int(hex_nonce, 16)), len(hex_nonce)*4) print bin_nonce bin_iv = pad_to_block(convert_to_bits(int(hex_iv, 16)), len(hex_iv)*4) ctr = Counter.new(32) def counter_block(): return bits_to_string(bin_nonce + bin_iv + string_to_bits(ctr())) final_str = hex(int(display_bits(string_to_bits(counter_block())), 2))[2:-1].zfill(32) print final_str print final_str == ''.join('00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 01'.lower().split()) final_str = hex(int(display_bits(string_to_bits(counter_block())), 2))[2:-1].zfill(32) print final_str print final_str == ''.join('00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 02'.lower().split())
def generate_bills(bill_amount, bill_count=100): global _NONCES _NONCES = [] bills = [] for _ in range(bill_count): bill = create_bill(random.randint(0, 100), bill_amount) bill_int = bits_to_int(string_to_bits(bill)) nonce = random_nonce() t = blind_msg(bill_int, nonce, BANK_PUBLIC_KEY[0], BANK_PUBLIC_KEY[1]) _NONCES.append(nonce) bills.append(t) return bills
def test_counter_block_function(): hex_nonce = ''.join('00 6C B6 DB'.split()) print hex_nonce hex_iv = ''.join('C0 54 3B 59 DA 48 D9 0B'.split()) print hex_iv bin_nonce = pad_to_block(convert_to_bits(int(hex_nonce, 16)), len(hex_nonce) * 4) print bin_nonce bin_iv = pad_to_block(convert_to_bits(int(hex_iv, 16)), len(hex_iv) * 4) ctr = Counter.new(32) def counter_block(): return bits_to_string(bin_nonce + bin_iv + string_to_bits(ctr())) final_str = hex(int(display_bits(string_to_bits(counter_block())), 2))[2:-1].zfill(32) print final_str print final_str == ''.join( '00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 01'.lower().split()) final_str = hex(int(display_bits(string_to_bits(counter_block())), 2))[2:-1].zfill(32) print final_str print final_str == ''.join( '00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 02'.lower().split())
def counter_block(): return bits_to_string(bin_nonce + bin_iv + string_to_bits(ctr()))
def create_bill_message(i, bill_amount, nonce): bill = create_bill(i, bill_amount) # print "Created bill:", bill bill_int = bits_to_int(string_to_bits(bill)) t = blind_msg(bill_int, nonce, BANK_PUBLIC_KEY[0], BANK_PUBLIC_KEY[1]) return t
def create_bill_message(i, bill_amount, nonce): bill = create_bill(i, bill_amount) bill_int = bits_to_int(string_to_bits(bill)) t = blind_msg(bill_int, nonce, BANK_PUBLIC_KEY[0], BANK_PUBLIC_KEY[1]) return t
def string_to_int(s): return bits_to_int(string_to_bits(s))