SHA-256: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: changed 'require' to 'frequire' because the module is function-oriented) |
(Added Haskell version) |
||
Line 829: | Line 829: | ||
Testing |
Testing |
||
<lang groovy>assert sha256Hash('Rosetta code') == '764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf'</lang> |
<lang groovy>assert sha256Hash('Rosetta code') == '764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf'</lang> |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.Char (ord) |
|||
import Crypto.Hash.SHA256 (hash) |
|||
import Data.ByteString (unpack, pack) |
|||
import Text.Printf (printf) |
|||
main = putStrLn $ -- output to terminal |
|||
concatMap (printf "%02x") $ -- to hex string |
|||
unpack $ -- to array of Word8 |
|||
hash $ -- SHA-256 hash to ByteString |
|||
pack $ -- to ByteString |
|||
map (fromIntegral.ord) -- to array of Word8 |
|||
"Rosetta code" |
|||
</lang> |
|||
{{out}} |
|||
<pre style="font-size:80%">764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
The solution to this task would be a small modification to [[MD5#Java|MD5]] (replacing "MD5" with "SHA-256" as noted [http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest here]). |
The solution to this task would be a small modification to [[MD5#Java|MD5]] (replacing "MD5" with "SHA-256" as noted [http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest here]). |