<p>Check out <a href="http://brainwallet.org/" rel="nofollow">http://brainwallet.org/</a> for an example.</p>

<p>A bitcoin private key is just a 256-bit number. Any algorithm that can convert arbitrary text to a number of that size ought to do.</p>

<p>A rather simple algorithm would be to consider your string as a base 63 number (a-z, A-Z, 0-9 and spaces) and write in binary, take the number modulo 2<sup>256</sup>, and write in hex.</p>

<p>Or, you take the base 63-to-binary number, raise it to the power ten, bit shift left 20 times, multiply by 8, add 4, bit shift right 50 times, take modulo 2<sup>256</sup>, convert to hex, and you have a private key.</p>

<p>Or whatever. Try to make it so that the number generated before you calculate it modulo 2<sup>256</sup> is much larger than 2<sup>256</sup>. Otherwise, many of your generated addresses will just be a bunch of zeroes followed by a relatively short hex string.</p>

CC BY-SA 3.0
2013-04-28T16:02:15.607Z
Random question, does brainwallet take the SHA-256 hash of the passphrase to get the secret exponent?
lurf jurv
CC BY-SA 3.0
2013-04-28T16:06:19.610Z
@lurfjurv: I think so. No clue, I tried reverseengineering the code but it's minified and complicated. I may try later.
Manishearth
CC BY-SA 3.0
2013-04-28T16:40:58.063Z
Thank you - I hadn't seen that website before. So if I had an existing (valid) private key in import format, what would it take to manipulate it into another valid WIF key with a different bitcoin address?
George Pearce
CC BY-SA 3.0
2013-04-28T16:41:46.820Z
@gsp92: what's WIF?
Manishearth
CC BY-SA 3.0
2013-04-28T16:42:18.730Z
@gsp92: But yeah, if you take a private key and plug it into brainwallet, you get another private key :)
Manishearth
CC BY-SA 3.0
2013-04-28T16:45:08.297Z
Wallet Import Format - and I didn't think of that. That gives the potential to spawn a potentially unlimited number of addresses from a known base key - I like it.
George Pearce
CC BY-SA 3.0
2013-04-28T17:53:26.387Z
Another question: say I generate a brainwallet private key and address pair - is this inherently less safe than a randomly generated one? If so, at what point does the length of the passphrase negate this?
George Pearce
CC BY-SA 3.0
2013-04-29T19:36:10.363Z
Brainwallets typically take a sha256 hash of a phrase that becomes the private key (simply because they are the same size). From that the public key and address can be calculated. They really should use key strengenthing. If your original phrase can be bruteforced, it isn't safe.
cdm9002
CC BY-SA 3.0
2013-04-30T11:53:31.733Z
What if my original phrase was a string similar in strength to a randomly generated private key?
George Pearce
CC BY-SA 3.0
2013-04-30T11:55:11.447Z
@gsp92: It can be _anything_ (well maybe not something with wacky characters)
Manishearth
CC BY-SA 3.0
2013-04-30T11:57:38.660Z
I understand that, am interested in how secure a brain wallet generated from a 50 char key would be. I'm thinking as secure as any other random key?
George Pearce
CC BY-SA 3.0
2013-04-30T12:01:13.117Z
@gsp92: yep, pretty much. You lose a bit of entropy since the character set is decreased, but other than that you're fine since the number of characters is huge.
Manishearth
CC BY-SA 3.0
2013-04-28T15:20:19.300Z
2013-04-28T15:20:19.300Z
Manishearth
<p>The title pretty much sums up the question - say (for instance) I have a string of letters or numbers committed to memory, how hard would it be to convert that into a private key? Or similarly, how hard would it be to construct a private key based upon a sentence, mnemonic or otherwise? </p>

CC BY-SA 3.0
2013-04-28T17:37:48.190Z
Not an answer to your question, but a warning: people are very bad at estimating how "random" something is. If you generated a string of characters actually randomly (by a computer), you're probably safe if it is long enough (I wouldn't recommend anything below 128 bit of entropy). Realize that the whole world gets to try an infinite amount of times now and in the future to crack it.
Pieter Wuille
CC BY-SA 3.0
2013-04-28T17:43:22.003Z
Thanks for the heads up. I don't intend to use a string of characters, my question was actually a subversive look into the realities of constructing one private key from another (known and randomly generated) key. I had a look at blockchain.info which lets you import a private key with a single modified character, implying that any string is okay, but with a bit more research I found that there is a checksum to ensure validity, and so it isn't as simple as just changing a number.
George Pearce
<private-key>
What qualifies a valid private key?
George Pearce
# What qualifies a valid private key?

(Asked by: username_0 on 2013-04-28)

The title pretty much sums up the question - say (for instance) I have a string of letters or numbers committed to memory, how hard would it be to convert that into a private key? Or similarly, how hard would it be to construct a private key based upon a sentence, mnemonic or otherwise?

**Tags:** private-key

> **Comments:**
> **username_1**: Not an answer to your question, but a warning: people are very bad at estimating how "random" something is. If you generated a string of characters actually randomly (by a computer), you're probably safe if it is long enough (I wouldn't recommend anything below 128 bit of entropy). Realize that the whole world gets to try an infinite amount of times now and in the future to crack it.  
> **username_0**: Thanks for the heads up. I don't intend to use a string of characters, my question was actually a subversive look into the realities of constructing one private key from another (known and randomly generated) key. I had a look at blockchain.info which lets you import a private key with a single modified character, implying that any string is okay, but with a bit more research I found that there is a checksum to ensure validity, and so it isn't as simple as just changing a number.  

---

## 1 answers

### Answer by username_2 on 2013-04-28. Score: 4 | Accepted answer

Check out <http://brainwallet.org/> for an example.

A bitcoin private key is just a 256-bit number. Any algorithm that can convert arbitrary text to a number of that size ought to do.

A rather simple algorithm would be to consider your string as a base 63 number (a-z, A-Z, 0-9 and spaces) and write in binary, take the number modulo 2256, and write in hex.

Or, you take the base 63-to-binary number, raise it to the power ten, bit shift left 20 times, multiply by 8, add 4, bit shift right 50 times, take modulo 2256, convert to hex, and you have a private key.

Or whatever. Try to make it so that the number generated before you calculate it modulo 2256 is much larger than 2256. Otherwise, many of your generated addresses will just be a bunch of zeroes followed by a relatively short hex string.

> **Comments:**
> **username_3**: Random question, does brainwallet take the SHA-256 hash of the passphrase to get the secret exponent?  
> **username_2**: @username_3: I think so. No clue, I tried reverseengineering the code but it's minified and complicated. I may try later.  
> **username_0**: Thank you - I hadn't seen that website before. So if I had an existing (valid) private key in import format, what would it take to manipulate it into another valid WIF key with a different bitcoin address?  
> **username_2**: @gsp92: what's WIF?  
> **username_2**: @gsp92: But yeah, if you take a private key and plug it into brainwallet, you get another private key :)  
> **username_0**: Wallet Import Format - and I didn't think of that. That gives the potential to spawn a potentially unlimited number of addresses from a known base key - I like it.  
> **username_0**: Another question: say I generate a brainwallet private key and address pair - is this inherently less safe than a randomly generated one? If so, at what point does the length of the passphrase negate this?  
> **username_4**: Brainwallets typically take a sha256 hash of a phrase that becomes the private key (simply because they are the same size). From that the public key and address can be calculated. They really should use key strengenthing. If your original phrase can be bruteforced, it isn't safe.  
> **username_0**: What if my original phrase was a string similar in strength to a randomly generated private key?  
> **username_2**: @gsp92: It can be _anything_ (well maybe not something with wacky characters)  
> **username_0**: I understand that, am interested in how secure a brain wallet generated from a 50 char key would be. I'm thinking as secure as any other random key?  
> **username_2**: @gsp92: yep, pretty much. You lose a bit of entropy since the character set is decreased, but other than that you're fine since the number of characters is huge.  

---

