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 1: Line 1:
{{mirc title|$sha1 identifier}}'''$sha1''' calculates the [[sha1 hash]] of a text, {{mirc|binary variables|binary variable}}, or file. Hash is 160-bits, shown as 40 lower-case hexadecimal characters.
+
{{mirc title|$sha1 Identifier}}
 +
The '''$sha1''' identifier calculates the [[sha1 hash]] of a text, {{mirc|binary variables|binary variable}}, or file. Hash is 160-bits, shown as 40 lower-case hexadecimal characters.
 +
 
 
== Synopsis ==
 
== Synopsis ==
<pre>$sha1(plaintext|&binaryvar|filename,[N])</pre>
+
<pre>$sha1(plaintext|&binaryvar|filename,[N])
 +
</pre>
 +
 
 
== Parameters ==
 
== Parameters ==
 
'''plaintext''' - Used with N = 0, just the string you want the sha1 hash of
 
'''plaintext''' - Used with N = 0, just the string you want the sha1 hash of
Line 9: Line 13:
 
'''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 returns hash of the plaintext string, 1 returns the hash of the data contained inside the named &binary variable, 2 returns the hash of the contents of the named disk 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 />
  
 
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.)
 +
 
== Properties ==
 
== Properties ==
 +
 
None
 
None
 +
 
== Example ==
 
== Example ==
 
Echo the SHA1 hash of plain text string ''abc'' to the active window:
 
Echo the SHA1 hash of plain text string ''abc'' to the active window:
Line 21: Line 28:
 
The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
 
The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
  
Echo the SHA1 hash of the contents of the mIRC program you're running to the active window:
+
Echo the SHA1 hash of the zero-length null string to the active window:
<pre>//echo -a $sha1($mircexe,2)</pre>
+
<pre>//echo -a $sha1($null)</pre>
  
 
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 $sha1(&snip,1) and again $sha1(&snip,1)</pre>
+
<pre>//bread $qt($mircexe) 0 1000 &snip | echo -a $sha1(&snip,1)</pre>
  
Mode 0 allows string to be null, including %variable not existing.
+
Echo the SHA1 hash of the contents of the mIRC program you're running to the active window:
<pre>//unset %a | var %b $null | echo -a $sha1(%a) is $sha1(%b) is $sha1()</pre>
+
<pre>//echo -a $sha1($mircexe,2)</pre>
 
 
Mode 1 allows binvar to be zero length generates an error if the &binvar is not defined.
 
<pre>//noop $regsubex(foo,$null,,,&v) | echo -a $bvar(&v) $sha1(&v,1) | echo -a $bvar(&v2) $sha1(&v2,1)</pre>
 
 
 
Mode 2 allows filesize to be zero but not missing.
 
<pre>//btrunc zero.dat 0 | echo -a $sha1(zero.dat,2) | remove zero.dat | echo -a $sha1(zero.dat,2)</pre>
 
  
 
Suggested Uses:
 
Suggested Uses:
 
* 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 the hash obtained from the sender.
+
* 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 />
 
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))<br />
 
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))<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 $sha1 as a binary variable:<br />
 
 
<pre>//bset -ta &string 1 chloé | echo -a $sha1(&string,1)</pre>
 
 
== Warning ==
 
From v7.54 back through at least v6.35, and probably as far back as v6.3 when it was added, $sha1 can corrupt the contents of the &binvar it is hashing. If the length is 128+, and the file is split into 64-byte chunks, the 1st chunk is never affected, but each of the other 64-byte chunks that are not consisting entirely of 0x00 bytes is corrupted. This can be seen in the above example hashing the first 1000 bytes of mirc.exe, where v7.54 and earlier versions produce different hashes when repeating the exact same command against the same &binvar. In those same versions, this also affects using the same &binvar as the data hashed by $hmac when it uses sha1 has the hash. 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>
 
 
Users of those versions needing to use the contents of the &binvar after hashing would need to use a throw-away temporary &binvar whose contents are not needed after being hashed.
 
  
 
== Error Messages ==
 
== Error Messages ==
Line 64: Line 55:
  
 
<pre>Both above errors halt execution of the script</pre>
 
<pre>Both above errors halt execution of the script</pre>
Note: even though an SHA1 hash collision has been found between 2 different strings, it continues to be considered adequate in some situations, especially when used by $hmac as its hash function. The collision was possible in a scheme where they finding 2 strings having a matching hash regardless of that value, but it still remains out of reach of creating collisions against a specific sha1 hash. SHA1 continues to be widely used in Google Authenticator TOTP where sha1 is used inside HMAC. It continues to be used by github to detect changes in documents, where any collision would result in keeping the existing older file and discarding the new file having the matching sha1 hash.
 
  
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|6.3}}
 
{{mIRC compatibility|6.3}}
== See Also ==
+
 
{{collist
+
== See also ==
|count = 3
+
* {{mIRC|$crc}}
|style = width: 100%; display: inherit;
+
* {{mIRC|$md5}}
|
 
 
* {{mIRC|$sha256}}
 
* {{mIRC|$sha256}}
 +
* {{mIRC|$sha384}}
 
* {{mIRC|$sha512}}
 
* {{mIRC|$sha512}}
* {{mIRC|$sha384}}
+
* [[List of identifiers - mIRC]]
* {{mIRC|$md5}}
+
{{mIRC identifier list}}
* {{mIRC|$crc}}
 
* {{mIRC|$hmac}}
 
* {{mIRC|$hotp}}
 
* {{mIRC|$totp}}
 
}}
 

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)