Retired

Checksum error detection with the Damm algorithm (retired)

5 of 11Nekose

Description:

The Damm algorithm can be used as a form of check-sum error detection. It can detect single-digit and even adjacent transposition errors.

The algorithm relies upon a special latin square look-up table, which happens to be "weakly totally anti-symmetric". If none of that made sense to you, dont worry, because the look-up table will be provided as a list of list.

For reference, here is the table in plain-text:

0 1 2 3 4 5 6 7 8 9
0 0 3 1 7 5 9 8 6 4 2
1 7 0 9 2 1 5 4 8 6 3
2 4 2 0 6 8 7 1 3 5 9
3 1 7 5 0 9 8 3 4 2 6
4 6 1 2 3 0 4 5 9 7 8
5 3 6 7 4 2 0 9 5 8 1
6 5 8 6 9 7 2 0 1 3 4
7 8 9 4 5 3 6 2 0 1 7
8 9 4 3 8 6 1 7 2 0 5
9 2 5 8 1 4 3 6 7 9 0

By navigating the table, a final check digit will be generated. With that check digit appended to the end of the original sequence, re-navigating the table will always result in a final digit of 0. In the event of an error, the final digit will be something other than 0.

Steps to navigate the Damm algorithm:

  • Start with an interim digit of 0
  • Using the interim digit as the row, and the digit to be processed as the column, the result is the digit in the table.
  • Use the results as the next interim digit, and proceed to the next digit in the sequence.

Once finished navigating the table, the final digit will be the check digit, and should be appended to the end of the sequence.

To check if we've received a valid sequence, we repeat the process including the check digit at the end. If the new final digit is a 0, the sequence was valid.

Further details, along with some helpful diagrams, can be found on the wikipedia page.


In this kata, you must create two functions, "damm_append_check_digit", and "damm_check_result".

damm_append_check_digit will receive a string, and return the same string with the final damm algorithm check digit appended to the end.

damm_check_result will recieve a string and return True if the damm algorithm determines it is valid, or False if there is an error in the sequence.

"sequence" will always be a valid intereger.

The lookup table is provided as a list of lists under "damm_lookup_table".

Algorithms

More By Author:

Check out these other kata created by Nekose

Stats:

CreatedOct 4, 2024
Warriors Trained15
Total Skips0
Total Code Submissions34
Total Times Completed11
Python Completions5
Total Stars0
% of votes with a positive feedback rating25% of 8
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes5
Total Rank Assessments7
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Nekose Avatar
Ad