Skip to content

Instantly share code, notes, and snippets.

@wurin7i
Last active March 1, 2020 15:44

Revisions

  1. wurin7i revised this gist Aug 18, 2015. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions taq.js
    Original 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'));
  2. wurin7i revised this gist May 27, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions damm_check_digit.php
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,11 @@
    */
    if (! function_exists('taq'))
    {
    function taq($digits)
    function taq($digits)
    {
    $taq_table = array(
    '0317598642', '7092154863', '4206871359', '1750983426', '6123045978',
    '3674209581', '5869720134', '8945362017', '9438617205', '2581436790');
    '3674209581', '5869720134', '8945362017', '9438617205', '2581436790');
    $interim = 0;

    foreach (str_split($digits) as $digit) {
  3. wurin7i created this gist May 27, 2013.
    44 changes: 44 additions & 0 deletions damm_check_digit.php
    Original 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;
    }
    }