SHA-256 Merkle tree: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Initial Haskell version.) |
m (→{{header|Wren}}: Minor tidy) |
||
(One intermediate revision by one other user not shown) | |||
Line 7:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program merkleRoot64.s */
Line 695:
.include "../includeARM64.inc"
</syntaxhighlight>
<pre>
Start hash number : 22
Line 702:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program merkleRoot.s */
Line 1,313:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
<pre>
Start hash number : 22
Line 1,320:
=={{header|C}}==
{{libheader|GLib}}
<
#include <stdlib.h>
#include <stdio.h>
Line 1,391:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 1,400:
=={{header|C++}}==
{{libheader|OpenSSL}}
<
#include <fstream>
#include <iomanip>
Line 1,499:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 1,510:
{{libheader| DCPsha256}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program SHA256_Merkle_tree;
Line 1,606:
writeln(Merkle_tree('title.png'));
readln;
end.</
{{out}}
<pre>A4F902CF9D51FE51EDA156A6792E1445DFF65EDF3A217A1F3334CC9CF1495C2C</pre>
Line 1,612:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
io.encodings.binary io.files kernel make math math.parser
namespaces sequences ;
Line 1,638:
bytes>hex-string ;
"title.png" 1024 merkle-hash print</
{{out}}
<pre>
Line 1,645:
=={{header|Go}}==
<
import (
Line 1,696:
fmt.Printf("%x", hashes[0])
fmt.Println()
}</
{{out}}
Line 1,704:
=={{header|Haskell}}==
<
import Control.Monad (mfilter)
Line 1,768:
Nothing -> putStrLn "No input to hash"
Just h -> printByteStringHex h
_ -> putStrLn "Argument usage: chunk-size"</
{{out}}
Line 1,776:
=={{header|Java}}==
<
import java.security.*;
import java.util.*;
Line 1,833:
return digests.get(0);
}
}</
{{out}}
Line 1,841:
=={{header|Julia}}==
<
function merkletree(filename="title.png", blocksize=1024)
Line 1,856:
println(merkletree())
</
<pre>a4f902cf9d51fe51eda156a6792e1445dff65edf3a217a1f3334cc9cf1495c2c</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
parts=Hash[ByteArray[#],"SHA256","ByteArray"]&/@Partition[data,UpTo[1024]];
parts=NestWhile[If[Length[#]==2,Hash[Join@@#,"SHA256","ByteArray"],First[#]]&/@Partition[#,UpTo[2]]&,parts,Length[#]>1&];
StringJoin[IntegerString[Normal[First[parts]],16]]</
{{out}}
<pre>a4f92cf9d51fe51eda156a6792e1445dff65edf3a217a1f3334cc9cf1495c2c</pre>
Line 1,870:
{{libheader|nimcrypto}}
To compute the digests of file blocks, we use the procedure “digest” which accepts the address of a byte array and a byte count. To compute the digests of pairs of digests, we use instead a SHA256 context and the procedures “update” and “finish”, which avoids a copy in an intermediate buffer.
<syntaxhighlight lang="nim">
import nimcrypto
Line 1,899:
hashes= newHashes
echo hashes[0]</
{{out}}
Line 1,907:
==={{header|Free Pascal}}===
minimal modified [http://rosettacode.org/wiki/SHA-256_Merkle_tree#Delphi Delphi] version
<
program SHA256_Merkle_tree;
{$IFDEF WINDOWS}
Line 2,021:
readln;
{$ENDIF}
end.</
{{out}}
<pre>
Line 2,028:
=={{header|Perl}}==
{{Trans|Raku}}
<
use strict;
Line 2,048:
}
print unpack ( 'H*', $blocks[0] ) , "\n";</
{{out}}
<pre>
Line 2,056:
=={{header|Phix}}==
{{libheader|Phix/libcurl}}
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 2,101:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">asHex</span><span style="color: #0000FF;">(</span><span style="color: #000000;">merkle</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"title.png"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"https://rosettacode.org/mw/title.png"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1024</span><span style="color: #0000FF;">)))</span>
<!--</
{{out}}
<pre>
Line 2,110:
This version attempts to combine blocks as soon as possible to minimize the memory footprint.
<
# compute the root label for a SHA256 Merkle tree built on blocks of a given
# size (default 1MB) taken from the given file(s)
Line 2,152:
argh.dispatch_command(main)
</syntaxhighlight>
{{Out}}
Line 2,160:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
unit sub MAIN(Int :b(:$block-size) = 1024 × 1024, *@args);
Line 2,172:
}
say @blocks[0]».fmt('%02x').join;</
{{Out}}
Line 2,179:
=={{header|Rust}}==
<
use crypto::digest::Digest;
Line 2,241:
Err(error) => eprintln!("I/O error: {}", error),
}
}</
{{out}}
Line 2,253:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<
import "./crypto" for Sha256, Bytes
import "./seq" for Lst
import "./str" for Str
import "./fmt" for Conv
var bytes = File.read("title.png").bytes.toList
Line 2,287:
hashes = hashes2
}
System.print(Bytes.toHexString(hashes[0]))</
{{out}}
|