(Created page with "{{mirc title|$sha512 identifier}}'''$sha512''' calculates the sha512 hash of a text, {{mirc|binary variables|binary variable}}, or file. Hash is 160-bits, shown as 40 lowe...") |
(→Parameters) |
||
Line 5: | Line 5: | ||
== Parameters == | == Parameters == | ||
− | '''plaintext''' - Used with N = 0, just the string you want the | + | '''plaintext''' - Used with N = 0, just the string you want the sha512 hash of |
− | '''&binaryvar''' - A binary variable, used with N = 1, return the | + | '''&binaryvar''' - A binary variable, used with N = 1, return the sha512 hash of the content of the binvar |
− | '''filename''' - A filename, used with N = 2, return the | + | '''filename''' - A filename, used with N = 2, return the sha512 hash of the content of the file |
'''N:''' Optional integer 0-2, where 0 indicates data is treated as plaintext, 1 indicates a &binary variable, 2 treats data as contents of a filename<br /> | '''N:''' Optional integer 0-2, where 0 indicates data is treated as plaintext, 1 indicates a &binary variable, 2 treats data as contents of a filename<br /> |
Revision as of 16:39, 21 September 2017
$sha512 calculates the sha512 hash of a text, binary variable, or file. Hash is 160-bits, shown as 40 lower-case hexadecimal characters.
Synopsis
$sha512(plaintext|&binaryvar|filename,[N])
Parameters
plaintext - Used with N = 0, just the string you want the sha512 hash of
&binaryvar - A binary variable, used with N = 1, return the sha512 hash of the content of the binvar
filename - A filename, used with N = 2, return the sha512 hash of the content of the file
N: Optional integer 0-2, where 0 indicates data is treated as plaintext, 1 indicates a &binary variable, 2 treats data as contents of a filename
If the N parameter isn't used, the default 0 is used (which is different than $crc which has default of N=2.)
Properties
None
Example
Echo the SHA1 hash of plain text string abc to the active window:
//echo -a $sha1(abc) or //echo -a $sha1(abc,0)
The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
Echo the SHA1 hash of the zero-length null string to the active window:
//echo -a $sha1($null)
Echo the SHA1 hash of the first 1000 bytes of the mIRC program you're running to the active window:
//bread $qt($mircexe) 0 1000 &snip | echo -a $sha1(&snip,1)
Echo the SHA1 hash of the contents of the mIRC program you're running to the active window:
//echo -a $sha1($mircexe,2)
Suggested Uses:
- Quick way to compare if 2 files are identical. (First check should always be comparing file sizes.)
- Quick way to check if a file's contents have changed since stored sha1 hash was made.
- Verify downloaded file hasn't been corrupted, matches the sender's original.
Note that because the default is N=0, $sha1($mircexe) is the SHA1 hash for the plaintext text string of the drive:\path\filename for the mIRC you're running, and not the hash of the filename contents. This differs from $crc($mircexe) giving the checksum of the filename contents because $crc has default of N=2.
mIRC v7.x Unicode-encodes plaintext before providing to $sha1, so v7.x and v6.x return different answers for //echo -a $sha1($chr(233))
If the text doesn't have Unicode code points above 255, to avoid having Unicode points 128-255 encoded to 2-byte pairs, the text must be fed to $sha1 as a binary variable:
//bset -ta &string 1 chloé | echo -a $sha1(&string,1)
Error Messages
Note that $sha1 differs from $crc in that it generates error for non-existent files instead of returning hash of $null string. Also, hex string returned by $sha1 is lowercase while $crc returns uppercase hex.
* Error accessing file: $sha1
Either file does not exist, or file permissions don't allow the file to be read. i.e. $sha1(non-existent-file,2) or $sha1(c:\hiberfil.sys,2)
* Invalid parameters: $sha1
Either using a zero-length/non-existent binary variable or specifying an N where $int(%N) isn't 0-2.
Both above errors halt execution of the script
Compatibility
Added: mIRC v6.3
Added on: 16 Aug 2007
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
See also
- $crc
- $md5
- $sha256
- $sha384
- $sha512
- List of identifiers - mIRC