Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:22:02+00:00 2026-05-23T15:22:02+00:00

I download a file and his checksum (generated by cksum Unix command). So, I

  • 0

I download a file and his checksum (generated by cksum Unix command).

So, I want, in my C# app test if the Checksum is in adequation with the app I downloaded.

I checked at the Unix man page of chsum:

  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.

So i wrote a simple program that does the sum :

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);
}

But checksums aren’t the same, how can I fix this?

Thanks


EDIT

1) The modified algorithm is:

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));
}

2) I used the class Crc32 : HashAlgorithm

Given an Unix file where the Crc32 is : 2774111254

  • 1) Gives me : 4243613712
  • 2) Gives me : 3143134679 (with a seed of 0)

What I’m doing wrong !?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:22:03+00:00Added an answer on May 23, 2026 at 3:22 pm

    In C# the ^ symbol is the exclusive-or operator. You want the function Math.Pow.

    This gives the piower of two floating point numbers, alteratives are suggested at How do you do *integer* exponentiation in C#?

    So, your code would look something like:

    cksum += Math.pow(x,32) + Math.pow(x,26)
    

    Be aware also of the last statement:

    The results of the calculation are truncated to a 32-bit value. The
    number of bytes in the file is also printed.

    Is this signed (int) or unsigned (uint)

    you could of course use the following:
    http://www.codeproject.com/Articles/35134/How-to-calculate-CRC-in-C

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to download a file and need to check the response status code
I don't know how to download a CSV file. The CSV will be generated
I want to download a image file (jpeg image) to the user files system
I am trying to download mp3 file to users machine without his/her consent while
I need to download file from FTP server and make some changes on it
I cannot download file using java if the url contains special characters. eg:-http://something.com/something/this+this+this.html http://something.com/something/this%20this%20this.html
How can I download a XAP file to Windows Phone 7? Can't download file
I'm using Watin to automate download file from a website. At some point a
I hope to display the download file size by reading http header. I know
i have a link <a id=DownloadLink href='controller/action' target=_blank>Download File</a> that has to open a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.