StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Miscellaneous Utilities : StringTools/Hash

StringTools

 Hash
 compute a hash value for a string

 Calling Sequence Hash( s ) Hash( s, method=m )

Parameters

 s - Maple string or byte Array; string to be hashed m - one of "md4", "md5", or "sha1".

Options

 • method : one of "md4", "md5", or "sha1". This specifies the hashing algorithm to use. The default value is "md5".

Description

 • The procedure Hash computes a hash, or message digest of the string s. By default, it uses the MD5 message digest algorithm. However, by using the method= option, you can select a different hashing algorithm. The available methods are: "md5", "md4" and "sha1".
 • This hashed value is represented by a string that is a hexadecimal representation of the integer value of the hash.
 • The input can be a Maple string or a ByteArray. Using a ByteArray is necessary if the desired input contains bytes that are zero: a string cannot contain such bytes.
 • It is extremely unlikely that two distinct strings, of arbitrary length, will produce the same hashed value.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Hash}\left(""\right)$
 ${"d41d8cd98f00b204e9800998ecf8427e"}$ (1)
 > $\mathrm{Hash}\left("abcde"\right)$
 ${"ab56b4d92b40713acc5af89985d4b786"}$ (2)
 > $\mathrm{Hash}\left("xxxx"\right)$
 ${"ea416ed0759d46a8de58f63a59077499"}$ (3)
 > $\mathrm{Hash}\left("xxxxx"\right)$
 ${"fb0e22c79ac75679e9881e6ba183b354"}$ (4)
 > $a≔\mathrm{Array}\left(\left[1,0,4\right],'\mathrm{datatype}=\mathrm{integer}[1]'\right)$
 ${a}{:=}\left[\begin{array}{ccc}{1}& {0}& {4}\end{array}\right]$ (5)
 > $\mathrm{Hash}\left(a\right)$
 ${"2fd5cec7a3d4210b1676d83b998d6533"}$ (6)
 > $\mathrm{Hash}\left("abc",'\mathrm{method}'="sha1"\right)$
 ${"a9993e364706816aba3e25717850c26c9cd0d89d"}$ (7)
 > $\mathrm{Hash}\left("abc",'\mathrm{method}'="md4"\right)$
 ${"a448017aaf21d8525fc10ae87aa6729d"}$ (8)