SHA-1

Revision as of 21:01, 18 January 2012 by rosettacode>Kernigh (Introduce SHA-1 with 2 lines of Factor code.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

SHA-1 or SHA1 is a message digest algorithm; it transforms a message into a 160-bit hash. SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits.

SHA-1 is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

A US government standard, FIPS 180-1, defines SHA-1.

  • Warning: SHA-1 has known weaknesses. Users may consider a stronger alternative, such as SHA-256 (from the SHA-2 family) or the upcoming SHA-3.

Find the SHA-1 message digest for a string of octets. You may either call a SHA-1 library, or implement SHA-1 in your language. Both approaches interest Rosetta Code.

Factor

Factor provides sha1 in the checksums.sha vocabulary. In Factor, checksum-bytes returns a sequence of bytes; hex-string converts this sequence to a hexadecimal string.

IN: scratchpad USING: checksums checksums.sha ;
IN: scratchpad "Rosetta Code" sha1 checksum-bytes hex-string .
"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"

The implementation is at basis/checksums/sha/sha.factor.