Hash

Hash[expr]

gives an integer hash code for the expression expr.

Hash[expr,"type"]

gives an integer hash code of the specified type for expr.

Hash[expr,"type","format"]

gives a hash code in the specified format.

Details

  • Hash[expr,] will always give the same result for the same expression expr.
  • Possible hash code types include:
  • "Adler32"Adler 32-bit cyclic redundancy check
    "CRC32"32-bit cyclic redundancy check
    "MD2"128-bit MD2 code
    "MD4"128-bit MD4 code
    "MD5"128-bit MD5 code
    "RIPEMD160"160-bit RIPEMD code
    "RIPEMD160SHA256"RIPEMD-160 following SHA-256 (as used in Bitcoin)
    "SHA"160-bit SHA-1 code
    "SHA256"256-bit SHA code
    "SHA256SHA256"double SHA-256 code (as used in Bitcoin)
    "SHA384"384-bit SHA code
    "SHA512"512-bit SHA code
    "Expression"expression hash code (default)
  • The "Expression" hash code is computed from the internal representation of an expression and may vary between computer systems and from one version of the Wolfram Language to another.
  • For hash code types (such as "SHA") that operate on sequences of bytes, Hash[expr,] first converts expr to bytes according to:
  • exprbytes in ToString[FullForm[expr]]
    "string"bytes in the UTF-8 representation of string
    ByteArray[]literal bytes in the byte array
  • Possible formats include:
  • "Integer"integer (default)
    "DecimalString"decimal string
    "HexString"hexadecimal string
    "Base36String"base-36 alphanumeric string
    "Base64Encoding"Base64 encoding
    "ByteArray"hash code as an explicit byte array

Examples

open allclose all

Basic Examples  (3)

Hash a string:

In[1]:=
Click for copyable input
Out[1]=

Digital fingerprint of data:

In[1]:=
Click for copyable input
Out[1]=

SHA256 hash given in hexadecimal form:

In[1]:=
Click for copyable input
Out[1]=

Scope  (9)

Applications  (2)

Properties & Relations  (12)

Possible Issues  (3)

Neat Examples  (2)

See Also

FileHash  GenerateSymmetricKey  LeafCount  ByteCount  Dispatch  BaseEncode  BinarySerialize

Introduced in 1988
(1.0)
| Updated in 2018
(11.3)