From WikiChip
Editing mirc/identifiers/$sha1
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 9: | Line 9: | ||
'''filename''' - A filename, used with N = 2, return the sha1 hash of the content of the file | '''filename''' - A filename, used with N = 2, return the sha1 hash of the content of the file | ||
− | '''N:''' Optional integer 0-2, where 0 | + | '''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 /> |
If the N parameter isn't used, the default 0 is used (which is different than $crc which has default of N=2.) | If the N parameter isn't used, the default 0 is used (which is different than $crc which has default of N=2.) | ||
Line 25: | Line 25: | ||
Echo the SHA1 hash of the first 1000 bytes of the mIRC program you're running to the active window: | Echo the SHA1 hash of the first 1000 bytes of the mIRC program you're running to the active window: | ||
− | <pre>//bread $qt($mircexe) 0 1000 &snip | echo -a | + | <pre>//bread $qt($mircexe) 0 1000 &snip | echo -a $sha1(&snip,1)</pre> |
Mode 0 allows string to be null, including %variable not existing. | Mode 0 allows string to be null, including %variable not existing. | ||
<pre>//unset %a | var %b $null | echo -a $sha1(%a) is $sha1(%b) is $sha1()</pre> | <pre>//unset %a | var %b $null | echo -a $sha1(%a) is $sha1(%b) is $sha1()</pre> | ||
− | Mode 1 allows binvar to be zero length | + | Mode 1 allows binvar to be zero length but not undefined. |
<pre>//noop $regsubex(foo,$null,,,&v) | echo -a $bvar(&v) $sha1(&v,1) | echo -a $bvar(&v2) $sha1(&v2,1)</pre> | <pre>//noop $regsubex(foo,$null,,,&v) | echo -a $bvar(&v) $sha1(&v,1) | echo -a $bvar(&v2) $sha1(&v2,1)</pre> | ||
Line 39: | Line 39: | ||
* Quick way to compare if 2 files are identical. (First check should always be comparing file sizes.) | * 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. | * 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 | + | * Verify downloaded file hasn't been corrupted, matches the sender's original. |
<br /> | <br /> | ||
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.<br /> | 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.<br /> | ||
Line 49: | Line 49: | ||
== Warning == | == Warning == | ||
− | From v7.54 back through at least v6.35 | + | From v7.54 back through at least v6.35, $sha1 corrupts the &binvar if the length is 128+ and a multiple of 64 and contains at least 1 byte that isn't 0x00. This affects using sha1 against &binvar in $hmac too. It returns the correct hash of the input &binvar in spite of destroying it. |
<pre>//bset &v 128 1 | noop $sha1(&v,1) | echo -a $bvar(&v,1-)</pre> | <pre>//bset &v 128 1 | noop $sha1(&v,1) | echo -a $bvar(&v,1-)</pre> | ||
− | |||
− | |||
− | |||
== Error Messages == | == 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. | 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. | ||
Line 64: | Line 61: | ||
<pre>Both above errors halt execution of the script</pre> | <pre>Both above errors halt execution of the script</pre> | ||
− | |||
− | |||
== Compatibility == | == Compatibility == | ||
{{mIRC compatibility|6.3}} | {{mIRC compatibility|6.3}} |