Questions tagged [luhn]

Luhn's Algorithm is a simple checksum formula used to generate the check digit in most credit card numbers.

The Luhn algorithm is well known with credit cards but is also used in various other applications like the IMEI for cell phones.

See: https://en.wikipedia.org/wiki/Luhn_algorithm

One of the exercises in the CS50 course (tag — also CS50 Stack Exchange) is implementing Luhn's Algorithm; the tag will often show up with the tag.

207 questions
2
votes
1 answer

My attempt at Luhn's algorithm (for credit card validity) seems to recognise some cards but not others

I've constructed some code to simulate Luhn's algorithm for checking the validity of credit cards. It successfully recognises American Express cards (15 digit numbers beginning in 34 or 37), but when I try Mastercard (16 digits, beginning with 51,…
BlueKhakis
  • 293
  • 1
  • 8
2
votes
1 answer

Generate Luhn Mod N using SQL

We are using CRYPT_GEN_RANDOM to generate a 15 character string (numeric plus uppercase = 36 options for each character), and would like to add the final character as a checksum using Luhn Mod N. I am looking for a way to do this using SQL. There…
user1480192
  • 665
  • 8
  • 23
2
votes
1 answer

Generate unique public user identifier with check digit

We store patient and care provider records in our database. We need some kind of public identifier for each user that uniquely identifies them, and with some kind of check digit to minimize the chance of wrong inputs. In my research I have found the…
L-Four
  • 13,345
  • 9
  • 65
  • 109
2
votes
1 answer

Unexpected performance with Luhn's Algorithm in (I)python

I've implemented two python versions of the checksum part of Luhn's algorithm. The code snippets are nearly identical except for how they calculate the second summation. It differs from the usual implementation, in that it computes the total sum,…
spyr03
  • 864
  • 1
  • 8
  • 27
2
votes
1 answer

Python: Luhn's algorithm / if statement never executes

I am trying to implement the Luhn's algorithm to check for credit card number validity. To do this every second digit needs to be multiplied by 2 and if the result is >9 it then is replaced by the sum of the digits. def…
2
votes
2 answers

IMEI not passing Luhn Checksum

I have the following code for validating IMEIs (not SV) public static boolean luhnc(char[] digits) { int sum = 0, s = 0; for (int i = 0; i < digits.length - 1; i += 2) { s = (digits[i+1] - '0') * 2; sum += (s > 10 ? s - 9 :…
TheRealChx101
  • 1,468
  • 21
  • 38
2
votes
1 answer

Why Luhn algorithm multiply by 2?

I have question about Luhn algorithm. The luhn algorithm (mod 10) for error detection and check sum digits. For example digits like visa, credit card etc. for example we have digits : Digits 1 2 3 4 5 6 7 8 9 3 Step 1: Multiply the value of…
2
votes
1 answer

Algorithm for one sign checksum

I am desperate in the search for an algorithm to create a checksum that is a maximum of two characters long and can recognize the confusion of characters in the input sequence. When testing different algorithms, such as Luhn, CRC24 or CRC32, the…
Patrick Vogt
  • 898
  • 2
  • 14
  • 33
2
votes
8 answers

Python Credit Card Validation

I'm a beginner Python learner and I'm currently working on Luhn Algorithm to check credit card validation. I wrote most of the code, but I'm stuck with 2 errors I get 1st one is num is referenced before assignment. 2nd one I'm getting is object of…
Apurva Patel
  • 71
  • 1
  • 1
  • 6
2
votes
1 answer

Not sure how to fix this error Luhn Algorithm PYTHON

Alright, So I think i'm almost there, my first/second part work perfect when they are on their own, but i'm having trouble combining the two this is what I have so far I'm thinking the error is in the last bit, sorry, im new with python, so i'm…
2
votes
2 answers

Prolog: implement Luhn algorithm with efficiency

I try to apply Luhn algorithm in SWI-Prolog. But I get some problem in running. When I test with some simple number like 123, it gives out result fast. If I test with longer number like 5379173895860200, it runs so long time that I can only abort…
G_cy
  • 994
  • 3
  • 13
  • 28
2
votes
4 answers

Credit card number validator doesn't work correctly

def checksum(card_without_check): card_without_check = card_without_check[-1::-1] def numbers(string): return [int(x) for x in string] print(card_without_check) odd_numbers = numbers(card_without_check[0::2]) even_numbers…
Joel Gallant
  • 315
  • 4
  • 21
2
votes
1 answer

Luhn algorithm Ruby not recognising AMEX

So I am Having some problems when applying Luhn algorithm Here are the general rules: http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-algorithm and here is my code def luhn(credit_card) result = 0 nums =…
Adrian Grzywaczewski
  • 868
  • 1
  • 12
  • 25
2
votes
2 answers

Validating card credit numbers

I've been trying to create a program that can check if a credit card number is valid or not based on Hans Peter Luhn's algorithm. However, I can only get it to work for some inputs. // Loop through every digit in the card number for ( int i = 0; i <…
user2849447
2
votes
2 answers

LUHN credit-card validation fails on a valid card number

In my application i want to check whether the user have entered valid card number for that i have used LUHN algorithm.I have created it as method and called in the mainactivity. But even if i give valid card number it shows invalid.While entering…
june
  • 999
  • 3
  • 14
  • 20
1 2
3
13 14