Bitcoin Forum
May 25, 2024, 11:28:52 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Wallet software / Re: Need help recovering private key from 2009-2010 on: December 07, 2023, 06:27:11 AM
Quote: Also keep in mind that removing all question marks it leaves you with 66 chars. You still need to remove 2 

Could the first 2 characters be 0X ? If so, you can remove these 2 leaving you with 64 chars (32 hex pairs)
often hex output is prefixed with 0X to denote a hex string follows.

Thanks. Then how would I use the result? Just convert the hex to another format?
2  Bitcoin / Wallet software / Re: Need help recovering private key from 2009-2010 on: October 13, 2023, 12:21:07 AM
Thank you all for sharing your ideas and suggestions. It is helping to jog my memory.

I'm wondering how to create a CUDA program. The goal of this program would be to generate all conceivable permutations based on the current understanding of characters. From these permutations, the program should then be able to produce both compressed and uncompressed private keys. Once these keys are generated, it should derive their corresponding addresses. Then, it should check the balances of these addresses against a public directory to find matches.

I stumbled upon a potential hint that I had penned down in a different section of the notebook. However, I'm struggling to decode its exact meaning. Given that the missing characters are expected to be of the HEX variety, I'm leaning towards the idea that creating a CUDA-based solution might be our most efficient route to uncover these characters.

This is the hint: The numbers in my note are separated by single, double, or even multiple vertical lines. For context, I've denoted these vertical lines using the character located directly below the backspace key on a standard keyboard.

5| | | 6| | | 7|9|8|    5| | | 6|7|8|9|10|11|12
     2|3|4|                            2|3|4|
       1|                                   1|


I did a little research. Would a good starting template for the CUDA program look like this? Do you have any feedback?

Code:
// Including required header files
#include <stdio.h>
#include <cuda_runtime.h>
#include <math.h>

// CUDA Kernel function for generating permutations
__global__ void generatePermutations(char *baseString, char *result, unsigned long long num_permutations, unsigned long long offset) {
    // Calculate the global index for this thread across all blocks
    unsigned long long idx = blockIdx.x * blockDim.x + threadIdx.x + offset;

    // Check if the index exceeds the number of permutations we want to generate
    if (idx >= num_permutations) return;

    // Create a local copy of the base string in this thread
    char localString[81];
    memcpy(localString, baseString, 81);

    // Loop to replace '?' with hexadecimal characters based on idx
    // Start from the end of the string and move toward the beginning
    for (int i = 79; i >= 0; i--) {
        if (localString[i] == '?') {
            int hexVal = idx % 16; // Get the remainder when idx is divided by 16
            if (hexVal < 10) {
                localString[i] = '0' + hexVal; // If hexVal is a single-digit number
            } else {
                localString[i] = 'A' + (hexVal - 10); // If hexVal is a letter (A-F)
            }
            idx /= 16; // Divide idx by 16 for the next '?'
        }
    }

    // Store the generated string into the result array on the GPU
    memcpy(&result[(blockIdx.x * blockDim.x + threadIdx.x) * 81], localString, 81);
}

// Main program function
int main() {
    // Initialize your 80-character string with 14 '?' characters, plus a null-terminator
    char baseString[81] = "BASE_STRING_WITH_14_?";

    // Declare device pointers for the base string and the result array
    char *d_baseString, *d_result;

    // Number of permutations to generate in this subset (due to memory limitations)
    unsigned long long subset_size = 1e5;
    size_t result_size = 81 * subset_size; // Size of the result array in bytes

    // Allocate memory on the GPU for the base string and result array
    cudaMalloc((void**)&d_baseString, 81);
    cudaMalloc((void**)&d_result, result_size);

    // Copy the base string from the CPU to the GPU
    cudaMemcpy(d_baseString, baseString, 81, cudaMemcpyHostToDevice);

    // Define the number of threads per block and the number of blocks per grid
    int threadsPerBlock = 256;
    int blocksPerGrid = (subset_size + threadsPerBlock - 1) / threadsPerBlock;

    // Launch the CUDA Kernel
    generatePermutations<<<blocksPerGrid, threadsPerBlock>>>(d_baseString, d_result, subset_size, 0);

    // Allocate memory on the CPU to store the result and copy it from the GPU
    char *h_result = (char*) malloc(result_size);
    cudaMemcpy(h_result, d_result, result_size, cudaMemcpyDeviceToHost);

    // You can now process the result further or save it to a file

    // Free the allocated memory on the GPU and CPU
    cudaFree(d_baseString);
    cudaFree(d_result);
    free(h_result);

    return 0;
}

To compile the code:
Code:
nvcc filename.cu -o outputname
./outputname

Retrieve Permutations from GPU: After the CUDA kernel execution, there is a subset of permutations stored in a device array. Copy this array back to the host.
Code:
char *h_result = (char*) malloc(result_size);
cudaMemcpy(h_result, d_result, result_size, cudaMemcpyDeviceToHost);

Initialize OpenSSL: Before using OpenSSL's functions, initialize the library.
Code:
OpenSSL_add_all_algorithms();

Generate Private Key: For each permutation string, generate a SHA-256 hash to serve as a Bitcoin private key
Code:
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, permutation_string, strlen(permutation_string));
SHA256_Final(hash, &sha256);

Generate Public Key: Use the private key to generate an uncompressed public key using ECDSA with the secp256k1 curve
Code:
EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
BIGNUM *bn = BN_bin2bn(hash, 32, NULL);
EC_KEY_set_private_key(eckey, bn);
EC_KEY_generate_key(eckey);

Generate Compressed Public Key: The compressed public key is essentially the X-coordinate of the public key point along with one byte that helps to recover the Y-coordinate.

Code:
const EC_POINT *pub_key = EC_KEY_get0_public_key(eckey);
size_t size = EC_POINT_point2oct(group, pub_key, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
unsigned char *compressed_key = malloc(size);
EC_POINT_point2oct(group, pub_key, POINT_CONVERSION_COMPRESSED, compressed_key, size, NULL);

Cleanup: Don't forget to free any dynamically allocated resources.
Code:
free(h_result);
EC_KEY_free(eckey);
BN_free(bn);
free(compressed_key);

Compile and link C code with OpenSSL:
Code:
gcc your_file.c -o your_program -lcrypto

Combined into a unified program
Code:
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
#include <openssl/ec.h>
#include <openssl/obj_mac.h>
#include <cuda_runtime.h>
#include <math.h>

__global__ void generatePermutations(char *baseString, char *result, unsigned long long num_permutations, unsigned long long offset) {
    unsigned long long idx = blockIdx.x * blockDim.x + threadIdx.x + offset;
    if (idx >= num_permutations) return;

    char localString[81];
    memcpy(localString, baseString, 81);

    for (int i = 79; i >= 0; i--) {
        if (localString[i] == '?') {
            int hexVal = idx % 16;
            localString[i] = hexVal < 10 ? '0' + hexVal : 'A' + (hexVal - 10);
            idx /= 16;
        }
    }
    memcpy(&result[(blockIdx.x * blockDim.x + threadIdx.x) * 81], localString, 81);
}

int main() {
    char baseString[81] = "BASE_STRING_WITH_14_?";
    char *d_baseString, *d_result;
    unsigned long long subset_size = 1e3;
    size_t result_size = 81 * subset_size;

    cudaMalloc((void**)&d_baseString, 81);
    cudaMalloc((void**)&d_result, result_size);
    cudaMemcpy(d_baseString, baseString, 81, cudaMemcpyHostToDevice);

    int threadsPerBlock = 256;
    int blocksPerGrid = (subset_size + threadsPerBlock - 1) / threadsPerBlock;
    generatePermutations<<<blocksPerGrid, threadsPerBlock>>>(d_baseString, d_result, subset_size, 0);

    char *h_result = (char*) malloc(result_size);
    cudaMemcpy(h_result, d_result, result_size, cudaMemcpyDeviceToHost);

    // Initialize OpenSSL
    OpenSSL_add_all_algorithms();

    for (int i = 0; i < subset_size; ++i) {
        char *perm = &h_result[i * 81];

        // Generate SHA-256 Hash
        unsigned char hash[SHA256_DIGEST_LENGTH];
        SHA256_CTX sha256;
        SHA256_Init(&sha256);
        SHA256_Update(&sha256, perm, strlen(perm));
        SHA256_Final(hash, &sha256);

        // Generate Public Key
        EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
        BIGNUM *bn = BN_bin2bn(hash, 32, NULL);
        EC_KEY_set_private_key(eckey, bn);
        EC_KEY_generate_key(eckey);

        // Generate Compressed Public Key
        const EC_GROUP *group = EC_KEY_get0_group(eckey);
        const EC_POINT *pub_key = EC_KEY_get0_public_key(eckey);
        size_t size = EC_POINT_point2oct(group, pub_key, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
        unsigned char *compressed_key = (unsigned char*) malloc(size);
        EC_POINT_point2oct(group, pub_key, POINT_CONVERSION_COMPRESSED, compressed_key, size, NULL);

        // TODO: Store or process the keys

        // Cleanup
        EC_KEY_free(eckey);
        BN_free(bn);
        free(compressed_key);
    }

    // Final Cleanup
    free(h_result);
    cudaFree(d_baseString);
    cudaFree(d_result);

    return 0;
}

Compile the program using both the CUDA and OpenSSL libraries:
Code:
nvcc -o combined_program combined_program.cu -lssl -lcrypto

Run the program:
Code:
./combined_program
3  Bitcoin / Wallet software / Re: Need help recovering private key from 2009-2010 on: September 07, 2023, 10:39:00 PM
Great theories. Here is the exact format I wrote it in, but I changed all the characters. I do remember maybe converting it to hex or binary, or at least considering it.

0486 | 4AE5 | 41BC
A58F | 3FBA | 1AD7

34F6 | 2AEB
37A4 | 4AAF

7?A4 | ?42? | 6F?? | ??D8
71?D | 6?A? | ?FCA | 86B?

32?F
7F?B
4  Bitcoin / Wallet software / Re: Need help recovering private key from 2009-2010 on: August 29, 2023, 11:14:05 PM
It definitely has all the characteristics of hexadecimal. The question marks are sort of spread around the first half of the characters and aren't in the beginning or end. I'm sure I could read everything clearly when I wrote it down so I put the question marks there intentionally. All characters used in hexadecimal are located in the string of characters, so I didn't intentionally leave a specific character or two out and just add those in place of the question marks. I stacked they string of characters in a way I couldn't tell if it was two 40 character keys or an 80 character key. If I only use the top line I have a 40 character string with no question marks, but that is an odd length.

I read this in Armory's FAQ, and opposes some other things I've seen. What kind of key are they talking about here?
"Each bitcoin (or fragment of) belongs to a cryptographic private key, which is an 80-digit number that is essentially impossible to guess. Bitcoins cannot be transferred unless the holder of the private key uses it to create a digital signature authorizing the transaction. A Bitcoin address is a string of letters that let other users know what your digital signature looks like without revealing the private key (it is related to the “public key”)." https://www.bitcoinarmory.com/faq/
5  Bitcoin / Wallet software / Re: Need help recovering private key from 2009-2010 on: August 29, 2023, 09:15:00 PM
Thanks for the information. The public address starts with a 1 and here it is: 1DYFqhdKDkHYytVn66QWKGY4PUebNYH9j9

The character starts with most likely an A or 1, but read another way these are the first three 001.
6  Bitcoin / Wallet software / Need help recovering private key from 2009-2010 on: August 29, 2023, 08:39:58 PM
I finally found the backup I wrote down after using Gavin Andresen's Bitcoin faucet. I don't remember if I was using only Bitcoin Core, Armory, or something like Multi-bit. Those sound familiar.

There are 5 bitcoins in the first address and I never moved or used them. The characters I found on my handwritten paper backup are 80 characters, between (0-9) and (A-F). I wrote these in blocks of four characters. Within these 80 characters, I have 14 question marks. So a total of 66 known characters. I'm not sure if I only need 64, 66, or 80 characters total.

I have Bitcoin Core and Electrs downloaded on my Umbrel to start trying the recovery process. I also have Electrum and Armory downloaded.

I'm not sure the best course to go from here to find out what the key may be and how long it should be. I'm not in a hurry and have time to try to figure this out, hopefully with your help.

Offering a full Bitcoin to the best helper.
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!