mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2025-01-11 08:10:54 +00:00
reformat code samples
This commit is contained in:
parent
364fa2d1b2
commit
b958f51ceb
@ -301,33 +301,29 @@ Running this will produce the hashes of several phrases, made different by addin
|
||||
((("nonce")))
|
||||
[[sha256_example_generator_output]]
|
||||
.SHA256 Output of a script for generating many hashes by iterating on a nonce
|
||||
====
|
||||
++++
|
||||
<screen>
|
||||
$ <userinput>python hash_example.py</userinput>
|
||||
I am Satoshi Nakamoto0 => a80a81401765c8eddee25df36728d732acb6d135bcdee6c2f87a3784279cfaed
|
||||
I am Satoshi Nakamoto1 => f7bc9a6304a4647bb41241a677b5345fe3cd30db882c8281cf24fbb7645b6240
|
||||
I am Satoshi Nakamoto2 => ea758a8134b115298a1583ffb80ae62939a2d086273ef5a7b14fbfe7fb8a799e
|
||||
I am Satoshi Nakamoto3 => bfa9779618ff072c903d773de30c99bd6e2fd70bb8f2cbb929400e0976a5c6f4
|
||||
I am Satoshi Nakamoto4 => bce8564de9a83c18c31944a66bde992ff1a77513f888e91c185bd08ab9c831d5
|
||||
I am Satoshi Nakamoto5 => eb362c3cf3479be0a97a20163589038e4dbead49f915e96e8f983f99efa3ef0a
|
||||
I am Satoshi Nakamoto6 => 4a2fd48e3be420d0d28e202360cfbaba410beddeebb8ec07a669cd8928a8ba0e
|
||||
I am Satoshi Nakamoto7 => 790b5a1349a5f2b909bf74d0d166b17a333c7fd80c0f0eeabf29c4564ada8351
|
||||
I am Satoshi Nakamoto8 => 702c45e5b15aa54b625d68dd947f1597b1fa571d00ac6c3dedfa499f425e7369
|
||||
I am Satoshi Nakamoto9 => 7007cf7dd40f5e933cd89fff5b791ff0614d9c6017fbe831d63d392583564f74
|
||||
I am Satoshi Nakamoto10 => c2f38c81992f4614206a21537bd634af717896430ff1de6fc1ee44a949737705
|
||||
I am Satoshi Nakamoto11 => 7045da6ed8a914690f087690e1e8d662cf9e56f76b445d9dc99c68354c83c102
|
||||
I am Satoshi Nakamoto12 => 60f01db30c1a0d4cbce2b4b22e88b9b93f58f10555a8f0f4f5da97c3926981c0
|
||||
I am Satoshi Nakamoto13 => 0ebc56d59a34f5082aaef3d66b37a661696c2b618e62432727216ba9531041a5
|
||||
I am Satoshi Nakamoto14 => 27ead1ca85da66981fd9da01a8c6816f54cfa0d4834e68a3e2a5477e865164c4
|
||||
I am Satoshi Nakamoto15 => 394809fb809c5f83ce97ab554a2812cd901d3b164ae93492d5718e15006b1db2
|
||||
I am Satoshi Nakamoto16 => 8fa4992219df33f50834465d30474298a7d5ec7c7418e642ba6eae6a7b3785b7
|
||||
I am Satoshi Nakamoto17 => dca9b8b4f8d8e1521fa4eaa46f4f0cdf9ae0e6939477e1c6d89442b121b8a58e
|
||||
I am Satoshi Nakamoto18 => 9989a401b2a3a318b01e9ca9a22b0f39d82e48bb51e0d324aaa44ecaba836252
|
||||
I am Satoshi Nakamoto19 => cda56022ecb5b67b2bc93a2d764e75fc6ec6e6e79ff6c39e21d03b45aa5b303a
|
||||
</screen>
|
||||
++++
|
||||
====
|
||||
----
|
||||
$ *python hash_example.py*
|
||||
I am Satoshi Nakamoto0 => a80a81401765c8eddee25df36728d732...
|
||||
I am Satoshi Nakamoto1 => f7bc9a6304a4647bb41241a677b5345f...
|
||||
I am Satoshi Nakamoto2 => ea758a8134b115298a1583ffb80ae629...
|
||||
I am Satoshi Nakamoto3 => bfa9779618ff072c903d773de30c99bd...
|
||||
I am Satoshi Nakamoto4 => bce8564de9a83c18c31944a66bde992f...
|
||||
I am Satoshi Nakamoto5 => eb362c3cf3479be0a97a20163589038e...
|
||||
I am Satoshi Nakamoto6 => 4a2fd48e3be420d0d28e202360cfbaba...
|
||||
I am Satoshi Nakamoto7 => 790b5a1349a5f2b909bf74d0d166b17a...
|
||||
I am Satoshi Nakamoto8 => 702c45e5b15aa54b625d68dd947f1597...
|
||||
I am Satoshi Nakamoto9 => 7007cf7dd40f5e933cd89fff5b791ff0...
|
||||
I am Satoshi Nakamoto10 => c2f38c81992f4614206a21537bd634a...
|
||||
I am Satoshi Nakamoto11 => 7045da6ed8a914690f087690e1e8d66...
|
||||
I am Satoshi Nakamoto12 => 60f01db30c1a0d4cbce2b4b22e88b9b...
|
||||
I am Satoshi Nakamoto13 => 0ebc56d59a34f5082aaef3d66b37a66...
|
||||
I am Satoshi Nakamoto14 => 27ead1ca85da66981fd9da01a8c6816...
|
||||
I am Satoshi Nakamoto15 => 394809fb809c5f83ce97ab554a2812c...
|
||||
I am Satoshi Nakamoto16 => 8fa4992219df33f50834465d3047429...
|
||||
I am Satoshi Nakamoto17 => dca9b8b4f8d8e1521fa4eaa46f4f0cd...
|
||||
I am Satoshi Nakamoto18 => 9989a401b2a3a318b01e9ca9a22b0f3...
|
||||
I am Satoshi Nakamoto19 => cda56022ecb5b67b2bc93a2d764e75f...
|
||||
----
|
||||
|
||||
Each phrase produces a completely different hash result. They seem completely random, but you can re-produce the exact results in this example on any computer with Python and see the same exact hashes.
|
||||
|
||||
@ -358,10 +354,9 @@ Running the code above, you can set the desired difficulty (in bits, how many of
|
||||
|
||||
[[pow_example_outputs]]
|
||||
.Running the proof-of-work example for various difficulties
|
||||
====
|
||||
++++
|
||||
<screen>
|
||||
$ <userinput>python proof-of-work-example.py</userinput>
|
||||
----
|
||||
$ *python proof-of-work-example.py*
|
||||
|
||||
Difficulty: 1 (0 bits)
|
||||
|
||||
[...]
|
||||
@ -415,9 +410,7 @@ Hash is 0000001f0ea21e676b6dde5ad429b9d131a9f2b000802ab2f169cbca22b1e21a
|
||||
Elapsed Time: 665.0949 seconds
|
||||
Hashing Power: 127141 hashes per second
|
||||
|
||||
</screen>
|
||||
++++
|
||||
====
|
||||
----
|
||||
|
||||
As you can see, increasing the difficulty by 1 bit causes an exponential increase in the time it takes to find a solution. If you think of the entire 256-bit number space, each time you constrain one more bit to zero, you decrease the search space by half. In the example above, it takes 84 million hash attempts to find a nonce that produces a hash with 26 leading bits as zero. Even at a speed of more than 120 thousand hashes per second, it still requires ten minutes on a consumer laptop to find this solution.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user