Hash
✖
Hash
Details



- Hash[expr,…] will always give the same result for the same expression expr.
- Possible hash types include:
-
"Adler32" Adler 32-bit cyclic redundancy check "BLAKE2b-512" 512-bit BLAKE2b code "BLAKE2s-256" 256-bit BLAKE2s code {"BLAKE2b",b} BLAKE2b code with arbitrary length b up to 512 bits {"BLAKE2s",b} BLAKE2s code with arbitrary length b up to 256 bits {"BLAKE2bp",b} multicore parallel version of BLAKE2b {"BLAKE2sp",b} multicore parallel version of BLAKE2s {"BLAKE2xb",b} BLAKE2xb code with arbitrary length b up to 256 GiB {"BLAKE2xs",b} BLAKE2xs code with arbitrary length b up to 128 GiB "CRC32" 32-bit cyclic redundancy check "Keccak224" 224-bit Keccak code "Keccak256" 256-bit Keccak code "Keccak384" 384-bit Keccak code "Keccak512" 512-bit Keccak code {"Keccak",b} Keccak code with length b of 224, 256, 384, 512 bits "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) "SHA1" 160-bit SHA-1 code "SHA224" 224-bit SHA 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 {"SHA",b} SHA code with length b of 224, 256, 384, 512 bits "SHA3-224" 224-bit SHA3 code "SHA3-256" 256-bit SHA3 code "SHA3-384" 384-bit SHA3 code "SHA3-512" 512-bit SHA3 code {"SHA3",b} SHA3 code with length b of 224, 256, 384, 512 bits "Expression" expression hash code (default) - For a variable-length hash, length b must be a multiple of 8.
- The "Expression" hash 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 hashes that operate on sequences of bytes (such as "SHA"), Hash[expr,…] first converts expr to bytes according to:
-
expr bytes based on 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 "HexStringLittleEndian" hexadecimal string with little-endian byte order "Base36String" base-36 alphanumeric string "Base64Encoding" Base64 encoding "ByteArray" hash code as an explicit byte array
Examples
open allclose allBasic Examples (4)Summary of the most common use cases

https://wolfram.com/xid/0wgyg2i-za2bry


https://wolfram.com/xid/0wgyg2i-7893ik

SHA256 hash given in hexadecimal form:

https://wolfram.com/xid/0wgyg2i-gflclo

Specify output length of the SHA hash:

https://wolfram.com/xid/0wgyg2i-ksffn8

Scope (12)Survey of the scope of standard use cases

https://wolfram.com/xid/0wgyg2i-of40cz


https://wolfram.com/xid/0wgyg2i-slb7f2

Compare all the different hash codes:

https://wolfram.com/xid/0wgyg2i-8csbmb

Calculate "BLAKE2b" hashes with different lengths:

https://wolfram.com/xid/0wgyg2i-l3pklg

512-bit SHA code given as an integer:

https://wolfram.com/xid/0wgyg2i-ivtv9a


https://wolfram.com/xid/0wgyg2i-wmdxy0

512-bit SHA code given as a decimal string, including leading zeroes:

https://wolfram.com/xid/0wgyg2i-bwe34


https://wolfram.com/xid/0wgyg2i-9d5c65

Compare the different string representations of a hash:

https://wolfram.com/xid/0wgyg2i-e7iqlh

The double SHA code given as a ByteArray:

https://wolfram.com/xid/0wgyg2i-mevezj

The byte array contains the 256 bits of the result:

https://wolfram.com/xid/0wgyg2i-p04gji

View the individual bytes in the array:

https://wolfram.com/xid/0wgyg2i-tn2iqh

RIPEMD160SHA256 hash is essentially a repeated hash:

https://wolfram.com/xid/0wgyg2i-bv789r


https://wolfram.com/xid/0wgyg2i-h5buch

When using ByteArray or a string, literal bytes are hashed:

https://wolfram.com/xid/0wgyg2i-hy8ef6


https://wolfram.com/xid/0wgyg2i-lpsj1c

For non-ASCII characters, UTF-8 representation is used for hashing:

https://wolfram.com/xid/0wgyg2i-ep10m


https://wolfram.com/xid/0wgyg2i-kip2mb


https://wolfram.com/xid/0wgyg2i-bteqd


https://wolfram.com/xid/0wgyg2i-deudzd

Compute a cryptographic hash of zero bytes:

https://wolfram.com/xid/0wgyg2i-fg72nv

Calculate BLAKE2xs hash of desired length:

https://wolfram.com/xid/0wgyg2i-gyqecl

Applications (2)Sample problems that can be solved with this function
Provide a "checksum" to validate data integrity:

https://wolfram.com/xid/0wgyg2i-bmq52r

https://wolfram.com/xid/0wgyg2i-lf57t3


https://wolfram.com/xid/0wgyg2i-htejxk

https://wolfram.com/xid/0wgyg2i-fbfjfz


https://wolfram.com/xid/0wgyg2i-ektxx9

A concatenated cryptographic hash function:

https://wolfram.com/xid/0wgyg2i-y4rffz

https://wolfram.com/xid/0wgyg2i-ln48md

Properties & Relations (12)Properties of the function, and connections to other functions
The hash is always the same for identical expressions:

https://wolfram.com/xid/0wgyg2i-bjh6jr

https://wolfram.com/xid/0wgyg2i-dkeuci


https://wolfram.com/xid/0wgyg2i-csahb9

Distinct hash codes come from distinct inputs:

https://wolfram.com/xid/0wgyg2i-ugxiov


https://wolfram.com/xid/0wgyg2i-gtbwqt

The default hash code is "Expression":

https://wolfram.com/xid/0wgyg2i-cker5u

The "Expression" hash fits in a machine word:

https://wolfram.com/xid/0wgyg2i-0gtl69

https://wolfram.com/xid/0wgyg2i-nw4xqr


https://wolfram.com/xid/0wgyg2i-yyfies

"Integer" is the default format:

https://wolfram.com/xid/0wgyg2i-hkidqk

"DecimalString" is the string version of "Integer", padded with zeros if necessary:

https://wolfram.com/xid/0wgyg2i-ct1l5z

"HexString" is a base 16 representation, padded with zeros if necessary:

https://wolfram.com/xid/0wgyg2i-dvmssr

"Base36String" is a base 36 representation, padded with zeros if necessary:

https://wolfram.com/xid/0wgyg2i-b17y7o

"Base64Encoding" encodes bytes of the result using Base64 encoding:

https://wolfram.com/xid/0wgyg2i-bi5tkl


https://wolfram.com/xid/0wgyg2i-4znlsp

"ByteArray" is a base 256 representation:

https://wolfram.com/xid/0wgyg2i-cg8d51


https://wolfram.com/xid/0wgyg2i-lo9596

Convert from base 256 to an integer:

https://wolfram.com/xid/0wgyg2i-jbk9m


https://wolfram.com/xid/0wgyg2i-bznant

Repeated hash can be obtained by using ByteArray as an intermediate result:

https://wolfram.com/xid/0wgyg2i-bknoic


https://wolfram.com/xid/0wgyg2i-gv0hp7

FileHash[file,code] is effectively equivalent to Hash[ReadByteArray[file],code]:

https://wolfram.com/xid/0wgyg2i-q2y6le

Possible Issues (3)Common pitfalls and unexpected behavior
Hash of a List of integers uses a serialized version of the list as an expression:

https://wolfram.com/xid/0wgyg2i-bcrtw6

To hash literal bytes, use a ByteArray:

https://wolfram.com/xid/0wgyg2i-f4ate

ASCII strings can be used to hash 7-bit byte values:

https://wolfram.com/xid/0wgyg2i-0u9gic


https://wolfram.com/xid/0wgyg2i-cz475v

The Hash of an expression and a string containing the FullForm of the expression are different:

https://wolfram.com/xid/0wgyg2i-e5j44j


https://wolfram.com/xid/0wgyg2i-gy01ze

Hash takes into account the full symbol name, including its Context, which may result in different hash values:

https://wolfram.com/xid/0wgyg2i-0qucx


https://wolfram.com/xid/0wgyg2i-g8tgah

Neat Examples (2)Surprising or curious use cases
Hash collisions are very rare, but possible. Here are two lists of bytes:

https://wolfram.com/xid/0wgyg2i-lba3fa

https://wolfram.com/xid/0wgyg2i-gthzcu

https://wolfram.com/xid/0wgyg2i-e6s05u


https://wolfram.com/xid/0wgyg2i-h4gaht

Hash the two sequences of bytes:

https://wolfram.com/xid/0wgyg2i-fu5tmq


https://wolfram.com/xid/0wgyg2i-yuof3


https://wolfram.com/xid/0wgyg2i-e79rs

Distribution of hash values for different types:

https://wolfram.com/xid/0wgyg2i-bu7tsj


https://wolfram.com/xid/0wgyg2i-8a1jb


https://wolfram.com/xid/0wgyg2i-gycl4z


https://wolfram.com/xid/0wgyg2i-om2ki


https://wolfram.com/xid/0wgyg2i-b6bg9


https://wolfram.com/xid/0wgyg2i-1ur9b

Wolfram Research (1988), Hash, Wolfram Language function, https://reference.wolfram.com/language/ref/Hash.html (updated 2022).
Text
Wolfram Research (1988), Hash, Wolfram Language function, https://reference.wolfram.com/language/ref/Hash.html (updated 2022).
Wolfram Research (1988), Hash, Wolfram Language function, https://reference.wolfram.com/language/ref/Hash.html (updated 2022).
CMS
Wolfram Language. 1988. "Hash." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Hash.html.
Wolfram Language. 1988. "Hash." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Hash.html.
APA
Wolfram Language. (1988). Hash. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Hash.html
Wolfram Language. (1988). Hash. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Hash.html
BibTeX
@misc{reference.wolfram_2025_hash, author="Wolfram Research", title="{Hash}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Hash.html}", note=[Accessed: 08-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_hash, organization={Wolfram Research}, title={Hash}, year={2022}, url={https://reference.wolfram.com/language/ref/Hash.html}, note=[Accessed: 08-July-2025
]}