these two algorithms are used to check for valid member numbers, the first one that I gave to the company, the second one that I developed, from my tests I see no difference between them functionally,
Are there any cases where someone can see where they will return different outputs?
test input:
6014355021355010
or
6014355065446212
or
6014351000254605
The check digit is calculated using the first 15 digits as follows:
- Sum the numbers in even positions from left to right
- Multiply each digit in odd numbered positions (left to right) by 2. If any results are 2 digits, sum the digits into one. Summarize the numbers from each multiplication by the final result.
- Add the final results of steps 1 and 2.
- Take the last digit of the result from step 3 and subtract from 10 into enter the check digit.
- Take the last digit from the 16 digits and compare with the check digit
- if they are equal, it really is
against
The check digit is calculated using all 16 digits as follows:
- Sum the numbers in even positions from left to right
- Multiply each digit in odd numbered positions (left to right) by 2. If any results are 2 digits, sum the digits into one. Summarize the numbers from each multiplication by the final result.
- Add the final results of steps 1 and 2.
- Accept the final result and module 10
- If the result is 0, it is valid
Update:So. I tried to create both of these algorithms in php, the second one, I created it successfully, the first one, however, I seem to be unable to work., , :
16- 10
15 :
1.
2. ( ) 2
- 2 , . .
3. 1 2.
4. 3 10, .
3 10, .
Example 6014 3590 0000 0928
1.0 0 + 4 + 5 + 0 + 0 + 0 + 9 = 18
2.0 6 * 2 = 12 so 1 + 2 = 3
2.1 1 * 2 = 2
2.2 3 * 2 = 6
2.3 9 * 2 = 18 , therefore 1 + 8 = 9
2.4 0 * 2 = 0
2.5 0 * 2 = 0
2.6 0 * 2 = 0
2.7 2 * 2 = 4
2.8 3 + 2 + 6 + 9 + 0 + 0 + 0 + 4 = 24
3.0 18 + 24 = 42
4.0 The check digit is 10 - 2 = 8
5.0 8 = the 16th digit (601435900000092 [8])
Update2:ok, so I fixed the algorithm,, ,
( != 16)
return 1;
( 5 != 601435)
return 1;
?
,
Matt
test [php]<?php
$file = file_get_contents('fb.csv');
$numbers = explode("\n", $file);
function validate_flybuys($number) {
$r = array ('o' => '0', 'i' => '1', 'l' => '1', 'e' => '3', ' ' => '');
$flybuys = trim(strtolower($number));
$flybuys = str_replace(array_keys($r), $r, $flybuys);
if('601435' != substr($flybuys, 0, 6) || strlen($flybuys) != 16)
return 1;
$evens = 0;
$odds = '';
for($i = 0; $i <= 15; $i+=2) {
$odds .= $flybuys[$i];
$evens += $flybuys[$i+1];
}
$odds = str_split($odds);
foreach($odds as &$odd) {
$odd = $odd*2;
if($odd >= 10) {
$odd = str_split($odd);
$odd = $odd[0] + $odd[1];
}
}
return (array_sum($odds)+$evens) % 10;
}
function validate_flybuys2($number) {
$r = array ('o' => '0', 'i' => '1', 'l' => '1', 'e' => '3', ' ' => '');
$flybuys = trim(strtolower($number));
$flybuys = str_replace(array_keys($r), $r, $flybuys);
if('601435' != substr($flybuys, 0, 6) || strlen($flybuys) != 16)
return 1;
$evens = 0;
$odds = '';
for($i = 0; $i <= 14; $i+=2) {
$odds .= $flybuys[$i];
if($i != 14)
$evens += $flybuys[$i+1];
}
$odds = str_split($odds);
foreach($odds as &$odd) {
$odd = $odd*2;
if($odd >= 10) {
$odd = str_split($odd);
$odd = $odd[0] + $odd[1];
}
}
$total = (array_sum($odds))+$evens;
$total = str_split($total);
$check = 10 - $total[1];
$check = $check % 10;
if($check == substr($flybuys, 15, 1))
return 0;
else
return $check;
}
foreach($numbers as $number) {
$valid = validate_flybuys($number);
$valid2 = validate_flybuys2($number);
if($valid != $valid2 || $valid != 0) {
echo '<hr />';
echo 'NUMBER: '.$number.'<br />';
echo 'V1: '.$valid.'<br />';
echo 'V2: '.$valid2.'<br />';
}
}
- , :)
oh 8D