From WikiChip
Difference between revisions of "mirc/identifiers/$sha1"
< mirc‎ | identifiers

(Created content for empty page)
 
(added title, short description)
Line 1: Line 1:
 +
{{mirc title|$sha1 Identifier}}
 +
The '''$sha1''' identifier calculates the [[sha1 hash]] of a text, {{mirc|binary variables|binary variable}}, or file.
 +
 
== Synopsis ==
 
== Synopsis ==
 
<pre>$sha1(plaintext|&binaryvar|filename,[N])
 
<pre>$sha1(plaintext|&binaryvar|filename,[N])

Revision as of 22:09, 11 June 2017

The $sha1 identifier calculates the sha1 hash of a text, binary variable, or file.

Synopsis

$sha1(plaintext|&binaryvar|filename,[N])
Returns the sha1 hash for the specified data, where N = 0 for plain text (default), 1 for &binary variable, 2 for filename.

Hash is 160-bits, shown as 40 hexadecimal characters.

Parameters

Required: Data
Optional: Integer 0-2, where 0 (default) indicates data is plaintext, 1 indicates a &binary variable, 2 indicates contents of a filename

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)

$sha1 is case-sensitive, so hash of "abc" is different than hash of "ABC"

Echo the SHA1 hash of the zero-length nul string to the active window:

//echo -a $sha1($nul)

Echo the SHA1 hash of the contents of the mIRC program you're running to the active window:

//echo -a $sha1($mircexe,2)

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)

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 $sha1($mircexe) is the same as the SHA1 hash for the text string of the drive:\path\filename for the mIRC you're running, regardless of file contents.
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))

Error Messages

Note that $sha1 differs from $crc in that it generates error for non-existent files instead of returning hash of $nul string. Also, in absence of specifying index 0-2, $sha1's default is 0 while $crc's default is 2. Also, hex string returned by $sha1 is lowercase while $crc returns uppercase.

* 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

[Expand]
v · d · e mIRC identifier list