Skip to Content
author's profile photo Former Member
Former Member

Checksum code

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Posted on Sep 22, 2006 at 10:08 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 25, 2006 at 08:33 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 25, 2006 at 01:42 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.