Quite often, when performing data transformation, some task will be required as part of the transformation process, that has traditionally been done outside of the tool being used to for mapping the transformation. In many cases, this is due to the transformation tool being used lacking the functionality to perform said task, but when using ITX, it is most often the result of the user not fully understanding the power of ITX, and how it can be used to meet the requirement.
One such example that comes to mind is the use of “Modulus 10” or the “Luhn Algorithm” as a checksum formula to validate identification numbers. Some examples of where the Luhn Algorithm is used for validation includes credit card numbers, IMEI numbers, National Provider Identifier numbers in the US, Canadian Social Insurance Numbers, Israel ID Numbers, and Greek Social Security Numbers(AMKA).
The Luhn algorithm, which is specified in ISO/IEC 7812-1, was designed to protect against accidental data entry errors, and is used to verify a number against its included check digit, which is usually appended to a portion of the number in question to generate the full number. A quick search of the internet will reveal several explanations of the Luhn Algorithm, along with code snippets of how to implement the check in JAVA, C, and other languages.
While many mapping tools would require that external code be written and accessed during its execution, that is not the case with ITX.
The Luhn Algorithm uses the following formula to test the validity of the number in question: To illustrate, let’s use 4168 as an example, where 8 is the check digit.
1. Beginning with the rightmost (check) digit, moving left, double the value of every second digit. If the result of doubling is a two-digit number, add the two digits together to form a single digit number. (6*2=12, 1+2=3)
3. If the result of step 2 ends in 0, or the Modulo 10 of the number is equal to 0, then the number is valid.
Now, let’s look at an implementation of the algorithm using ITX.
First, we need to define a data structure to represent the input number, as well as the result of applying the formula. This example shows an item called Digit, defined as a single byte integer, and a group defined as an unbounded group of Digit(s) called Num2Check.
Other objects defined in the type tree include:
While the functionality being implemented could easily be done using one output card, the example provided uses 3.
Card#1 DigitToDouble – Calculate the total number of digits in the number being checked. If the total number of digits is odd, then you know to double all the values of digits in even positions, if the total number of digits is even, then you know to double the values of digits in odd positions.
Card#2 Num2Check_Out – Call functional map CalcMod10, passing in 3 arguments.
Card#3 PassMod10 – Sums the digits that are the result of Card#2. If evenly divisible by 10 then the number passes validation, otherwise it fails validation. Create a text string to indicate if the number passed or failed validation.
Functional Map CalcMod10
1. Check to see if the digit should be doubled
a. If no, return the digit passed in
b. If yes, check to see if the result of multiplying by 2 yields a two-digit result.
i. If no, return the single digit result of multiplying by 2.
ii. If yes, subtract 9 from the 2 digit result.
1. Subtracting 9 from the 2 digit result yields the same value as adding each digit of the two-digit result.
So, the next time you contemplate exiting your ITX map to implement some functionality written in a third language, consider implementing that logic using ITX. You may even want to consider using an ITX map the next time you need to build a web service that is to be exposed to other processes in your organization. Think outside the box and take advantage of ITX and its capabilities.
Until next time, happy mapping.