From WikiChip
Editing mirc/identifiers/$crc

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 17: Line 17:
  
 
== Properties ==
 
== Properties ==
 +
 
None
 
None
  
 
== Example ==
 
== Example ==
<source lang="mIRC">
+
Echo the $crc hash of plain text string ''abc'' to the active window:
; Echo the $crc hash of plain text string ''abc'' to the active window:
+
<pre>//echo -a $crc(abc,0)
; The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
+
</pre>
//echo -a abc $crc(abc,0) / ABC $crc(ABC,0)
+
The DATA is case-sensitive, so hash of "abc" is different than hash of "ABC"
</source>
 
  
<source lang="mIRC">
+
Echo the CRC-32 hash of the first 1000 bytes of the mIRC program you're running to the active window:
; Calculate the CRC-32 hash of the 256 bytes from $chr(0) through $chr(255):
+
<pre>//bread $qt($mircexe) 0 1000 &snip | echo -a $crc(&snip,1)</pre>
//var %i 0 | while (%i isnum 0-255) { bset &ascii $calc(1+%i) %i | inc %i } | echo -a $bvar(&ascii,1-) | echo -a $crc(&ascii,1) should be 29058C73 | write -c ascii.dat | bwrite ascii.dat 0 256 &ascii
 
</source>
 
  
<source lang="mIRC">
+
Echo the CRC-32 hash of the contents of the mIRC program you're running to the active window:
; display the same CRC of filename ascii.dat as the above binary variable &ascii
+
<pre>//echo -a $crc($mircexe,2)
//echo -a filesize $file(ascii.dat).size $crc(ascii.dat) is the same as $crc(ascii.dat,2) because default N is 2
+
or
; append 4 bytes to ascii.dat to change the CRC value:
+
//echo -a $crc($mircexe)
//bset &b 1 176 84 33 47 | /bwrite ascii.dat -1 4 &b
+
</pre>
//echo -a filesize $file(ascii.dat).size has different CRC value $crc(ascii.dat,2)
 
</source>
 
  
 
Returns 00000000 if filename does not exist:
 
Returns 00000000 if filename does not exist:
<pre>
+
<pre>//echo -a $crc(no_such_file.txt,2)
//echo -a $crc(no_such_file.txt,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.)
Line 48: Line 43:
 
* Verify downloaded file hasn't been corrupted, matches the sender's original.
 
* Verify downloaded file hasn't been corrupted, matches the sender's original.
 
<br />
 
<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 />
+
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 />
 
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 />
 
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>
+
<pre>//bset -ta &string 1 chloé | echo -a $crc(&string,1)</pre>
//var %name chloé | bset -ta &string1 1 %name | bset -t &string2 1 %name | echo -a $crc(&string1,1) / $crc(&string2,1) / $crc(%name,0)
 
</pre>
 
 
 
'''Note:''' CRC-32 is good for detecting transfer errors. Any 1 bit changed in a file is guaranteed to change the CRC-32 value, which is not necessarily true for $sha1 or other 1-way hashes. However, CRC-32 is not good for detecting malicious tampering with a file. There is a 4-byte binary string which can change a file from any CRC-32 value to any CRC-32 value, and these 4 bytes can be quickly calculated without brute force testing of the 2^32 possible strings.
 
  
 
== Error Messages ==
 
== Error Messages ==

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)