Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

.hy3 checksum calculation

915 views
Skip to first unread message

Troy DeLano

unread,
Nov 29, 2010, 11:10:30 PM11/29/10
to SDIF Forum
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
//-----------------------------------------------------------------------------

Eddie Rowe

unread,
Mar 5, 2013, 12:17:28 PM3/5/13
to sdif-...@googlegroups.com
can you attach a sample, validating hy3 entries file that you were able to create?

Mike Walsh

unread,
Mar 8, 2013, 5:14:55 PM3/8/13
to sdif-...@googlegroups.com
Eddie -

You can download a zip file which contains a HY3 file and it's equivalent SD3 file which I generated using my WordPress plugin from this link:


Hopefully it will help you out.  Don't hesitate to ask any questions.

Mike

Eddie Rowe

unread,
Mar 13, 2013, 11:30:05 AM3/13/13
to sdif-...@googlegroups.com
Thanks, Mike this is great! 

     Is there an accompanying record layout available?  I see several record types, but I'm not sure what all of them are.  Is there something that says what fields go in what columns?

Thanks,
Eddie

Mike Walsh

unread,
Mar 13, 2013, 11:39:05 AM3/13/13
to sdif-...@googlegroups.com

Here is a collection of some things I’ve done and/or gathered up from other people.  Troy Delano (on this list) did a lot of the work to document the file formats.  I added some of the relay information to what he did last summer.

 

https://www.dropbox.com/s/jw5ivrm2o667hco/Hy-Tek_Docs.zip

 

Mike

--
You received this message because you are subscribed to the Google Groups "SDIF Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sdif-forum+...@googlegroups.com.
To post to this group, send email to sdif-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sdif-forum?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eddie Rowe

unread,
Dec 17, 2014, 10:41:01 AM12/17/14
to sdif-...@googlegroups.com
Here's a function in PERL for those who prefer that language:

sub get_checksum {
    
    my @chars = split // , shift;
    my @ord_chars = map { ord } @chars;  # get a number for each letter
    
    my @odd = ();
    my @even = ();
    
    # odd and even characters are handled differently.
    foreach my $i (0..$#chars) {
        if ( $i%2 ) {
            push @odd, $ord_chars[$i];
        } else {
            push @even, $ord_chars[$i];
        }
    }
    
    my $odd_sum = 0;
    my $even_sum = 0;
    
    # odd characters have their numeric representation doubled
    $odd_sum += 2*$_ for @odd;
    $even_sum += $_ for @even;
    
    # the checksum formula is below:
    # 1) Take the integer part of division by 21 of the sum of the characters (2*odd + even)
    # 2) Add 205
    # 3) The first digit of the checksum is the last digit of the previous result
    # 4) The second digit of the checksum is the penultimate digit of the same
    my $sum = $odd_sum + $even_sum;
    my $result = ($sum - $sum%21) / 21;
    my $sum2 = $result + 205;
    my $checksum1 = substr($sum2,-1);
    my $checksum2 = substr($sum2,-2,1);
    my $checksum = "$checksum1$checksum2";
    return $checksum;
}
Reply all
Reply to author
Forward
0 new messages