Check Digits What? Division Schemes Weighted Schemes Examples Spring 2015 Mathematics in Management Science Check Digits An additional digit attached to number for purposes of error & fraud detection and correction when copying or transmitting the number. Mathematical calculations (schemes) used on the digits of the original number to compute the check digit. Check Digits Check digit is calculated from the rest of the number and transmitted along with the number. When an error occurs, a recalculation of the check digit (usually) won’t match. When the recalculated value doesn’t match the supplied check digit, an error has occurred. Check Digits Start with pre-id number. Use this to calculate check digit. Get id number. Check digit is extra digit appended to pre-id number for purposes of detecting/correcting errors (or fraud) when the complete id number is copied or transmitted. Check Digits Examples Calculation of a check digit typically uses modular arithmetic. You are not expected to memorize rules in all the examples. You are expected to be able to calculate a check digit given a description of the procedure. USPS Money Order U.S. Postal Service money order with id number 6302438384, check digit 5. The check digit in this case is the calculated remainder after dividing the sum of the first ten digits by 9. USPS Money Order Length of ID: 10 + check digit a1a2a3a4a5a6a7a8a9a10 c Calculating check digit: c = a1a2a3a4a5a6a7a8a9a10 mod 9 = (a1+a2+a3+a4+a5+a6+a7+a8+a9+a10 ) mod 9 Errors detected/not detected: Single digit errors except replacing 0 with 9 or vice versa. Won’t detect transpositions. Example Find check digit for money order id 2755943610c. c = (2+7+5+5+9+4+3+6+1+0) mod 9 = 42 mod 9 =6 So, complete id number is 27559436106. Example Find check digit for money order id 5602419260c. c = (5+6+0+2+4+1+9+2+6+0) mod 9 = 35 mod 9 =8 So, complete id number is 5602419268. American Express Cheques Another division by 9 scheme. Id no has form a1a2a3a4a5a6a7a8a9 c ; The check digit c is chosen so that a1 +a2+a3+a4+a5+a6+a7+a8+a9 +c is evenly divisible by 9. Same error detection as USPS money orders. Example Find check digit for AmEx check: 603780104c. Need (6+0 +3+7+8+0+1+0+4) mod 9+c = 29 mod 9+c = 2+c to equal either 0 or 9. So, c = 7 and complete ID is 6037801047. Direct vs Indirect Methods USPS money order check digit is computed via direct calculation: c is remainder after division by 9. AmExpress cheques check digit is computed via indirect calculation: c is chosen so that sum is evenly divisible by 9. Direct methods easier to compute, but harder to verify. Indirect methods harder to compute, but easier to verify. Detecting Errors Direct Method: Recalculate check digit and compare it to one supplied. Indirect Method: Use supplied check digit and see if it satisfies condition. Other Schemes Can be “direct” or “indirect”. Can use division by 7 or 10 or 11 or 13. Can introduce “weights”: UPC, BIN, ISBN, codabar Do not need to memorize all these! But, shud be able to calculate a check digit given description of scheme. Indirect Div by 10 Example This a division by 10 scheme. 11 digits + check digit Check digit c chosen so that sum of all digits is divisible by 10. Id no of form a1a2a3a4a5a6a7a8a9a10 c Check digit c is chosen so that a1 +a2+a3+a4+a5+a6+a7+a8+a9 +a10+c is divisible by 10. Universal Product Code A bar code and identification number that is used on most retail items. By using a weighted scheme in the calculation of the check digit, the UPC number achieves greater error detection—up to 100% of all single-digit errors and most other types of errors. Example Consider the number 0 38000 00127 7 found on bottom of box of cornflakes. First digit identifies broad category of goods. Next five digits identify manufacturer. Next five digits identify product. The last is a check digit. Universal Product Codes This is a weighted div by 10 scheme. Pre-id no: a1a2a3a4a5a6a7a8a9a10a11 Id no: pre-id no + check digit Check digit c chosen so that weighted sum 3a1+a2+3a3+a4+3a5+a6+3a7+a8+3a9+a10+3a11+c is divisible by 10. Weights are 3,1 (repeated over & over). Example Look at UPC no 0 38000 00127 7. Weights are 3 13131 31313 1. Weighted sum of all these is 0+3+3*8+3*1+2+3*7+ 7=27+5+28=60 Which is divisible by 10. Example Find check digits for the UPC pre-id number 0 31200 00678. Weights are 3 13131 31313 1. Weighted sum of all these is 0+3+3+2+3*6+7+3*8+c=57+c. Want this to be divisible by 10. So, c=3. Then UPC id no is 0 31200 00678 3. Example Find check digits for the UPC pre-id number 0 74101 75074. Weights are 3 13131 31313 1. Weighted sum of all these is 7+3*4+1+1+3*7+5+7+3*4+c=66+c. Want this to be divisible by 10. So, c=4. Then UPC id no is 0 74101 75074 4. Example Is 0 38000 00097 2 a valid UPC no? 3 13131 31313 1 (weights). Weighted sum of all these is 3+3*8+9+3*7+2 = 59. Since this is not divisible by 10, above number is not a valid UPC number. Correcting Errors Suppose get a UPC number 0-46000-x2121-6 where the 7th digit x could not be read. So, this is, of course, an error. Can we fix this? Can we determine what digit the x should be? Yes, since it’s just one digit. Have a wanna be UPC number 0-46000-x2121-6. Need x to have prop that wtd sum is divisible by 10: 0 46 000 x21 21 6 3 13 131 313 13 1 Sum is 4+3*6+3x+2+3+2+3+6=38+3x. This div by 10 iff 8+3x is div by 10. Want x st 8+3x is divisible by 10. Solving 3x+8=0 mod 10 A number N is divisible by 10 iff N mod 10 = 0, or, N ≡ 0 mod 10 . Two numbers M and N satisfy M≡N mod 10 iff M-N is divisible by 10. So, 1≡11 mod 10, 2≡-8 mod 10, etc. We want 3x ≡ -8 mod 10, but -8 ≡ 2 ≡ 12 mod 10, so want 3x ≡ 12 mod 10; get x=4 . Solving 3x+8=0 mod 10 Another (better?) approach: We want 3x ≡ -8 ≡ 2 mod 10. Notice that 3 • 7 = 21 ≡ 1 mod 10. So, doing mod 10 arithmetic, we multiply both sides of 3x = 2 by 7 to get x ≡ 7 • 3x ≡ 7 • 2 ≡ 4 mod 10. Again we find that x=4 . Modular Arithmetic The set of integers “mod p” are 0, 1, 2, 3, …, p-1 . Just all remainders after division by p. When p=5 get 0, 1, 2, 3, 4. We add these by computing “mod p”. When p=5, 3+4 ≡ 2 mod 5. Do something similar for multiplication. Modular Multiplication The integers mod 5: 0, 1, 2, 3, 4 . All possible remainders after div by 5. Multiplication Table. X 1 2 3 4 1 1 2 3 4 2 2 4 1 3 3 3 1 4 2 4 4 3 2 1