sha256-animation-master.zip

  • eczky
    了解作者
  • WINDOWS
    开发工具
  • 5.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-01-22 17:25
    上传日期
SHA 256 master sourcecode
sha256-animation-master.zip
  • sha256-animation-master
  • images
  • t1.gif
    96KB
  • sha256.gif
    2.2MB
  • maj.gif
    14.2KB
  • compression.gif
    862.8KB
  • ch.gif
    13.9KB
  • usigma0.gif
    22.5KB
  • initial.gif
    29.6KB
  • sigma1.gif
    24.3KB
  • message.gif
    5.8KB
  • merkle-damgard-construction.png
    33.4KB
  • usigma1.gif
    23.6KB
  • sigma0.gif
    19.9KB
  • final.gif
    23.8KB
  • shr.gif
    12.8KB
  • rotr.gif
    16.9KB
  • blocks.gif
    19.7KB
  • t2.gif
    92.4KB
  • add.gif
    11.8KB
  • constants.gif
    838.4KB
  • schedule.gif
    927.4KB
  • padding.gif
    42.2KB
  • xor.gif
    101.8KB
  • expansion.gif
    121.6KB
  • initial.rb
    3.4KB
  • LICENSE
    1KB
  • t1.rb
    21.6KB
  • add.rb
    1.1KB
  • sigma1.rb
    1.9KB
  • constants.rb
    2.8KB
  • hash256.rb
    1.4KB
  • sha256lib.rb
    8.5KB
  • usigma1.rb
    1.9KB
  • padding.rb
    2.2KB
  • sigma0.rb
    1.9KB
  • message.rb
    1.3KB
  • xor.rb
    4.2KB
  • t2.rb
    17.9KB
  • blocks.rb
    1.1KB
  • maj.rb
    824B
  • expansion.rb
    22.5KB
  • rotr.rb
    747B
  • compression.rb
    19.2KB
  • README.md
    13.4KB
  • sha256.rb
    1.5KB
  • ch.rb
    842B
  • usigma0.rb
    1.9KB
  • schedule.rb
    5.1KB
  • shr.rb
    643B
  • final.rb
    1.7KB
内容介绍
# SHA-256 Animation An animation of the [SHA-256](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) hash function in your terminal. Video: <https://www.youtube.com/watch?v=f9EbD6iY9zI> ![](images/sha256.gif) ## Usage Just run the `sha256.rb` script with the data you want to see hashed. ``` # simple ruby sha256.rb abc # hash binary or hex data by using `0b` or `0x` prefixes ruby sha256.rb 0b01100001 ruby sha256.rb 0xaabbccdd # speed up or step through the animation (optional) ruby sha256.rb abc normal # default ruby sha256.rb abc fast ruby sha256.rb abc enter ``` You can also run the individual functions used in SHA-256 by passing in binary strings as arguments: ``` ruby shr.rb 11111111111111110000000000000000 22 ruby rotr.rb 11111111111111110000000000000000 22 ruby sigma0.rb 11111111111111110000000000000000 ruby sigma1.rb 11111111111111110000000000000000 ruby usigma0.rb 11111111111111110000000000000000 ruby usigma1.rb 11111111111111110000000000000000 ruby ch.rb 11111111111111110000000000000000 11110000111100001111000011110000 00000000000000001111111111111111 ruby maj.rb 11111111111111110000000000000000 11110000111100001111000011110000 00000000000000001111111111111111 ``` You can do double-SHA256 (e.g. [Bitcoin](https://learnmeabitcoin.com)) by using `hash256.rb`. This script accepts _hex data_ (e.g. [block headers](https://learnmeabitcoin.com/guide/block-header), [transaction data](https://learnmeabitcoin.com/guide/transaction-data)) by default. ``` ruby hash256.rb 0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c # genesis block header ``` ## How does SHA-256 work? The [<abbr title="National Institute of Standards and Technology" rel='nofollow' onclick='return false;'>NIST</abbr> specification](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) contains a precise explanation of SHA-256. The following is essentially a visualised summary of that document. ### 1. Definitions The official specification begins with a number of definitions, but seeing as this is a simplified explanation, all I want you to know is: * `bit` = `0` or `1` (the smallest unit of storage on a computer) * `word` = 32 bits Also, [bitwise operations](https://www.calleerlandsson.com/rubys-bitwise-operators/) use the following symbols: ``` OR = | XOR = ^ AND = & NOT = ~ ``` ### 2. Operations SHA-256 uses four basic bitwise operations on `words`. #### Right Shift ([`shr.rb`](shr.rb)) ![](images/shr.gif) <pre> SHR<sup>n</sup>(x) = x >> n </pre> Move bits a number of positions to the right. The bits shifted off the right-hand side are lost. #### Rotate Right ([`rotr.rb`](rotr.rb)) ![](images/rotr.gif) <pre> ROTR<sup>n</sup>(x) = (x >> n) | (x << 32-n) </pre> Move bits a number of positions to the right, and place the shifted bits on the left-hand side. This can also be referred to as a _circular right shift_. #### Exclusive Or ([`xor.rb`](xor.rb)) ![](images/xor.gif) <pre> x ^ y ^ z </pre> The `XOR` bitwise operator takes two input bits, and outputs a `1` if _only one_ of them is a `1`. This is useful for getting a _balanced representation of multiple bits_ when merging them together via multiple `XOR` operations. #### Addition ([`add.rb`](add.rb)) ![](images/add.gif) <pre> (v + w + x + y + z) % 2<sup>32</sup> </pre> This is standard integer addition, but we constrain the result to a 32 bit number by taking the result **modulus 2<sup>32</sup>**. ### 3. Functions The operations above can be combined to create functions. The first four functions are named using the Greek symbol **Sigma** (lowercase `σ` and uppercase `Σ`). This is for no particular reason, it's just so we can give names to some combined operations. I like to think of these as the "rotational" functions. #### σ0 ([`sigma0.rb`](sigma0.rb)) ![](images/sigma0.gif) <pre> σ<sub>0</sub>(x) = ROTR<sup>7</sup>(x) ^ ROTR<sup>18</sup>(x) ^ SHR<sup>3</sup>(x) </pre> <!-- σ0(x) = ROTR(7, x) ^ ROTR(18, x) ^ SHR(3, x) --> #### σ1 ([`sigma1.rb`](sigma1.rb)) ![](images/sigma1.gif) <pre> σ<sub>1</sub>(x) = ROTR<sup>17</sup>(x) ^ ROTR<sup>19</sup>(x) ^ SHR<sup>10</sup>(x) </pre> <!-- σ1(x) = ROTR(17, x) ^ ROTR(19, x) ^ SHR(10, x) --> #### Σ0 ([`usigma0.rb`](usigma0.rb)) ![](images/usigma0.gif) <pre> Σ<sub>0</sub>(x) = ROTR<sup>2</sup>(x) ^ ROTR<sup>13</sup>(x) ^ ROTR<sup>22</sup>(x) </pre> <!-- Σ0(x) = ROTR(2, x) ^ ROTR(13, x) ^ ROTR(22, x) --> #### Σ1 ([`usigma1.rb`](usigma1.rb)) ![](images/usigma1.gif) <pre> Σ<sub>1</sub>(x) = ROTR<sup>6</sup>(x) ^ ROTR<sup>11</sup>(x) ^ ROTR<sup>25</sup>(x) </pre> <!-- Σ1(x) = ROTR(6, x) ^ ROTR(11, x) ^ ROTR(25, x) --> The last two functions of **Choice** and **Majority** accept three different inputs. #### Choice ([`ch.rb`](ch.rb)) This function uses the `x` bit to **choose** between the `y` and `z` bits. It chooses the `y` bit if `x=1`, and chooses the `z` bit if `x=0`. ![](images/ch.gif) ``` Ch(x, y, z) = (x & y) ^ (~x & z) ``` #### Majority ([`maj.rb`](maj.rb)) This function returns the **majority** of the three bits. ![](images/maj.gif) ``` Maj(x, y, z) = (x & y) ^ (x & z) ^ (y & z) ``` ### 4. Constants ([`constants.rb`](constants.rb)) ![](images/constants.gif) <pre> K<sub>t</sub> = ∛primes <em>(first 32 bits of fractional part)</em> </pre> SHA-256 uses sixty four constants <code>K<sub>t</sub></code> to help with mixing up the bits during the main hash computation. These constants are generated by taking the **cube root** of the first sixty four **prime numbers**. The _fractional parts_ of these cube roots are irrational (they go on forever), so they make for a good selection of random bits to use at constants. This is better than using specifically chosen constants, as this makes it less likely that the hash function has been designed with a back-door. Anyway, to get _32 bits_ from these numbers, we take the fractional part and multiply it by 2<sup>32</sup>, and use the resulting _integer_ as the constant. --- Now that we've defined the functions and constants we're going to use, the next step is to _prepare the message_ for hashing. ### 5. Message ([`message.rb`](message.rb)) ![](images/message.gif) As you may have noticed, SHA-256 operates on the individual _bits_ of data. So we before we can hash any data, we first of all need to convert it to its binary representation (`1`s and `0`s). For example when hashing a _string_, we convert each character to its corresponding number in the [ASCII table](https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html). These numbers are converted to binary, and it's this binary data that we use as the input to the hash function. ### 6. Padding ([`padding.rb`](padding.rb)) ![](images/padding.gif) The SHA-256 hash function works on data in 512-bit chunks, so all messages need to be _padded_ with zeros up to the nearest multiple of 512 bits. Furthermore, to prevent similar inputs from hashing to the same result, we separate the message from the zeros with a `1` bit, and also include the size of the message in the last 64 bits of the padding. _**NOTE:** This method of separating the message with a `1` and including the message size in the padding is known as **Merkle–Damgård strengthening** (MD strengthening)._ ### 7. Message Blocks ([`blocks.rb`](blocks.rb)) ![](images/blocks.gif) After the message has been padded, we cut it in to equal 512-bit **message blocks** <code>M<sup>i</sup></code> to be processed by the hash function. (There is only one message block for this example message, so the animation above isn't very interesting.) Each of these message blocks can also be further split in to 16 words <code>M<sup>i</sup><sub>j</sub></code> (`512 / 32 = 16 words`), which will come in handy in just a moment. --- Now that we have padded our message and cut it in to equal chunks, we put _each of the message blocks_ through the main hash function. ### 8. Message
评论
    相关推荐
    • SHA256.rar
      密码算法SHA256的标准描述。。。。。。。。。。。。
    • sha256.rar
      sha语言,实现256bit的实现,提高安全性。
    • sha256.rar
      s加密sghshrova;kfdngvajkrgal
    • sha256算法
      sha256加密签名算法
    • SHA256.rar
      无需将消息一次读入内存,通过循环调用sha256_update1即可计算摘要值,摘要值最后存储在hash[32]中;可以利用SHA256在线工具验证; sha256_init(&ctx;); sha256_update1(&ctx;, message1, 64); sha256_update1(&ctx;...
    • sha256-noBLOCKCHAIN
      sha256-noBlockchain 只是想比较散列,不是真正的区块链,而只是一个概念。 原始块“ A至B 200个硬币,B至C 100个硬币,C至D 50个硬币,D至A 25个硬币” “ D到E 200硬币,E到F 100硬币,F到G 50硬币,G到D 25硬币”...
    • SHA256:C ++ SHA256实现
      SHA256 C ++ SHA256实现。 建造 只需运行make all 。 没有依赖关系。 用法示例 样例程序 根据需要提供尽可能多的字符串。 该程序将按顺序对所有它们进行哈希处理。 $ ./SHA256 "string" "string2" 473287f8298dba...
    • sha256.rar
      sha256 GitHub源代码,头文件未被添加进去
    • sha256.zip
      simple sha256 md5 checksum
    • 3DES加密算法源代码.rar
      DES加密源代码,用3DES加密算法。 加密强度高,到目前为止,还无人能够破解!