コード例 #1
0
ファイル: miner.py プロジェクト: AntoniMaton/zcashd-miner
 def submit_block(self, template, cb_tx, header_with_solution_bin):
     txs = get_txs_from_template(template)
     block_bin = ''.join((
         header_with_solution_bin,
         pack_varint(len(txs) + 1),
         # hex_to_bin(template['coinbasetxn']['data']),
         cb_tx,
         ''.join(txs),
     ))
     block_hex = bin_to_hex(block_bin)
     result = self.server.submitblock(block_hex)
     return bin_to_hex(
         double_sha256_digest(header_with_solution_bin)[::-1]), result
コード例 #2
0
ファイル: block.py プロジェクト: phuongwd/blockchain
 def details(self):
     return self.summary + \
            "Hash (bin)               : {:}\n" \
            "Hash (hex)               : {:}\n" \
            "Nonce                    : {:010d}\n" \
            "Extra-nonce              : {:010d}\n" \
            "Merkle root              : {:}\n" \
                .format(
                bin_str(bytes_to_int(self.hash), pad=service.hash_f.bits),
                bin_to_hex(self.hash),
                self.nonce,
                self.extra_nonce,
                bin_to_hex(self.merkle_root)
            )
コード例 #3
0
def fixed_xor(s1, s2):
	"""Computes the fixed XOR between two hexadecimal strings."""
	try:
		b1 = utils.hex_to_bin(s1)
		b2 = utils.hex_to_bin(s2)
		res_b = fixed_xor_bins(b1, b2)
	except utils.InvalidArgumentError as err:
		# Raise again as an error of this module for better clarity.
		raise InvalidArgumentError(err)

	return utils.bin_to_hex(res_b)
コード例 #4
0
ファイル: block.py プロジェクト: phuongwd/blockchain
 def summary(self):
     return \
         "Num. transactions        : {:}\n" \
         "Difficulty               : {:}\n" \
         "Previous block           : {:}\n" \
         "Target                   : {:}\n" \
             .format(
             len(self._transactions),
             self._difficulty,
             bin_to_hex(self.hash_prev),
             bin_str(self.target, pad=service.hash_f.bits),
         )
コード例 #5
0
def encode(text, polynomial):
    # transforma texto em uma lista de strings de binario
    bin_list = [utils.char_to_bin(c, 7) for c in text]

    # adiciona o bit de paridade em cada letra que são 7 bits
    for i in range(0, len(bin_list)):
        # calcula crc de um caracter com n-1 0s concatenados a direita, 
        # onde n é o tamanho do polinomio gerador
        bin_list[i] += calculate_crc(bin_list[i] + "".zfill(len(polynomial) - 1),  polynomial)

        # converter para hexadecimal.
        bin_list[i] = utils.bin_to_hex(bin_list[i])

    # concatena e retorna o resultado.
    result = "".join(bin_list)

    return result.upper()
コード例 #6
0
def encode_calc_hamming(binary):

    # inverte o binario
    bin_inv = list(binary[::-1])
    print(bin_inv)
    # para cada elemento 2^1 colocar 0
    for i in __range_power2__(len(bin_inv)):
        bin_inv.insert(i, "0")
    print(bin_inv)
    # pegar os indices que possuem 1
    index_list = __get_index_elemt_equals_one__(bin_inv)
    # pega as colunas de bits
    xor_list = list(map(list, zip(*index_list)))
    # realiza a paridade entre os bits
    xor_list = list(map(utils.parity, xor_list))[::-1]

    for i in range(len(xor_list)):
        # para cada bit gerado do xor por no novo binario
        bin_inv[(2**i) - 1] = xor_list[i]

    # converter este binario para hex
    return utils.bin_to_hex("".join(bin_inv[::-1]))
コード例 #7
0
 def testBinToHex_Incomplete(self):
     self.assertEqual('a', utils.bin_to_hex('1010101'))
コード例 #8
0
 def testBinToHex(self):
     self.assertEqual('ab', utils.bin_to_hex('10101011'))
コード例 #9
0
 def Encode(self, text, key):
     """The result is the string as hexadecimals."""
     bin_result = self._DoEncode(text, key)
     return utils.bin_to_hex(bin_result)
コード例 #10
0
ファイル: parser.py プロジェクト: Benderx2/athena_bot
def parse_ath_message(mycode, mystr):
		if mycode.startswith(".bf ", 0, 4) == True:
			mycode = mycode.replace(".bf ", "")
			irc.send_msg(bfc.compile_bf(mycode), variables.channel)
			signal.alarm(0)
		elif mycode.startswith(".be ", 0, 4) == True:
			mycode = mycode.replace(".be ", "")
			irc.send_msg(bec.compile_be(mycode), variables.channel)
			signal.alarm(0)
		elif mycode.startswith(".ul ", 0, 4) == True:
			print mycode
			mycode = mycode.replace(".ul ", "")
			irc.send_msg(ulc.compile_ul(mycode), variables.channel)
			signal.alarm(0)
		elif mycode.startswith(".test", 0, 5) == True:
			utils.test()
		elif mycode.startswith(".eval", 0, 5) == True:
			output = "Result: " + utils.evaluate_expression(mycode)
			irc.send_msg(output, variables.channel)
		elif mycode.startswith(".d2h", 0, 4) == True:
			utils.decimal_to_hex(mycode)
		elif mycode.startswith(".h2d", 0, 4) == True:
			utils.hex_to_decimal(mycode)
		elif mycode.startswith(".d2b", 0, 4) == True:
			utils.decimal_to_bin(mycode)
		elif mycode.startswith(".h2b", 0, 4) == True:
			utils.hex_to_bin(mycode)
		elif mycode.startswith(".b2h", 0, 4) == True:
			utils.bin_to_hex(mycode)
		elif mycode.startswith(".b2d", 0, 4) == True:
			utils.bin_to_decimal(mycode)
		elif mycode.startswith(".join", 0, 5) == True:
			user = mystr['PREFIX']
			user = user.split('!')
			if user[0] != variables.head_user:
				irc.send_msg("You need to be: " + variables.head_user + " to make me join a channel", variables.channel)	
			else:
				mychan = mycode.replace(".join", "")
				mychan = mychan.replace(" ", "")
				if mychan == "0":
					irc.send_msg(variables.i_hate_you, variables.channel)
				else:
					irc.join_channel(mychan)

		elif mycode.startswith(".leave", 0, 6):
			user = mystr['PREFIX']
			user = user.split('!')
			if user[0] != variables.head_user:
				irc.send_msg("You need to be: " + variables.head_user + " to make me leave a channel", variables.channel)	
			else:
				mychan = mycode.replace(".leave", "")
				mychan = mychan.replace(" ", "")
				if mychan == "0":
					irc.send_msg(variables.i_hate_you, variables.channel)
				else:
					irc.leave_channel(mychan)
		elif mycode.startswith(".time ", 0, 6) == True:
			utils.get_time(mycode)
		elif mycode.startswith(".ccount ", 0, 8) == True:
			mycode = mycode.replace(".ccount ", "")
			length = 0
			if check_if_unicode(mycode) == True:
				length = unicode_len(mycode)
			else:
				length = len(mycode)
			irc.send_msg("Length: " + str(length), variables.channel)
		elif mycode.startswith(".help", 0, 5) == True:
			irc.send_msg(help.athena_help, variables.channel)
		elif mycode.startswith(".list", 0, 5):
			irc.send_msg("List of modules: " + str(list(imports())), variables.channel)	
		elif mycode.startswith(".xkcd ", 0, 6):
			irc.send_msg(u'\u200b' + xkcd.search_xkcd(mycode.replace(".xkcd ", "")), variables.channel)
		elif mycode.startswith(".tr ", 0, 4):
			mycode = mycode.replace(".tr ", "")
			lang = mycode[:2]
			mycode = mycode.replace(lang, "")
			irc.send_msg(utils.translate_lang(lang, mycode), variables.channel)
		elif mycode.startswith(".bftxt ", 0, 7):
			mycode = mycode.replace(".bftxt ", "")
			irc.send_msg("Output: " + bftxt.bf(mycode), variables.channel)
		elif mycode.startswith(".df ", 0, 4):
			mycode = mycode.replace(".df ", "")
			irc.send_msg("Output: " + deadfish.compile_df(mycode), variables.channel)
		elif mycode.startswith(".source", 0, 7):
			irc.send_msg(u"\u200bhttps://github.com/Benderx2/athena_bot", variables.channel)
コード例 #11
0
ファイル: utils_test.py プロジェクト: shainer/matasano
	def testBinToHex_Incomplete(self):
		self.assertEqual('a', utils.bin_to_hex('1010101'))
コード例 #12
0
ファイル: utils_test.py プロジェクト: shainer/matasano
	def testBinToHex(self):
		self.assertEqual('ab', utils.bin_to_hex('10101011'))