Hash - Maple Help

FileTools

 Hash
 compute a hash value for a file

 Calling Sequence Hash(filepath, opts)

Parameters

 filepath - string; the file or URL to be hashed opts - zero or more options of the form method=value or output=value.

Options

 • method=one of md4, md5, or sha1.
 This specifies the hashing algorithm to use. The default value is md5.
 • output=one of string or integer
 This specifies whether the output should be a string with a hexadecimal representation of the hashed value, or an integer. The default value is string.

Description

 • The procedure Hash computes a hash, or message digest of the file 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: md4, md5 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 file or URL.
 • It is extremely unlikely that two distinct files of arbitrary length will produce the same hashed value.

Examples

 > file := FileTools:-JoinPath( ["images/rollercoaster.jpg"], base=datadir );
 ${"C:\Program Files\Maple 2016\data\images\rollercoaster.jpg"}$ (1)

Compute an MD5 hash of this file.

 > FileTools:-Hash( file );
 method = "md5", output = string
 ${"ad20d15e446e23ce8bb537f96720455c"}$ (2)

Compute an MD4 hash of this file.

 > FileTools:-Hash( file, method=md4 );
 method = md4, output = string
 ${"9733588532282617f53c026db00810a6"}$ (3)

Compute an SHA1 hash of this file.

 > FileTools:-Hash( file, method=sha1 );
 method = sha1, output = string
 ${"1af7332b4865b8254813bc07b068a92fe0d1381f"}$ (4)

Return the SHA1 hash as an integer.

 > FileTools:-Hash( file, method=sha1, output=integer );
 method = sha1, output = integer
 ${153946501560413761515295793599215680815507781663}$ (5)

Fetch a file from a remote source and compute an SHA1 hash.

 > FileTools:-Hash( "http://www.maplesoft.com/data/examples/jpg/fingerprint.jpg", method="sha1" );
 ${"1c2c82bd2b358b7fd2acb7dfffe3b67662f183a5"}$ (6)

Compatibility

 • The FileTools[Hash] command was introduced in Maple 2016.