SHA-256 algorithm in Snap!

Yep, I made this block recreating SHA-256 algorithm without JS, it returns an hex digest in big-endian. Just introduce your text and done! Here are some examples:




Source

Copy and import:

<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><block-definition s="sha256 hash of %&apos;msg&apos;" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%s">Abelson &amp; Sussman</input></inputs><script><block s="doDeclareVariables"><list><l>h</l><l>k</l><l>chk</l><l>len</l></list></block><block s="doSetVar"><l>h</l><block s="reportNewList"><list><l>0x6a09e667</l><l>0xbb67ae85</l><l>0x3c6ef372</l><l>0xa54ff53a</l><l>0x510e527f</l><l>0x9b05688c</l><l>0x1f83d9ab</l><l>0x5be0cd19</l></list></block></block><block s="doSetVar"><l>k</l><block s="reportNewList"><list><l>0x428a2f98</l><l>0x71374491</l><l>0xb5c0fbcf</l><l>0xe9b5dba5</l><l>0x3956c25b</l><l>0x59f111f1</l><l>0x923f82a4</l><l>0xab1c5ed5</l><l>0xd807aa98</l><l>0x12835b01</l><l>0x243185be</l><l>0x550c7dc3</l><l>0x72be5d74</l><l>0x80deb1fe</l><l>0x9bdc06a7</l><l>0xc19bf174</l><l>0xe49b69c1</l><l>0xefbe4786</l><l>0x0fc19dc6</l><l>0x240ca1cc</l><l>0x2de92c6f</l><l>0x4a7484aa</l><l>0x5cb0a9dc</l><l>0x76f988da</l><l>0x983e5152</l><l>0xa831c66d</l><l>0xb00327c8</l><l>0xbf597fc7</l><l>0xc6e00bf3</l><l>0xd5a79147</l><l>0x06ca6351</l><l>0x14292967</l><l>0x27b70a85</l><l>0x2e1b2138</l><l>0x4d2c6dfc</l><l>0x53380d13</l><l>0x650a7354</l><l>0x766a0abb</l><l>0x81c2c92e</l><l>0x92722c85</l><l>0xa2bfe8a1</l><l>0xa81a664b</l><l>0xc24b8b70</l><l>0xc76c51a3</l><l>0xd192e819</l><l>0xd6990624</l><l>0xf40e3585</l><l>0x106aa070</l><l>0x19a4c116</l><l>0x1e376c08</l><l>0x2748774c</l><l>0x34b0bcb5</l><l>0x391c0cb3</l><l>0x4ed8aa4a</l><l>0x5b9cca4f</l><l>0x682e6ff3</l><l>0x748f82ee</l><l>0x78a5636f</l><l>0x84c87814</l><l>0x8cc70208</l><l>0x90befffa</l><l>0xa4506ceb</l><l>0xbef9a3f7</l><l>0xc67178f2</l></list></block></block><block s="doSetVar"><l>chk</l><block s="reportCDR"><block s="reportListAttribute"><l><option>flatten</option></l><block s="reportAtomicMap"><block s="reifyReporter"><autolambda><block s="reportNewList"><list><block s="reportJoinWords"><list><l>0x</l><block s="reportListItem"><l>1</l><l/></block><block s="reportListItem"><l>2</l><l/></block></list></block><block s="reportUnicode"><block s="reportCDR"><block s="reportCDR"><l/></block></block></block></list></block></autolambda><list></list></block><block s="reportTextSplit"><block s="reportCDR"><block s="reportTextSplit"><block s="reportJoinWords"><list><l>%00</l><block s="reportTextFunction"><l><option>encode URI</option></l><block var="msg"/></block></list></block><l>%</l></block></block><l><option>letter</option></l></block></block></block></block></block><block s="doSetVar"><l>len</l><block s="reportListAttribute"><l><option>length</option></l><block var="chk"/></block></block><block s="doSetVar"><l>chk</l><block s="reportAtomicMap"><block s="reifyReporter"><autolambda><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>1</l><l/></block><l>24</l></list></block><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>2</l><l/></block><l>16</l></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>3</l><l/></block><l>8</l></list></block><block s="reportListItem"><l>4</l><l/></block></list></block></list></block></autolambda><list></list></block><block s="reportReshape"><block s="reportConcatenatedLists"><list><block var="chk"/><block s="reportNewList"><list><l>128</l><l>0</l><l>0</l><l>0</l><l>0</l></list></block><block s="reportReshape"><block s="reportJoinWords"><list><l>0</l></list></block><list><block s="reportModulus"><block s="reportDifference"><l>-9</l><block var="len"/></block><l>64</l></block></list></block></list></block><list><block s="reportDifference"><block s="reportVariadicProduct"><list><block s="reportMonadic"><l><option>ceiling</option></l><block s="reportQuotient"><block s="reportVariadicSum"><list><block var="len"/><l>9</l></list></block><l>64</l></block></block><l>16</l></list></block><l>1</l></block><l>4</l></list></block></block></block><block s="doAddToList"><block s="reportVariadicProduct"><list><block var="len"/><l>8</l></list></block><block var="chk"/></block><block s="doWarp"><script><block s="doForEach"><l>w</l><block s="reportReshape"><block var="chk"/><list><block s="reportQuotient"><block s="reportListAttribute"><l><option>length</option></l><block var="chk"/></block><l>16</l></block><l>16</l></list></block><script><block s="doDeclareVariables"><list><l>var</l><l>s0</l><l>s1</l><l>ch</l><l>ma</l><l>t1</l><l>t2</l></list></block><block s="doSetVar"><l>var</l><block s="reportMonadic"><l><option>id</option></l><block var="h"/></block></block><block s="doFor"><l>i</l><l>17</l><l>64</l><script><block s="doSetVar"><l>s0</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>15</l></block><block var="w"/></block><l>25</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>15</l></block><block var="w"/></block><l>7</l></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>15</l></block><block var="w"/></block><l>14</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>15</l></block><block var="w"/></block><l>18</l></list></block></list></block></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>15</l></block><block var="w"/></block><l>3</l></list></block></list></block></block><block s="doSetVar"><l>s1</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>2</l></block><block var="w"/></block><l>15</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>2</l></block><block var="w"/></block><l>17</l></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>2</l></block><block var="w"/></block><l>13</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>2</l></block><block var="w"/></block><l>19</l></list></block></list></block></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>2</l></block><block var="w"/></block><l>10</l></list></block></list></block></block><block s="doAddToList"><block s="reportVariadicSum"><list><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>16</l></block><block var="w"/></block><block var="s0"/><block s="reportListItem"><block s="reportDifference"><block var="i"/><l>7</l></block><block var="w"/></block><block var="s1"/></list></block><block var="w"/></block></script></block><block s="doFor"><l>i</l><l>1</l><l>64</l><script><block s="doSetVar"><l>s1</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>26</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>6</l></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>21</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>11</l></list></block></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>7</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><l>25</l></list></block></list></block></list></block></block><block s="doSetVar"><l>ch</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block><block s="reportListItem"><l>6</l><block var="var"/></block></list></block><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_not(a)</l><list><block s="reportListItem"><l>5</l><block var="var"/></block></list></block><block s="reportListItem"><l>7</l><block var="var"/></block></list></block></list></block></block><block s="doSetVar"><l>t1</l><block s="reportVariadicSum"><list><block s="reportListItem"><l>8</l><block var="var"/></block><block var="s1"/><block var="ch"/><block s="reportListItem"><block var="i"/><block var="k"/></block><block s="reportListItem"><block var="i"/><block var="w"/></block></list></block></block><block s="doSetVar"><l>s0</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>30</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>2</l></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>19</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>13</l></list></block></list></block></list></block><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportApplyExtension"><l>bit_left_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>10</l></list></block><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><l>22</l></list></block></list></block></list></block></block><block s="doSetVar"><l>ma</l><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_xor(a, b)</l><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><block s="reportListItem"><l>2</l><block var="var"/></block></list></block><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportListItem"><l>1</l><block var="var"/></block><block s="reportListItem"><l>3</l><block var="var"/></block></list></block></list></block><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportListItem"><l>2</l><block var="var"/></block><block s="reportListItem"><l>3</l><block var="var"/></block></list></block></list></block></block><block s="doSetVar"><l>t2</l><block s="reportVariadicSum"><list><block var="s0"/><block var="ma"/></list></block></block><block s="doReplaceInList"><l>8</l><block var="var"/><block s="reportListItem"><l>7</l><block var="var"/></block></block><block s="doReplaceInList"><l>7</l><block var="var"/><block s="reportListItem"><l>6</l><block var="var"/></block></block><block s="doReplaceInList"><l>6</l><block var="var"/><block s="reportListItem"><l>5</l><block var="var"/></block></block><block s="doReplaceInList"><l>5</l><block var="var"/><block s="reportVariadicSum"><list><block s="reportListItem"><l>4</l><block var="var"/></block><block var="t1"/></list></block></block><block s="doReplaceInList"><l>4</l><block var="var"/><block s="reportListItem"><l>3</l><block var="var"/></block></block><block s="doReplaceInList"><l>3</l><block var="var"/><block s="reportListItem"><l>2</l><block var="var"/></block></block><block s="doReplaceInList"><l>2</l><block var="var"/><block s="reportListItem"><l>1</l><block var="var"/></block></block><block s="doReplaceInList"><l>1</l><block var="var"/><block s="reportVariadicSum"><list><block var="t1"/><block var="t2"/></list></block></block></script></block><block s="doReplaceInList"><l>1</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>1</l><block var="var"/></block><block s="reportListItem"><l>1</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>2</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>2</l><block var="var"/></block><block s="reportListItem"><l>2</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>3</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>3</l><block var="var"/></block><block s="reportListItem"><l>3</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>4</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>4</l><block var="var"/></block><block s="reportListItem"><l>4</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>5</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>5</l><block var="var"/></block><block s="reportListItem"><l>5</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>6</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>6</l><block var="var"/></block><block s="reportListItem"><l>6</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>7</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>7</l><block var="var"/></block><block s="reportListItem"><l>7</l><block var="h"/></block></list></block><l>0</l></list></block></block><block s="doReplaceInList"><l>8</l><block var="h"/><block s="reportApplyExtension"><l>bit_or(a, b)</l><list><block s="reportVariadicSum"><list><block s="reportListItem"><l>8</l><block var="var"/></block><block s="reportListItem"><l>8</l><block var="h"/></block></list></block><l>0</l></list></block></block></script></block><block s="doDeclareVariables"><list><l>hex</l><l>d</l></list></block><block s="doSetVar"><l>hex</l><block s="reportNewList"><list><l>0</l><l>1</l><l>2</l><l>3</l><l>4</l><l>5</l><l>6</l><l>7</l><l>8</l><l>9</l><l>a</l><l>b</l><l>c</l><l>d</l><l>e</l><l>f</l></list></block></block><block s="doSetVar"><l>d</l><l></l></block><block s="doForEach"><l>v</l><block var="h"/><script><block s="doSetVar"><l>d</l><block s="reportJoinWords"><list><block var="d"/><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>28</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>24</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>20</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>16</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>12</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>8</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block s="reportApplyExtension"><l>bit_unsigned_right_shift(a, b)</l><list><block var="v"/><l>4</l></list></block><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block><block s="reportListItem"><block s="reportVariadicSum"><list><block s="reportApplyExtension"><l>bit_and(a, b)</l><list><block var="v"/><l>15</l></list></block><l>1</l></list></block><block var="hex"/></block></list></block></block></script></block></script></block><block s="doReport"><block var="d"/></block></script></block-definition></blocks>

(C) 2022 ScratchModification

Added source code

Excellent work :slight_smile:

not copyrighted, scratchmod!

Did you know? Since v8, when you "script pic" a script like this:
image
all the code inside the block is saved into the metadata of the picture, so when you drop this image on the forum, we can import the block into a snap program...

sha256
Try to save this image on your computer and drop it on the script section of a new project.

it is copyrighted, with CC-BY-NC-SA

Tainted...?
tainted

Yeah but that's weird... How do I fix this?

Wait, I forgot...Wait... I forgot to just do these: Save it to my computer, then try dragging it to the scripts.

You have to save it to tour harddrive before and import it after...

sometimes you have to click on the image first to get it into a bigger view and then drag into snap