The Luhn Mod-10 Method (ISO 2894/ANSI 4.13) involves a check digit in the one's position. The check digit is calculated starting at the right with the digit immediately preceding the check digit (ten's digit) and moving toward the left, doubling every other digit. If a doubled digit is greater than nine, the two digits are added to together to obtain a single-digit result. The sum of all the resulting digits (including those skipped) is then taken modulo with 10, to obtain the check digit. Below, is untested code. /************************************************************************ * LuhnMod10 - self-checking scheme for validating card account numbers * according to ISO 2894/ANSI 4.13. * * Ex: cardNumber = "795102879015546" * strlen(cardNumber) == 15 * LuhnMod10(cardNumber, 14) == 6 == cardNumber[14] * ************************************************************************/ int LuhnMod10(char* cardNumber, int size) { static int table[2][10] = { {0,1,2,3,4,5,6,7,8,9}, {0,2,4,6,8,1,3,5,7,9} }; for (int i=size-1, odd=0, sum=0; i>=0; i--) if (isdigit(cardNumber[i])) sum += table[(odd=1-odd)][cardNumber[i]-'0']; sum %= 10; return (sum ? 10-sum : 0); /* return the check digit */ }