The stupid question is the question not asked PerlMonks

### Re^8: Faster Luhn Check Digit Calculation? (Ignore this!)

by BrowserUk (Patriarch)
 on Dec 02, 2018 at 15:09 UTC ( #1226623=note: print w/replies, xml ) Need Help??

in reply to Re^7: Faster Luhn Check Digit Calculation?
in thread Faster Luhn Check Digit Calculation?

Update:Ignore this! It doesn't stand up to syphilis's scrutiny. (It only works for the OPs limited test range by luck!)

Looks fat to me ( just kidding :)

If its skinny you want, try this for (its lack of) size :)

Correct results and 35% faster to boot:

```int lookup[] = { 8, 6, 4, 2, 0, 7, 5, 3, 1, 9, 7, 5, 3, 1, 9, 6, 4, 2,
+ 0 };
int c_fluhn( int n ) {
return lookup[ n % 20 ];
}

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^9: Faster Luhn Check Digit Calculation?
by kschwab (Vicar) on Dec 02, 2018 at 21:55 UTC
Very nice. Unfortunately, Algorithm::LUHN supports some odd inputs, like non-numeric strings (See their docs).
Algorithm::LUHN supports some odd inputs

That module may attempt to extend the purpose and use of the algorithm to inputs for which it was never designed; but in doing so, it invalidates itself and the algorithm.

Ie. The purpose of the algorithm is to catch 2 digit transposition errors in numeric identifiers; trying to extend that mathematics to non-numerics invalidates that purpose.

Eg. The use of Mod 9, on alpha data that has a 26 character alphabet means that some (34% of) combinations of 2-digits transpositions will not be detected.

Rules to live by:Don't perpetuate other people's bullshit.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
The module docs read like Standard & Poor's decided to do that, not the original module author, but I digress.
> Unfortunately, Algorithm::LUHN supports some odd inputs, like non-numeric strings

Careful, is this algorithm well defined for input >=10 !?!

From the docs:

> For example, Standard & Poor's maps A..Z to 10..35 so the LIST to add these valid characters would be (A, 10, B, 11, C, 12, ...)

provided B=11 is on an odd position, what's the formula now to reduce 2*11?

cross total is 4, but 22-9 =13

and if it's even does 11 stay 11 with cross total 2 or do you take it module 10 hence resulting in 1?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Just replicating the original module, including a fairly straight port to C that's passing the original module's tests...

Maybe I'll make a separate module that "does the right thing", but isn't compatible with Algorithm::LUHN.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226623]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-01-28 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2022, my preferred method to securely store passwords is:

Results (73 votes). Check out past polls.

Notices?