Total members 11893 |It is currently Tue Nov 05, 2024 1:38 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Adler-32 checksum java code
java code
/*
* Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
public class Adler32 implements Checksum {
private int value = 1;

/*
* BASE is the largest prime number smaller than 65536
* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
*/
private static final int BASE = 65521;
private static final int NMAX = 5552;

/**
* Update current Adler-32 checksum given the specified byte.
*/
public void update(int b) {
int s1 = value & 0xffff;
int s2 = (value >> 16) & 0xffff;
s1 += b & 0xff;
s2 += s1;
value = ((s2 % BASE) << 16) | (s1 % BASE);
}

/**
* Update current Adler-32 checksum given the specified byte array.
*/
public void update(byte[] b, int off, int len) {
int s1 = value & 0xffff;
int s2 = (value >> 16) & 0xffff;

while (len > 0) {
int k = len < NMAX ? len : NMAX;
len -= k;
while (k-- > 0) {
s1 += b[off++] & 0xff;
s2 += s1;
}
s1 %= BASE;
s2 %= BASE;
}
value = (s2 << 16) | s1;
}

/**
* Reset Adler-32 checksum to initial value.
*/
public void reset() {
value = 1;
}

/**
* Returns current checksum value.
*/
public long getValue() {
return (long)value & 0xffffffff;
}
}


java code
public interface Checksum {
/**
* Updates the current checksum with the specified byte.
*/
public void update(int b);

/**
* Updates the current checksum with the specified array of bytes.
*/
public void update(byte[] b, int off, int len);

/**
* Returns the current checksum value.
*/
public long getValue();

/**
* Resets the checksum to its initial value.
*/
public void reset();
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Adler-32 checksum java code
 TCP/IP Checksum     -  
 GamePLay java code ( please help )     -  
 Algorithms code in java     -  
 java code for chat     -  
 polyalphabetic cipher java code     -  
 Read your gmail using Java code     -  
 Java Insertion Sort Code     -  
 need java client/server code     -  
 apriori algorithm java code     -  
 How are Java source code files named     -  



Topic Tags

Java Networking
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com