Summary of .hy3 checksum calculation...Thanks to Joe!
Joe's original description can be found here:
http://groups.google.com/group/rec.sport.swimming/browse_thread/thread/4c402f0648552e4a
I changed a few things I thought were in error and adapted for my java
code example. I take no credit for the algorithm just sharing what I
did with it.
Each line is actually 130 characters in length (128 characters of
"data" + 2 checksum characters)
To match the software I used zero based indexing (0, 1, 2, ..., 128,
129) so my odd and even characters are different than what was
described by Joe.
------------------------------------------------------------------------------------------
Step 1.) Excluding the checksum characters sum all of the even (0,
2, 4, ...,124, 126) characters, this is sumEvn
sumEvn = val0 + val2 + ... + val124 + val126
Step 2.) Excluding the checksum characters sum twice the value all
of the odd (1, 3, 5, ...,125, 127) characters, this is sumOdd.
sumOdd = 2*val1 + 2*val2 + ... + 2*val125 + 2*val127
Step 3.) Add the two sums (even and odd) together
sum = sumEvn + sumOdd
Step 4.) Divide by 21 and only take the integer portion (no
rounding)
result = (int) sum/21
Step 5.) Now add 205 to the result
sum2 = result + 205
Step 6.) The checksum digits are ones and tens digits from sum2 in
reverse order
checksum => sum2(ones digit) sum2(tens digit)
------------------------------------------------------------------------------------------
Here is a java code example I used to run some tests. Not sure any of
you have a use for java but I use it to parse all of my hy-tek files
to automatically generate web pages in a format I like along with
creating other supporting files. This one will simply check each line
of the file and report any line in which the checksum does not match
it will also report the file name and number of lines. By using a
batch file a quick test of multiple .hy3 files can be ran.
//-----------------------------------------------------------------------------
// .HY3 Checksum Validation
//-----------------------------------------------------------------------------
import java.io.*;
public class ChecksumValidation {
public static void main (String[] args) {
try {
// Open the file that is the first command line parameter
FileInputStream fstreamStandards = new FileInputStream(args[0]);
// Get the object of DataInputStream
DataInputStream inStandards = new
DataInputStream(fstreamStandards);
BufferedReader brStandards = new BufferedReader(new
InputStreamReader(inStandards));
// Read File Line By Line
int lineNumber = 0;
String strLine;
while ((strLine = brStandards.readLine()) != null) {
lineNumber++;
int sumEvn = 0;
int sumOdd = 0;
if (strLine.length() > 0) {
if (strLine.length() == 130) {
int fileChecksum =
Integer.parseInt(strLine.substring(128,130));
int fileTens = fileChecksum/10 % 10;
int fileOnes = fileChecksum/1 % 10;
for (int i=0;i<64;i++) {
sumEvn = sumEvn + (int) strLine.charAt(2*i);
sumOdd = sumOdd + (2 * ((int) strLine.charAt((2*i)+1)));
}
int checksum = ((int) ((sumEvn + sumOdd)/21)) + 205;
int tens = checksum/10 % 10;
int ones = checksum/1 % 10;
if ( (fileTens != ones) || (fileOnes != tens) ) {
System.out.printf("%s %5d %d%d %d%d
\n",args[0],lineNumber,ones, tens, fileTens, fileOnes);
}
} else {
System.out.printf("Line: %d is not 130 characters long.
\n",lineNumber);
}
}
}
System.out.printf("%-30s %10d\n",args[0] ,lineNumber);
inStandards.close();
} catch (Exception e) {
System.err.println("Error processing input file: " +
e.getMessage());
return;
}
} // main
} // Checksum Validation
//-----------------------------------------------------------------------------
// EOF
//-----------------------------------------------------------------------------