Bitcoin Forum
May 25, 2024, 09:40:18 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bit range of a private key  (Read 145 times)
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 05, 2023, 05:21:18 AM
Last edit: January 05, 2023, 01:27:12 PM by yoshimitsu777
 #1

if you have some private key how can i quickly find out which bit range this key is in?

example private key 1A9FF47

i know it is inside bit range 25 (1000000 - 2000000) but is the any python tool that allows to quickly display this?
if tool also possible to display the range after input of bit range would be great

example input bit range 25 - output = 1000000:2000000

edit: range corrected
witcher_sense
Legendary
*
Offline Offline

Activity: 2352
Merit: 4369


🔐BitcoinMessage.Tools🔑


View Profile WWW
January 05, 2023, 06:17:14 AM
 #2

example input bit range 25 - output = 100000:200000
Excuse my ignorance, what formula do you use to calculate these values? Why 25 bits are in range 100000-200000?

As for number of bits, you can use this:

Code:
def eval_bit(key):
    return len(f'{int(key, 16):b}')


print(eval_bit('1A9FF47'))

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
PowerGlove
Hero Member
*****
hacker
Offline Offline

Activity: 514
Merit: 4096



View Profile
January 05, 2023, 06:47:43 AM
Merited by ABCbits (1), witcher_sense (1)
 #3

I think this is what you're after:

Code:
def get_bit_length(value: int) -> int:

    return len(bin(value)[2:])

def print_bit_range(value: int, *, inclusive: bool = False) -> None:

    bit_length = get_bit_length(value)

    print(f'Range {bit_length}: {hex(2**(bit_length-1))[2:]}-{hex(2**bit_length - (1 if inclusive else 0))[2:]}')

print_bit_range(0x1A9FF47)

Range 25: 1000000-2000000
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 05, 2023, 01:27:32 PM
 #4

fantastic - thank you
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!