on 09-22-2006 10:39 AM
Hi all,
i need to calculate a checksum of a file in Java..
The old program was written in Delphi and has following code:
unit lib_CRC;
interface
uses
SysUtils;
function CalculateCRC(Text: String): String;
implementation
{------------------------------------------------------------------------------}
.........
Now my problem is to have the same logic of this code, but written in java... I already tried 3 different programs, but they generate another checksum of the program written in Delphi.
Should I use the same array for the CRC table?
Anyone have experience with this matter?
Thx in advance!
Greets,
Wouter.
Message was edited by: Wouter Dhaenens
Hi,
now I have the error "<i>Type mismatch: cannot convert from byte[] to byte</i>...
This is the line code with error:
byte b = text;
Thx for your help!
Message was edited by: Wouter Dhaenens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thx for your code!
But I still have 1 little problem... there is one error:
Error: The operator ^is undefined for the argument type(s) int, byte[]
Anyone can tell me how to solve this error?
Thanks in advance!
Wouter.
Message was edited by: Wouter Dhaenens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this one:
private static int[] CRCTable =
{{------------------------------------------------------------------------------}};
public static String crc(String initialText) {
int CRCVal = 0;
String result;
byte[] text = initialText.getBytes();
for (int i = 0; i < text.length; i++) {
byte b = text<i>;
CRCVal = CRCTable [ Math.abs( (byte)( CRCVal ^ text<i> )) ] ^ ((CRCVal>>8) & 0x00FFFFFF);
}
return Long.toHexString(CRCVal).toUpperCase();
}
Message was edited by: Maksim Rashchynski
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.