A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a...

download A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a 2-Digit Modulo 11 Error Correction Scheme_by_Luwa Matthews

of 4

Transcript of A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a...

  • 8/3/2019 A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a 2-Digit Modulo 11 Error Correction Scheme_by_Luwa

    1/4

  • 8/3/2019 A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a 2-Digit Modulo 11 Error Correction Scheme_by_Luwa

    2/4

    Below is the URL for 2 Sage functions I wrote. The 1 st function generates final 2 check digits for any 8-digit number and the other function detects and corrects any single-digit error, thus providing acomplete implementation of this error detection and correction scheme.

    http://sage.luther.edu:8443/home/pub/110

    The first function AppendCheckDigit(num) takes an 8-digit number num and prints a new numberwith the corresponding 2 check digits appended to the original number. The second functionErrorCheck_Correct(num) will take in a 10-digit number num, (the last 2 digits are the correctiondigits, of course) and will indicate whether or not that number has an error. If it does, it will print out thecorrected number. Below are several examples, starting with the example given in the article.

    On page 13 of the article, Gallian asks the user to consider the number 73245018. He points out that a9(digit 9) and a10 (digit 10) must satisfy 8+a9+a10=0 (mod 11), from the 1 st dot product. For the 2 nd dotproduct, 10+9a9+10a10=0(mod 11). This gives a9=7 and a10=7.

    Running this on my Sage function:

    AppendCheckDigits(73245018)

    Output:Full Digit is: 7324501877

    We get the same last 2 digits!

    Next, Gallian changes the 2 nd digit from 3 to 8, giving the digit 7324501877. The 1 st dot product,(7,3,2,4,5,0,1,8,7,7).(1,1,,1,1) gives 5. This means there is 1 digit that is magnitude of 5 mod 11 toolarge, assuming there is only 1 defective digit. Doing the 2 nd dot product, (7,3,2,4,5,0,1,8,7,7).(1,2,,10)gives 10=ErrorMagnitude*i, where i is the position of the error. Hence, here the error is at digit 2.

    Running my Sage function:

    ErrorCheck_Correct( 78245018 )

    Output:Number Entered: 7824501877Error in Digit 2It is 5 mod 11 too large.Correct Number is: 7324501877

    My Sage function prints out the original number, thus correcting the number that was entered! Now,Let s do this for a few more examples.

    Let s first generate the last 2 check digits for, say 24290854.

    AppendCheckDigits(24290854)

    Output:

  • 8/3/2019 A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a 2-Digit Modulo 11 Error Correction Scheme_by_Luwa

    3/4

    Full Digit is: 2429085437Now, let us change the 4 th digit from 9 to 3. This gives 2423085437.

    Let us now check for an error.

    ErrorCheck_Correct(2423085437)

    Output:Number Entered: 2423085437Error in Digit 4It is 5 mod 11 too large.Correct Number is: 2429085437

    F inally, let us check 47589309.Full Digit is: 4758930937

    Let us change the 7 th digit from 0 to 7.That gives 4758937937.

    Let us then check for errors using the Sage code.

    ErrorCheck_Correct( 4758937937 )

    Output:Number Entered: 4758936937Error in Digit 7It is 6 mod 11 too large.Correct Number is: 4758930937

    The code was tested with several more examples and seems to be reliable. Overall, I wish to expressappreciation for the brilliance of these error-detection and correction schemes. It has been fascinating notonly to work with this 2-digit modulo 11 error detection scheme, but to actually fully implement it. Withthe Sage code, any 8-digit number can be given 2 check digits, with which error correction can be carriedout.

  • 8/3/2019 A Sage-Based Implementation of Check-Digit Generation, Error Detection and Error Correction Using a 2-Digit Modulo 11 Error Correction Scheme_by_Luwa

    4/4

    # The 2 functions below Implement the Error Correction Scheme outlined on page 13 of the article#" Error Detection Methods " by Joseph A. Gallian.#F ree download: http://www.d.umn.edu/~jgallian/detection.pdf

    # This will append 2 final check digits to any 8-digit number.def AppendCheckDigits(num):

    num=str(num)F irstMod=0for index in range(len(num)):

    F irstMod+=int(num[index])F irstMod= F irstMod%11

    SecondMod=0for index in range(len(num)):

    SecondMod+=int(num[index])*(index+1)SecondMod=SecondMod%11

    a9=(-10* F irstMod+SecondMod)%11a10=(9* F irstMod-SecondMod)%11

    print( "F ull Digit is: "+num+str(a9)+str(a10))

    # This will indicate whether or not there is an error. If there is one, it will print out the correct number.def ErrorCheck_Correct(num):

    num=str(num)F irstMod=0for index in range(len(num)):

    F irstMod+=int(num[index])F irstMod= F irstMod%11

    SecondMod=0for index in range(len(num)):

    SecondMod+=int(num[index])*(index+1)SecondMod=SecondMod%11

    print( "N umber Entered: "+num)if F irstMod==0 and SecondMod==0:

    print( "N o Error " )

    else:ErrorMag= F irstModErrorPosition=0for i in range(1,9):

    ErrorPosition=iif (ErrorMag*ErrorPosition)%11==SecondMod:

    print( " Error in Digit " +str(ErrorPosition)+ "\ n" +"It is "+str(ErrorMag)+ " mod 11 too large. ") break

    correct N um= ""

    for index in range(len(num)):if index+1==ErrorPosition:

    correct N um+=str((int(num[index])-ErrorMag)%11)else:

    correct N um+=num[index] print( " Correct N umber is: "+correct N um)