Maroonbells (talk | contribs) (Create content for empty page) |
(No difference)
|
Revision as of 18:45, 14 June 2017
The $crc identifier calculates the 32-bit checksum of a text, binary variable, or file. Hash is 32-bits, shown as 8 upper-case hexadecimal characters.
Synopsis
$crc(plaintext|&binaryvar|filename[,N])
Parameters
plaintext - Used with N = 0, just the string you want the CRC-32 checksum hash of
&binaryvar - A binary variable, used with N = 1, return the CRC-32 checksum of the content of the binary variable
filename - A filename, used with N = 2, return the CRC-32 checksum 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 2 is used (which is different than $sha1 which has default of N=0.) Also different than $sha1, invalid N outside 0-2 range are treated as default 2 instead of creating an error.
Properties
None
Example
Echo the $crc hash of plain text string abc to the active window:
//echo -a $crc(abc,0)
The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
Echo the CRC-32 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 $crc(&snip,1)
Echo the CRC-32 hash of the contents of the mIRC program you're running to the active window:
//echo -a $crc($mircexe,2) or //echo -a $crc($mircexe)
Returns 00000000 if filename does not exist:
//echo -a $crc(no_such_file.txt,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 CRC checksum was made. * Verify downloaded file hasn't been corrupted, matches the sender's original. <br /> Note that because the default is N=2, '''$crc(versions.txt)''' is the CRC-32 for the contents of versions.txt (or 00000000 if the file doesn't exist). This differs from $sha1(versions.txt) giving the hash of the plaintext inside the parenthesis because $sha1 has default of N=0.<br /> mIRC v7.x Unicode-encodes plaintext before providing to $crc, so v7.x and v6.x return different answers for //echo -a $crc($chr(233),0)<br /> 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 $crc as a binary variable:<br /> <pre>//bset -ta &string 1 chloé | echo -a $crc(&string,1)
Error Messages
None
$crc differs from $sha1 in that it returns no error messages.
For non-existent filenames, it returns 00000000 instead of halting script with an error. For calculating hash of $null string it returns nothing instead of the checksum of the null-string When given invalid N outside the 0-2 range, it uses default 2 instead of halting script with an error.
Compatibility
Added: mIRC v5.6
Added on: 03 Jun 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
for $crc(filename)
Added: mIRC v6.1
Added on: 29 Aug 2003
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
for N=0-2 parameter