Java implementation - about weak checksum difference

Frédéric Lecointre frederic.lecointre at burnweb.net
Wed Jan 26 06:40:31 MST 2011


Hi all,

rs_calc_weak_sum, cast data from void to unsigned char.
In C, unsigned char can represent values from 0 to 255
In Java, the smallest data type is the byte and it can represent values 
from -128 to 127 and there is not unsigned type.

My implementation of weaksum use an array of bytes and do :

int s2 += 4 * (s1 + buffer[i]) + 3 * buffer[i + 1] + 2 * buffer[i + 2] + 
buffer[i + 3] + 10 * RS_CHAR_OFFSET;

In that, buffer[i] and others are silently converted to int.
For example, if buffer[i] is a byte and value is 00E2 (226), 
(int)buffer[i] return FFE2 in java and not 00E2 as in c

To have the correct value, i must do :
int bt  = (buffer[i] < 0) ? (int)buffer[i] & 0x00ff : (int)buffer[i];

And now, checksum is correct. Test of COPYING was successful because 
there's no byte with value greater than 127.

So that problem is solved :-) ... for now ...

Thanks for attention

Le 24/01/2011 18:40, Frédéric Lecointre a écrit :
> Hi all,
>
> I'm trying a java implementation of rsync for "fun and profits" ;-) 
> helped by librsync 0.9.7 and jarsync (a died java implementation)
> So i started to implement rdiff command and for now i have a working 
> signature command.
>
> With first test, i had the same signature file of 
> testsuite/mksum.input/COPYING.sig but when i try with another dummy 
> file, for each checksum pair :
>     - each weak sum is different but just byte 1 and 3
>     - each strong sum is identical
>
> For example, this is the begenning of signature from and rdiff and java
>
> # From rdiff
> 72 73 01 36 00 00 08 00 00 00 00 08 <- header
> Pair 1
> e1 c4 cd 65 <- weak
> 8b 4f 52 f9 d9 d2 27 e1 <- strong
>
> Pair 2
> 30 66 72 71 <- weak
> cd f6 1e 66 ac f2 af c5 <- strong
>
> # From java
> 72 73 01 36 00 00 08 00 00 00 00 08 <- header
>
> Pair 1
> 26 c4 ad 65 <- weak
> 8b 4f 52 f9 d9 d2 27 e1
>
> Pair 2
> c3 66 86 71 <- weak
> cd f6 1e 66 ac f2 af c5 <- strong
>
> Is anyone have an idea ?
>
> Thanks in advance.

-- 
*Frédéric Lecointre*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/rsync/attachments/20110126/8a0663e3/attachment.html>


More information about the rsync mailing list