Bitcoin Forum
May 05, 2024, 06:04:17 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Key generator in hex format  (Read 337 times)
temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 02, 2020, 10:50:46 AM
 #1

Hi, everybody.
Tell me how I can generate millions of keys in hex format with output one per line without any extra characters?
This should work on Linux
1714932257
Hero Member
*
Offline Offline

Posts: 1714932257

View Profile Personal Message (Offline)

Ignore
1714932257
Reply with quote  #2

1714932257
Report to moderator
1714932257
Hero Member
*
Offline Offline

Posts: 1714932257

View Profile Personal Message (Offline)

Ignore
1714932257
Reply with quote  #2

1714932257
Report to moderator
It is a common myth that Bitcoin is ruled by a majority of miners. This is not true. Bitcoin miners "vote" on the ordering of transactions, but that's all they do. They can't vote to change the network rules.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714932257
Hero Member
*
Offline Offline

Posts: 1714932257

View Profile Personal Message (Offline)

Ignore
1714932257
Reply with quote  #2

1714932257
Report to moderator
AdolfinWolf
Legendary
*
Offline Offline

Activity: 1946
Merit: 1427


View Profile
February 02, 2020, 05:12:17 PM
Last edit: February 02, 2020, 05:43:25 PM by AdolfinWolf
 #2

Something like https://github.com/matja/bitcoin-tool ?

I'm not sure what would be the most efficient library to generate millions of keys in HEX format.
But i guess you could also use https://github.com/bitcoinjs/bitcoinjs-lib (But again, for something more efficient you might want to use a more low-level language..)

temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 02, 2020, 05:31:44 PM
 #3

Something like https://github.com/matja/bitcoin-tool ?

I'm not sure what would be the most efficient library to generate millions of keys in HEX format (or why you would want HEX format, as you'd lose compression data(?))
But i guess you could also use https://github.com/bitcoinjs/bitcoinjs-lib

I tried the command keys=1000; openssl rand $[32*keys] | xd-pc 32
but more than 60000000 at a time does not generate I need continuous generation of random keys
LoyceV
Legendary
*
Offline Offline

Activity: 3304
Merit: 16599


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
February 02, 2020, 06:02:41 PM
 #4

I need continuous generation of random keys
Can you share what you're trying to accomplish?

Anis1984
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
February 02, 2020, 09:41:07 PM
 #5

You can try https://sourceforge.net/projects/pwgen-win/
This is also under Linux
On my pc it can generate 1M keys for 3-4sec, file size 60Mb for 1B will 60Gb  Wink




temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 03, 2020, 02:27:31 AM
 #6

I need continuous generation of random keys
Can you share what you're trying to accomplish?
Unfortunately, I can't say what I need it for yet.
temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 03, 2020, 02:51:10 AM
 #7

You can try https://sourceforge.net/projects/pwgen-win/
This is also under Linux
On my pc it can generate 1M keys for 3-4sec, file size 60Mb for 1B will 60Gb  Wink

https://i.ibb.co/KFbHfRY/screenshot-10.jpg

https://i.ibb.co/B3wSjS4/screenshot-8.jpg


Thanks. Tell me How to run linux in the terminal?
Abdussamad
Legendary
*
Offline Offline

Activity: 3612
Merit: 1564



View Profile
February 03, 2020, 04:47:06 AM
 #8

Code:
for thing in {1..100}; do openssl rand -hex 32 >> privkeys; done

that'll put them in a file named privkeys. replace 100 with 1,000,000 or whatever once you are satisfied it does what you want it to.

btw this may interest you

temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 04, 2020, 11:58:06 AM
 #9

Code:
for thing in {1..100}; do openssl rand -hex 32 >> privkeys; done

that'll put them in a file named privkeys. replace 100 with 1,000,000 or whatever once you are satisfied it does what you want it to.

btw this may interest you



This is what I need. Tell me how to immediately send to another program through the pipe and not save to a file?
LoyceV
Legendary
*
Offline Offline

Activity: 3304
Merit: 16599


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
February 04, 2020, 02:32:50 PM
 #10

Code:
for thing in {1..100}; do openssl rand -hex 32 >> privkeys; done
This is what I need. Tell me how to immediately send to another program through the pipe and not save to a file?
Remove the ">> privkeys" and pipe the whole thing:
Code:
for thing in {1..100}; do openssl rand -hex 32; done | wc -l
This sends it to "word count" as an example.

This is a terribly slow method for generating private keys though.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4616



View Profile
February 04, 2020, 02:44:08 PM
Merited by suchmoon (7), ABCbits (2), HCP (2)
 #11

Code:
for thing in {1..100}; do openssl rand -hex 32 >> privkeys; done

that'll put them in a file named privkeys. replace 100 with 1,000,000 or whatever once you are satisfied it does what you want it to.

btw this may interest you

While rare and generally unlikely, it is possible that the provided command may generate values that are out of range for a Bitcoin Private key.  To be sure that you are only generating valid private keys, you'll want to check each 32 byte value and make sure it's greater than:

0000000000000000000000000000000000000000000000000000000000000000

and less than:

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10549



View Profile
February 05, 2020, 04:41:47 AM
 #12

and less than:
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140

"less than or equal to" instead (or just add +1 to the value) since the order of sekp256k1 curve is FF....4141 and private keys are chosen in range of [1, n-1] and the quoted value is n-1 not n.
for reference (page 9): https://www.secg.org/sec2-v2.pdf

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 05, 2020, 12:19:21 PM
 #13

Code:
for thing in {1..100}; do openssl rand -hex 32 >> privkeys; done
This is what I need. Tell me how to immediately send to another program through the pipe and not save to a file?
Remove the ">> privkeys" and pipe the whole thing:
Code:
for thing in {1..100}; do openssl rand -hex 32; done | wc -l
This sends it to "word count" as an example.

This is a terribly slow method for generating private keys though.

Unfortunately, this works very slowly and loads the computer's memory very much. If you set this command as
Code:
keys=60000000; openssl rand $[32*keys] | xd-p-c32
generates 17000 keys per second. But no more than 60000000 keys at a time. And I need continuous generation of keys in hex format with their transfer through a pipe to another program.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10549



View Profile
February 05, 2020, 01:40:59 PM
Merited by ABCbits (1)
 #14

generates 17000 keys per second.

if you want speed then you shouldn't be using bash and while you're at it avoid using strings (hex) altogether. you are adding a couple of bottlenecks that slow down your process.
instead write your own code and generate random keys based on what you need. you didn't say what you are using it for, so i'll guess it is nothing serious and randomness doesn't matter. for that case you can simply use a fast hash algorithm that produces 256-bit digests and hash numbers from 1 to 1 mil (or whatever message you want) and use the result as the random key. that shouldn't take any more than a  seconds or so.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
temadlyavseh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 05, 2020, 04:05:46 PM
 #15

generates 17000 keys per second.

if you want speed then you shouldn't be using bash and while you're at it avoid using strings (hex) altogether. you are adding a couple of bottlenecks that slow down your process.
instead write your own code and generate random keys based on what you need. you didn't say what you are using it for, so i'll guess it is nothing serious and randomness doesn't matter. for that case you can simply use a fast hash algorithm that produces 256-bit digests and hash numbers from 1 to 1 mil (or whatever message you want) and use the result as the random key. that shouldn't take any more than a  seconds or so.

I can't write this code. Can you help me with this?
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10549



View Profile
February 06, 2020, 05:52:40 AM
 #16

generates 17000 keys per second.

if you want speed then you shouldn't be using bash and while you're at it avoid using strings (hex) altogether. you are adding a couple of bottlenecks that slow down your process.
instead write your own code and generate random keys based on what you need. you didn't say what you are using it for, so i'll guess it is nothing serious and randomness doesn't matter. for that case you can simply use a fast hash algorithm that produces 256-bit digests and hash numbers from 1 to 1 mil (or whatever message you want) and use the result as the random key. that shouldn't take any more than a  seconds or so.

I can't write this code. Can you help me with this?

compile with .net core. it takes 1.2 seconds in debug mode to generate all these hashes.
Code:
using System.Security.Cryptography;

namespace ValueGen
{
    class Program
    {
        private static byte[] max = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 186, 174, 220, 230, 175, 72, 160, 59, 191, 210, 94, 140, 208, 54, 65, 64 };

        static void Main(string[] args)
        {
            SHA256 hash = SHA256.Create();
            for (int i = 0; i < 1_000_000; i++)
                Foo(hash.ComputeHash(new byte[4] { (byte)i, (byte)(i >> 8), (byte)(i >> 16), 0 }));
        }
        public static void Foo(byte[] key)
        {
            if (((ReadOnlySpan<byte>)key).SequenceEqual(new byte[32]) ||((ReadOnlySpan<byte>)key).SequenceEqual(max))
                return;

            // Do whatever with the key!
        }
    }
}

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!