Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation in ranges #6

Open
turalyf opened this issue Dec 18, 2023 · 8 comments
Open

Generation in ranges #6

turalyf opened this issue Dec 18, 2023 · 8 comments

Comments

@turalyf
Copy link

turalyf commented Dec 18, 2023

Thank you for such a project. The question is, is it possible to change it so that you can search for keys by ranges, for example, specify 65-66

@RandstormBTC
Copy link
Owner

Thank you for such a project. The question is, is it possible to change it so that you can search for keys by ranges, for example, specify 65-66

If you want to generate private keys within a specific range, you can modify the custom_private_key_generator function to accept a range parameter and use that range to extract a subset of bytes from the random number generator pool. Here's an example modification:

def custom_private_key_generator(rng_simulator=None, key_range=None):
    rng_simulator = rng_simulator or MathRandomSimulator()
    if key_range and len(key_range) == 2:
        start, end = sorted(key_range)
    else:
        start, end = 0, 32
    start = max(0, min(start, 32))
    end = max(0, min(end, 32))
    private_key_bytes = rng_simulator.rng_get_bytes(end - start)[start:]
    private_key_hex = private_key_bytes.hex()
    return private_key_hex

Now, you can call custom_private_key_generator with a range parameter, for example:

private_key = custom_private_key_generator(key_range=(65, 66))
print(private_key)

@turalyf
Copy link
Author

turalyf commented Dec 20, 2023

Thank you for such a project. The question is, is it possible to change it so that you can search for keys by ranges, for example, specify 65-66

If you want to generate private keys within a specific range, you can modify the custom_private_key_generator function to accept a range parameter and use that range to extract a subset of bytes from the random number generator pool. Here's an example modification:


def custom_private_key_generator(rng_simulator=None, key_range=None):

    rng_simulator = rng_simulator or MathRandomSimulator()

    if key_range and len(key_range) == 2:

        start, end = sorted(key_range)

    else:

        start, end = 0, 32

    start = max(0, min(start, 32))

    end = max(0, min(end, 32))

    private_key_bytes = rng_simulator.rng_get_bytes(end - start)[start:]

    private_key_hex = private_key_bytes.hex()

    return private_key_hex

Now, you can call custom_private_key_generator with a range parameter, for example:


private_key = custom_private_key_generator(key_range=(65, 66))

print(private_key)

please tell me in which column to write this code? If it’s not difficult, write down the finished code, indicate the link, I’ll upload it myself. and also, in the previous discussion, they said that key generation takes place in a few days, key generation is in a countdown, what’s the problem? that is, -1,636,737,993 decreases

@RandstormBTC
Copy link
Owner

RandstormBTC commented Dec 21, 2023

In this example, generate_random_string creates a random private key, and extract_key_range extracts a specific range of bytes from that key based on the specified key range. However, Bitcoin private keys are typically generated randomly, and their values are not chosen based on numerical order or ranges.

import random

def generate_random_string():
    # Generate 32 bytes (256 bits) as a list of random integers
    random_bytes = [random.randint(0, 255) for _ in range(32)]

    # Convert the list of integers to a bytes object
    random_bytes = bytes(random_bytes)

    # Convert the bytes to a hexadecimal string
    random_string = random_bytes.hex()

    return random_string

def extract_key_range(random_string, key_range):
    # Ensure key_range is valid
    start, end = key_range
    start = max(0, min(start, 64))  # Ensure start is within bounds
    end = max(0, min(end, 64))  # Ensure end is within bounds

    # Extract the specified range from the random string
    key_subset = random_string[start * 2: end * 2]

    return key_subset

Example usage

generated_string = generate_random_string()
print(f"Generated String: {generated_string}")

key_range = (16, 32) # Example key range
selected_key_range = extract_key_range(generated_string, key_range)
print(f"Selected Key Range: {selected_key_range}")

Output:

Generated Key: cd8dd143c43d55c0dda546a3a13664a562f9a61e3ce7c33d801ec38ce2d24328
Selected Key Range: 62f9a61e3ce7c33d801ec38ce2d24328

@demonluca
Copy link

Thanks for the update, is it possible to choose your own seed of time you want to search like say 13/1/13 13.45 and does it need converting to epoch time? Thanks

@RandstormBTC
Copy link
Owner

RandstormBTC commented Dec 21, 2023

Yes for your example this generates all 60 private keys, 1 for each second for the time:

Date: January 13, 2013
Time: 13:45 (1:45 PM) GMT

import os
import random

class MathRandomSimulator:
    def __init__(self, psize=32, seed=None):
        # Initialize the random number generator pool and set the initial state
        self.rng_pool = bytearray()
        self.rng_pptr = 0  # Pointer to the current position in the pool
        self.rng_psize = psize  # Size of the pool

        # Set the seed to the provided value or generate a random seed
        self._seed = seed if seed is not None else int.from_bytes(os.urandom(4), 'big')
        random.seed(self._seed)

    @property
    def seed(self):
        # Get the current seed value used by the random number generator
        return self._seed

    def rng_get_bytes(self, size):
        # Generate and retrieve the next 'size' bytes from the random number generator pool
        while len(self.rng_pool) < size:
            random_value = int(random.random() * (2**32))
            self.rng_pool.extend(random_value.to_bytes(4, 'big'))

        result = bytes(self.rng_pool[:size])
        self.rng_pool = self.rng_pool[size:]  # Remove the bytes that were returned

        return result
        
def custom_private_key_generator(rng_simulator=None):
    # If no random number generator simulator is provided, create a new one
    rng = MathRandomSimulator() if rng_simulator is None else rng_simulator

    # Generate 32 bytes (256 bits) as the private key
    private_key_bytes = rng.rng_get_bytes(32)

    # Convert the bytes to a hexadecimal string
    private_key_hex = private_key_bytes.hex()

    # Return the generated private key in hexadecimal format
    return private_key_hex
    
# Starting Epoch timestamp 
# Date and time (GMT): Sunday, January 13, 2013 1:45:01 PM
rng_simulator = MathRandomSimulator(seed=1358084723)

for i in range(60): # Loop for one minute (60 seconds)
    private_key = custom_private_key_generator(rng_simulator)
    print(f"Generated Private Key {i + 1}: {private_key}")

Output:

...
Generated Private Key 14: ab472c2f55d9df2621b54422fc1a308e8c72454ccb908078e21eef0d58c0b781
Generated Private Key 15: ef9d8c6d0bb8ed2b45911e7902e117c5737e0940ea53c7a2d327c0e65e0d22d5
Generated Private Key 16: b2792426078f9d1b0f12e8bf4e2ef8bc0431b101df88052c7f09bb425cbee3c7
Generated Private Key 17: 790d5c852f46030a5a463c99872b8469ad7390e3eb484d961b465fe1748f15fb
Generated Private Key 18: e4ef9550e67c3121ad462e5840066e0801e9b9ff8765280e570c8a69eae825c2
Generated Private Key 19: ecba46487dc5ddf5626b7109fffcf850579d2cf1e3a718581ec066f2b324f8ed
Generated Private Key 20: 2b1b8ceb1f5eacad24d74d95dcc537755ec2ebb6787d59d3175548075fb065fc
Generated Private Key 21: c234064e8a86864b266f297855a00861fc2197c20bcdcf2bff09e3dd1c71be08
Generated Private Key 22: ad9f73e58de0c35597c2bb2391d6cf9cebe33071f735d05817b9d4d5de2c5032
Generated Private Key 23: 8a56dbf45d6e9fe352ae3d37361f2512ab5ab60449ec2715d8d182c8f3e16c26
...

@demonluca
Copy link

Nice work that does generate the keys but is it possible you can choose the epoch time to start at and then search sequentially from there? Thanks really enjoy your script!

@turalyf
Copy link
Author

turalyf commented Dec 22, 2023

In this example, generate_random_string creates a random private key, and extract_key_range extracts a specific range of bytes from that key based on the specified key range. However, Bitcoin private keys are typically generated randomly, and their values are not chosen based on numerical order or ranges.


import random



def generate_random_string():

    # Generate 32 bytes (256 bits) as a list of random integers

    random_bytes = [random.randint(0, 255) for _ in range(32)]



    # Convert the list of integers to a bytes object

    random_bytes = bytes(random_bytes)



    # Convert the bytes to a hexadecimal string

    random_string = random_bytes.hex()



    return random_string



def extract_key_range(random_string, key_range):

    # Ensure key_range is valid

    start, end = key_range

    start = max(0, min(start, 64))  # Ensure start is within bounds

    end = max(0, min(end, 64))  # Ensure end is within bounds



    # Extract the specified range from the random string

    key_subset = random_string[start * 2: end * 2]



    return key_subset

Example usage

generated_string = generate_random_string()

print(f"Generated String: {generated_string}")

key_range = (16, 32) # Example key range

selected_key_range = extract_key_range(generated_string, key_range)

print(f"Selected Key Range: {selected_key_range}")

Output:

Generated Key: cd8dd143c43d55c0dda546a3a13664a562f9a61e3ce7c33d801ec38ce2d24328

Selected Key Range: 62f9a61e3ce7c33d801ec38ce2d24328

I could not get. Gives an error message. Can you please send me the finished script by email?

[email protected]

I will be very grateful 🙏🏻

@turalyf
Copy link
Author

turalyf commented Dec 24, 2023

Unfortunately, after two days it again generates a countdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants