<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi all,<br>
<br>
rs_calc_weak_sum, cast data from void to unsigned char.<br>
In C, unsigned char can represent values from 0 to 255<br>
In Java, the smallest data type is the byte and it can represent values
from -128 to 127 and there is not unsigned type.<br>
<br>
My implementation of weaksum use an array of bytes and do :<br>
<br>
int s2 += 4 * (s1 + buffer[i]) + 3 * buffer[i + 1] + 2 * buffer[i + 2]
+ buffer[i + 3] + 10 * RS_CHAR_OFFSET;<br>
<br>
In that, buffer[i] and others are silently converted to int.<br>
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<br>
<br>
To have the correct value, i must do :<br>
int bt = (buffer[i] < 0) ? (int)buffer[i] & 0x00ff :
(int)buffer[i];<br>
<br>
And now, checksum is correct. Test of COPYING was successful because
there's no byte with value greater than 127.<br>
<br>
So that problem is solved :-) ... for now ...<br>
<br>
Thanks for attention<br>
<br>
Le 24/01/2011 18:40, Frédéric Lecointre a écrit :
<blockquote cite="mid:4D3DB972.3000503@burnweb.net" type="cite">Hi all,
<br>
<br>
I'm trying a java implementation of rsync for "fun and profits" ;-)
helped by librsync 0.9.7 and jarsync (a died java implementation)
<br>
So i started to implement rdiff command and for now i have a working
signature command.
<br>
<br>
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 :
<br>
- each weak sum is different but just byte 1 and 3
<br>
- each strong sum is identical
<br>
<br>
For example, this is the begenning of signature from and rdiff and java
<br>
<br>
# From rdiff
<br>
72 73 01 36 00 00 08 00 00 00 00 08 <- header
<br>
Pair 1
<br>
e1 c4 cd 65 <- weak
<br>
8b 4f 52 f9 d9 d2 27 e1 <- strong
<br>
<br>
Pair 2
<br>
30 66 72 71 <- weak
<br>
cd f6 1e 66 ac f2 af c5 <- strong
<br>
<br>
# From java
<br>
72 73 01 36 00 00 08 00 00 00 00 08 <- header
<br>
<br>
Pair 1
<br>
26 c4 ad 65 <- weak
<br>
8b 4f 52 f9 d9 d2 27 e1
<br>
<br>
Pair 2
<br>
c3 66 86 71 <- weak
<br>
cd f6 1e 66 ac f2 af c5 <- strong
<br>
<br>
Is anyone have an idea ?
<br>
<br>
Thanks in advance.
<br>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<strong>Frédéric Lecointre</strong>
</div>
</body>
</html>