Note that there are some explanatory texts on larger screens.

plurals
  1. POEquivalent to Unix cksum in Windows
    primarykey
    data
    text
    <p>I download a file and his checksum (generated by cksum Unix command).</p> <p>So, I want, in my C# app test if the Checksum is in adequation with the app I downloaded.</p> <p>I checked at the Unix man page of chsum:</p> <blockquote> <pre><code> The cksum command calculates and prints to standard output a checksum for each named file, the number of octets in the file and the filename. cksum uses a portable algorithm based on a 32-bit Cyclic Redundancy Check. This algorithm finds a broader spectrum of errors than the 16-bit algorithms used by sum (see sum(1)). The CRC is the sum of the following expressions, where x is each byte of the file. x^32 + x^26 + x^23 +x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 The results of the calculation are truncated to a 32-bit value. The number of bytes in the file is also printed. </code></pre> </blockquote> <p>So i wrote a simple program that does the sum :</p> <pre><code>byte[] arr = File.ReadAllBytes(@"MyApp").ToArray(); int cksum = 0; foreach (byte x in arr) { cksum += (x ^ 32 + x ^ 26 + x ^ 23 + x ^ 22 + x ^ 16 + x ^ 12 + x ^ 11 + x ^ 10 + x ^ 8 + x ^ 7 + x ^ 5 + x ^ 4 + x ^ 2 + x ^ 1 + x ^ 0); } </code></pre> <p>But checksums aren't the same, how can I fix this?</p> <p>Thanks</p> <hr> <h2>EDIT</h2> <p>1) The modified algorithm is:</p> <pre><code>uint cksum = 0; foreach (byte b in arr) { var x = (uint)b; cksum += (IntPow(x, 32) + IntPow(x, 26) + IntPow(x, 23) + IntPow(x, 22) + IntPow(x, 16) + IntPow(x, 12) + IntPow(x, 11) + IntPow(x, 10) + IntPow(x, 8) + IntPow(x, 7) + IntPow(x, 5) + IntPow(x, 4) + IntPow(x, 2) + IntPow(x, 1) + IntPow(x, 0)); } </code></pre> <p>2) I used the <code>class Crc32 : HashAlgorithm</code></p> <p>Given an Unix file where the Crc32 is : 2774111254</p> <ul> <li>1) Gives me : 4243613712</li> <li>2) Gives me : 3143134679 (with a seed of 0)</li> </ul> <p>What I'm doing wrong !?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload