diff --git a/library/Metier/Util/Luhn.php b/library/Metier/Util/Luhn.php new file mode 100644 index 00000000..e9e57dba --- /dev/null +++ b/library/Metier/Util/Luhn.php @@ -0,0 +1,49 @@ +=0;--$i) { + $sum += $this->sumTable[$flip++ & 0x1][$number[$i]]; + } + // Multiply by 9 + $sum *= 9; + // Last digit of sum is check digit + return (int)substr($sum,-1,1); + } + + /** + * Validate number against check digit + * + * @param string $number + * @param integer $digit + * @return boolean + */ + public function validate(string $number, int $digit) + { + $calculated = $this->calculate($number); + if($digit == $calculated) { + return true; + } + else { + return false; + } + } +} \ No newline at end of file