Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Adler32 Algorithm Doubts

Adler32 Algorithm Doubts

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasealgorithms
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rupeshkp728
    wrote on last edited by
    #1

    I am writing a adler32 code to compute the adler32 checksum of a string. On the net I came across various sample codes: I did not understand some code entirely as <b>it has additional code</b> marked in bold below apart from the basic implementation of the adler32 logic. I did not understand the addional part as to what is is doing. Can anybody experienced with adler32 give some hint on it? The various sample codes are: //--------------------------------------------------------------------- // WIKI I understood this code as its the basic implementation of the adler32 logic. So no doubts in this. /* Loop over each byte of data, in order */ for (size_t index = 0; index < blen; ++index) { a = (a + buff[index]) % BASE; b = (b + a) % BASE; } wweak_cs = (b << 16) | a; //--------------------------------------------------------------------- // RSYNC I did not understand some code marked in bold below. { #define CHAR_OFFSET 0 char *buf = buff; int len = blen; int index = 0; UINT32 s1, s2; s1 = s2 = 0; for (index = 0; index < (len-4); index+=4) { s2 += 4*(s1 + buf[index]) + 3*buf[index+1] + 2*buf[index+2] + buf[index+3] + 10*CHAR_OFFSET; s1 += (buf[index+0] + buf[index+1] + buf[index+2] + buf[index+3] + 4*CHAR_OFFSET); } for (; index < len; index++) { s1 += (buf[index]+CHAR_OFFSET); s2 += s1; } rweak_cs = (s1 & 0xffff) + (s2 << 16); weak_cs = rweak_cs; } //--------------------------------------------------------------------- // sharpdevelop I did not understand some code marked in bold below. { char *buf = buff; int len = blen; sweak_cs = 1; int s1 = sweak_cs & 0xFFFF; int s2 = sweak_cs >> 16 & 0xFFFF; int index =0; while (len > 0) { int n = 3800; if (n > len) { n = len; } len -= n; while (--n >= 0) { s1 = s1 + (int)(buf[index++] & 0xFF); s2 = s2 + s1; } s1 %= BASE; s2 %= BASE; } sweak_cs = (s2 << 16) | s1; weak_cs = sweak_cs; } //--------------------------------------------------------------------- //altivec I did not understand some code marked in bold below. { #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <=

    CPalliniC R 2 Replies Last reply
    0
    • R rupeshkp728

      I am writing a adler32 code to compute the adler32 checksum of a string. On the net I came across various sample codes: I did not understand some code entirely as <b>it has additional code</b> marked in bold below apart from the basic implementation of the adler32 logic. I did not understand the addional part as to what is is doing. Can anybody experienced with adler32 give some hint on it? The various sample codes are: //--------------------------------------------------------------------- // WIKI I understood this code as its the basic implementation of the adler32 logic. So no doubts in this. /* Loop over each byte of data, in order */ for (size_t index = 0; index < blen; ++index) { a = (a + buff[index]) % BASE; b = (b + a) % BASE; } wweak_cs = (b << 16) | a; //--------------------------------------------------------------------- // RSYNC I did not understand some code marked in bold below. { #define CHAR_OFFSET 0 char *buf = buff; int len = blen; int index = 0; UINT32 s1, s2; s1 = s2 = 0; for (index = 0; index < (len-4); index+=4) { s2 += 4*(s1 + buf[index]) + 3*buf[index+1] + 2*buf[index+2] + buf[index+3] + 10*CHAR_OFFSET; s1 += (buf[index+0] + buf[index+1] + buf[index+2] + buf[index+3] + 4*CHAR_OFFSET); } for (; index < len; index++) { s1 += (buf[index]+CHAR_OFFSET); s2 += s1; } rweak_cs = (s1 & 0xffff) + (s2 << 16); weak_cs = rweak_cs; } //--------------------------------------------------------------------- // sharpdevelop I did not understand some code marked in bold below. { char *buf = buff; int len = blen; sweak_cs = 1; int s1 = sweak_cs & 0xFFFF; int s2 = sweak_cs >> 16 & 0xFFFF; int index =0; while (len > 0) { int n = 3800; if (n > len) { n = len; } len -= n; while (--n >= 0) { s1 = s1 + (int)(buf[index++] & 0xFF); s2 = s2 + s1; } s1 %= BASE; s2 %= BASE; } sweak_cs = (s2 << 16) | s1; weak_cs = sweak_cs; } //--------------------------------------------------------------------- //altivec I did not understand some code marked in bold below. { #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <=

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Why do you need the 'additional code' can you just use the basic algorithm? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      T 1 Reply Last reply
      0
      • CPalliniC CPallini

        Why do you need the 'additional code' can you just use the basic algorithm? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        T Offline
        T Offline
        tom groezer
        wrote on last edited by
        #3

        Here also Mr Palini is gracing the posts by his immmaculate understanding of software. Trying to highlack things. Boss come on earth else you will thump down.

        CPalliniC 1 Reply Last reply
        0
        • T tom groezer

          Here also Mr Palini is gracing the posts by his immmaculate understanding of software. Trying to highlack things. Boss come on earth else you will thump down.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          tom groezer wrote:

          Here also Mr Palini is gracing the posts by his immmaculate understanding of software.

          Wow, that's actually nice! :) Well, of course you missed the point of my post.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • R rupeshkp728

            I am writing a adler32 code to compute the adler32 checksum of a string. On the net I came across various sample codes: I did not understand some code entirely as <b>it has additional code</b> marked in bold below apart from the basic implementation of the adler32 logic. I did not understand the addional part as to what is is doing. Can anybody experienced with adler32 give some hint on it? The various sample codes are: //--------------------------------------------------------------------- // WIKI I understood this code as its the basic implementation of the adler32 logic. So no doubts in this. /* Loop over each byte of data, in order */ for (size_t index = 0; index < blen; ++index) { a = (a + buff[index]) % BASE; b = (b + a) % BASE; } wweak_cs = (b << 16) | a; //--------------------------------------------------------------------- // RSYNC I did not understand some code marked in bold below. { #define CHAR_OFFSET 0 char *buf = buff; int len = blen; int index = 0; UINT32 s1, s2; s1 = s2 = 0; for (index = 0; index < (len-4); index+=4) { s2 += 4*(s1 + buf[index]) + 3*buf[index+1] + 2*buf[index+2] + buf[index+3] + 10*CHAR_OFFSET; s1 += (buf[index+0] + buf[index+1] + buf[index+2] + buf[index+3] + 4*CHAR_OFFSET); } for (; index < len; index++) { s1 += (buf[index]+CHAR_OFFSET); s2 += s1; } rweak_cs = (s1 & 0xffff) + (s2 << 16); weak_cs = rweak_cs; } //--------------------------------------------------------------------- // sharpdevelop I did not understand some code marked in bold below. { char *buf = buff; int len = blen; sweak_cs = 1; int s1 = sweak_cs & 0xFFFF; int s2 = sweak_cs >> 16 & 0xFFFF; int index =0; while (len > 0) { int n = 3800; if (n > len) { n = len; } len -= n; while (--n >= 0) { s1 = s1 + (int)(buf[index++] & 0xFF); s2 = s2 + s1; } s1 %= BASE; s2 %= BASE; } sweak_cs = (s2 << 16) | s1; weak_cs = sweak_cs; } //--------------------------------------------------------------------- //altivec I did not understand some code marked in bold below. { #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <=

            R Offline
            R Offline
            rupeshkp728
            wrote on last edited by
            #5

            Any updates?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups