The LuhnModNIdentifierValidator.java class contains the code that computes a check digit using "baseCharacters" as the set of possible characters for the identifier or check digit. In fact, the Mod25 algorithm omits both numbers and letters that look similar and can be confused with each other (0, 1, 2, 5, 8, B, I, O, Q, S, and Z) the Mod30 algorithm omits only the potentially confusing letters. Typically, letters than can easily be confused with numbers (B, I, O, Q, S, and Z) are omitted. These algorithms not only allow letters and numbers to be used throughout the identifier, but also allow the check "digit" to be a letter. The idgen module supports additional algorithms, including Mod25 and Mod30 algorithms. The Luhn CheckDigit Validator uses this variation to allow for letters, whereas the Luhn Mod-10 Check-Digit Validator uses the standard Luhn Algorithm using only numbers 0-9. To keep life simple, we convert identifiers to uppercase and remove any spaces before applying the algorithm. The letters "A" through "Z" are values 65 to 90 in the ASCII table (and become values 17 to 42 in our algorithm after subtracting 48). Subtracting 48 lets the characters "0" to "9" assume the values 0 to 9 we'd expect. We subtract 48 because the characters "0" through "9" are assigned values 48 to 57 in the ASCII table. To handle alphanumeric digits (numbers and letters), we actually use the ASCII value (the computer's internal code) for each character and subtract 48 to derive the "digit" used in the Luhn algorithm. Adding a 2-3 letter suffix to the identifer was our solution. In our case (Regenstrief with the AMPATH Medical Record System), we were forced to come up with a simple method for generating identifiers in disparate, disconnected location without collision (giving out the same number twice). In fact, the potential for mistaking numbers and letters likely increases the chance for errors. ![]() This allows for an identifier like "139MT" that the original Luhn algorithm cannot handle (it's limited to numeric digits only).Īllowing letters- even limited to capital letters-does not increase the accuracy of data entry. In this variation, we allow for letters as well as numbers in the identifier (i.e., alphanumeric identifiers). We have borrowed the variation on the Luhn algorithm used by Regenstrief Institute, Inc. Our variation on the Luhn algorithm Allowing for Letters For a sum of '14', the check digit is '6' since '20' is the next number divisible by ten. So the answer is '1 + 8 + 3 + 2 = 14' and the check digit is the amount needed to reach a number divisible by ten. Now sum all of the digits (note '18' is two digits, '1' and '8'). ![]() If doubling the digit results in a two-digit number, then we need to do an extra step to get back down to a single digit – we're going to add those digits together to produce a single-digit number, so for 16, this would be 1+6=7.Work right-to-left, using "139" and doubling every other digit. Lastly, we double the fourth digit, 8, to get 16.After that, the third digit, 6, for which there is no change. ![]() Next, we double the second digit, 4, to get 8.So for 2 (the first digit from the right), there is no change.Starting with the rightmost digit, we're going to double every second digit: Let's see how this works for a short example of 4 digits (instead of the usual 16 digits) – let's check whether the number 8642 would be a valid card number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |