looking for a checksum routine in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angelo Chen

    looking for a checksum routine in C

    Hi,

    I'm looking for a way to calculate a checksum for a block of memory,
    I'd like to use a readable two char(0..9, A..Z) to represent this
    checksum, so the checksum should be less than 1296. I'm looking at
    crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
    that's more than what the two char can accommodate, any idea how to
    achieve this? even less than 1296, 1024 will do.

    Thanks,

    Angelo
  • Richard Bos

    #2
    Re: looking for a checksum routine in C

    Angelo Chen <angelochen960@ gmail.comwrote:
    I'm looking for a way to calculate a checksum for a block of memory,
    I'd like to use a readable two char(0..9, A..Z) to represent this
    checksum, so the checksum should be less than 1296. I'm looking at
    crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
    that's more than what the two char can accommodate, any idea how to
    achieve this? even less than 1296, 1024 will do.
    So what you want is basically a CRC-10, and the quality won't need to be
    fabulously high since, with those specs, you're not going to share your
    CRCs with anybody else.

    I strongly suspect a websearch on CRC-10 would be helpful to you.

    Richard

    Comment

    • Thad Smith

      #3
      Re: looking for a checksum routine in C

      Angelo Chen wrote:
      I'm looking for a way to calculate a checksum for a block of memory,
      I'd like to use a readable two char(0..9, A..Z) to represent this
      checksum, so the checksum should be less than 1296. I'm looking at
      crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
      that's more than what the two char can accommodate, any idea how to
      achieve this? even less than 1296, 1024 will do.
      I would use a 16- or 32-bit CRC and then reduce mod 1296.

      --
      Thad

      Comment

      • Angelo Chen

        #4
        Re: looking for a checksum routine in C

        On Jun 19, 9:34 pm, Thad Smith <ThadSm...@acm. orgwrote:
        I would use a 16- or 32-bit CRC and then reduce mod 1296.
        >
        That's one solution, but Richard suggests crc10, that's a good
        approach too, I'm still searching for any sample code, so far, none
        working code turned out.

        Comment

        • santosh

          #5
          Re: looking for a checksum routine in C

          Angelo Chen wrote:
          On Jun 19, 9:34 pm, Thad Smith <ThadSm...@acm. orgwrote:
          >
          >I would use a 16- or 32-bit CRC and then reduce mod 1296.
          >>
          >
          That's one solution, but Richard suggests crc10, that's a good
          approach too, I'm still searching for any sample code, so far, none
          working code turned out.
          What about the CRC code at:

          <http://c.snippets.org/browser.php>
          <http://www.ross.net/crc/links.html>

          Comment

          • Angelo Chen

            #6
            Re: looking for a checksum routine in C

            On Jun 19, 8:56 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:


            I found a code : http://www.packet.cc/files/CRC-10-code-ex.html, this
            works. now, any tips on how to pack a number which is less than 1024
            into a two byte char in the range of 0..9, A..Z?

            Thanks


            Comment

            • viza

              #7
              Re: looking for a checksum routine in C

              On Thu, 19 Jun 2008 07:45:43 -0700, Angelo Chen wrote:
              I found a code : http://www.packet.cc/files/CRC-10-code-ex.html, this
              works. now, any tips on how to pack a number which is less than 1024
              into a two byte char in the range of 0..9, A..Z?

              #define BASE32 "0123456789ABCD EFGHIJKLMNOPQRS TUV"
              {
              char str[2];
              int crc= crc10( data );

              str[0]= BASE32[ crc & 0x1f ];
              str[1]= BASE32[ crc >5 ];
              }

              Comment

              • viza

                #8
                Re: looking for a checksum routine in C

                On Thu, 19 Jun 2008 07:34:05 -0600, Thad Smith wrote:
                I would use a 16- or 32-bit CRC and then reduce mod 1296.
                Not necessarily very safe. You would need to investigate the type of CRC
                to see that it didn't, eg, treat the data as words and so using modulo
                (especially modulo a non-prime with only two bits set) might discard all
                information about certain bits in each input word.

                Comment

                • Angelo Chen

                  #9
                  Re: looking for a checksum routine in C

                  On Jun 19, 11:00 pm, viza <tom.v...@gmil. comwrote:
                  On Thu, 19 Jun 2008 07:45:43 -0700, Angelo Chen wrote:
                  #define BASE32 "0123456789ABCD EFGHIJKLMNOPQRS TUV"
                  {
                    char str[2];
                    int crc= crc10( data );
                  >
                    str[0]= BASE32[ crc & 0x1f ];
                    str[1]= BASE32[ crc >5 ];
                  >
                  }
                  thanks, that finally solves the problem. case closed:)

                  Comment

                  • CBFalconer

                    #10
                    Re: looking for a checksum routine in C

                    Angelo Chen wrote:
                    r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
                    >
                    I found a code : http://www.packet.cc/files/CRC-10-code-ex.html,
                    this works. now, any tips on how to pack a number which is less
                    than 1024 into a two byte char in the range of 0..9, A..Z?
                    Those char sets can represent 36 values each, so you can represent
                    any number less that 36 * 36.

                    --
                    [mail]: Chuck F (cbfalconer at maineline dot net)
                    [page]: <http://cbfalconer.home .att.net>
                    Try the download section.

                    ** Posted from http://www.teranews.com **

                    Comment

                    • CBFalconer

                      #11
                      Re: looking for a checksum routine in C

                      Angelo Chen wrote:
                      >
                      I'm looking for a way to calculate a checksum for a block of memory,
                      I'd like to use a readable two char(0..9, A..Z) to represent this
                      checksum, so the checksum should be less than 1296. I'm looking at
                      crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
                      that's more than what the two char can accommodate, any idea how to
                      achieve this? even less than 1296, 1024 will do.
                      Use the 16 bit crc, such as CCIT. You can always display it as 4
                      hex chars. In addition, pay attention to whether you want to
                      detect errors in leading blocks of zeroes, which requires
                      initializing the crc to 0xffff.

                      --
                      [mail]: Chuck F (cbfalconer at maineline dot net)
                      [page]: <http://cbfalconer.home .att.net>
                      Try the download section.


                      ** Posted from http://www.teranews.com **

                      Comment

                      Working...