Adler32 Algorithm Doubts
-
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) <=
-
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) <=
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] -
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]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.
-
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.
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] -
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) <=
Any updates?