Last active
March 1, 2020 15:44
Revisions
-
wurin7i revised this gist
Aug 18, 2015 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ function taq(digits) { var taqTable = ['0317598642', '7092154863', '4206871359', '1750983426', '6123045978', '3674209581', '5869720134', '8945362017', '9438617205', '2581436790']; var interim = 0; var chars = digits.split(''); var index, len; for (index = 0, len = chars.length; index < len; ++index) { var digit = parseInt(chars[index]); var taqRow = taqTable[interim]; var strInterim = taqRow.substr(digit, 1); interim = parseInt(strInterim); } return interim; } console.log(taq('8436714657207786')); -
wurin7i revised this gist
May 27, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,11 +8,11 @@ */ if (! function_exists('taq')) { function taq($digits) { $taq_table = array( '0317598642', '7092154863', '4206871359', '1750983426', '6123045978', '3674209581', '5869720134', '8945362017', '9438617205', '2581436790'); $interim = 0; foreach (str_split($digits) as $digit) { -
wurin7i created this gist
May 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ <?php /** * The Damm check digit * For more information cf. http://en.wikipedia.org/wiki/Damm_algorithm * totally anti-symmetric quasigroup * * @author Wuri Nugrahadi <[email protected]> */ if (! function_exists('taq')) { function taq($digits) { $taq_table = array( '0317598642', '7092154863', '4206871359', '1750983426', '6123045978', '3674209581', '5869720134', '8945362017', '9438617205', '2581436790'); $interim = 0; foreach (str_split($digits) as $digit) { if (! preg_match('~\d~', $digit)) { return FALSE; } $interim = substr($taq_table[$interim], $digit, 1); } return $interim; } } if (! function_exists('calc_check_digit')) { function calc_check_digit($digits) { return $digits.taq($digits); } } if (! function_exists('is_check_digit_valid')) { function is_check_digit_valid($digits) { return taq($digits) == 0; } }