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
5
votes
8 answers

How do I implement the Luhn algorithm?

I am trying to create a program to validate 10 to 12 digit long number sequences based on the luhn algorithm, but my program keeps on telling me that every number is invalid even though they're not. This number should be valid, but my code doesn't…
Pontus
  • 53
  • 1
  • 1
  • 3
5
votes
3 answers

Generate IMEI in python

Hello I am trying to make a function in python to generate valid IMEI numbers so here is my function.The IMEI validation uses the Luhn algorithm so I am trying to implement it in my script. def getImei(): num = '' suma = 0 for i in…
opc0de
  • 11,557
  • 14
  • 94
  • 187
4
votes
2 answers

JavaScript card PAN check digit Luhn verification

I've used the code from the link below to try and validate a credit card, however I'm not getting an alert when I submit a the wrong data in the field. Strip spaces before performing Luhn check my form is as follows:
Ghatzi
  • 567
  • 2
  • 12
  • 24
4
votes
2 answers

Luhns Algorithm

Hey I am doing Luhn's algorithm for an assignment for school. A few outputs are coming out the correct way; however, some are not. 0004222222222222 is giving me a total of 44, and 0378282246310005 is giving me a total of 48, for a few examples. I…
Brian Upward
  • 59
  • 1
  • 8
3
votes
3 answers

How to add product digits rather than products themselves in C?

I am trying to finish an assignment in C for the CS50 course in which I must implement Luhn's algorithm to validate a credit card number. Here is a quick example to elaborate: credit card number: 4003600000000014. Now for every other digit,…
Bryce
  • 71
  • 8
3
votes
1 answer

Made a script on the Luhn's Alg. Unable to understand how to create and call functions clearly for revised script

I am new to programming. I am currently taking online lectures quite rigorously and completed a task using Luhn's Algorithm. It is just one script that runs straight through, but for my future-self I want to learn to code more efficiently as…
schu97
  • 31
  • 4
3
votes
1 answer

Can't find the digit check algorithm

I can´t find which algorithm is being used to to calculate the 2 digits check digit of my bank references. Some examples 0404 3295 60983 0707 3328 25810 0900 9907 32991 0900 8912 91695 0707 2268 89938 0808 1153 45010 0808 0964 91963 0900 6632…
Fraga
  • 1,361
  • 2
  • 15
  • 47
3
votes
2 answers

Luhn function in Haskell

I'm currently working through the book Programming in Haskell (which is absolutely amazing so far), but ran into a problem in exercise 4.8.8. The task is to implement the Luhn algorithm in Haskell, using a help function luhnDouble :: Int -> Int…
TheCoolFrood
  • 367
  • 2
  • 15
3
votes
4 answers

Are there any valid credit numbers that are initial substrings of other valid credit card numbers?

I'm trying to implement recognition of a valid credit card number so that I can transition to the next field. Given that credit card numbers come in various lengths, my question is whether I can count on the fact that if I confirm a valid credit…
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
3
votes
2 answers

How to calculate check digits for a Hexadecimal IMEI (Number+Character) using luhn's algorithm?

I want to understand the logic so that I can implement this algorithm in java. I want to calculate check digit for a valid hexadecimal IMEI number. For example - 6C4BFFC0000004 Please help me with the algorithm. I tried to find solution in google…
SUNNY
  • 125
  • 1
  • 3
  • 13
3
votes
2 answers

Credit Card Number validity with Luhn's Algorithm (Java)

I'm working on a school assignment that checks whether a credit card number that is entered is valid or not, using Luhn's Algorithm. In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to…
NEPat10
  • 159
  • 1
  • 2
  • 12
3
votes
4 answers

How should I approach a credit card number validation algorithm?

I'm writing a program to validate credit card numbers and I have to use Luhn's Algorithm. Let me say beforehand, that I have just started to learn to program (we covered loops like last week), so there a lot of things I am unfamiliar with. I am…
Alti
  • 189
  • 1
  • 9
2
votes
3 answers

C: Credit Card Number checker/ Luhn's algorithm

Everything looks fine and seems to follow Luhn's algorithm, but when i enter my own credit card number or this sample number that should be valid: 4388576018410707 , it still comes back as invalid... Can anyone find the problem? #include…
user1145538
  • 641
  • 2
  • 9
  • 14
2
votes
2 answers

Validating Israeli ID number

I'm looking for a clean and efficient way to validate an Israeli ID number. It's basically an implementation of the Luhn algorithm on a 9 digits number. Note: This question is here for the community because it wasn't on stack overflow yet. You can…
Milana
  • 557
  • 9
  • 20
2
votes
2 answers

Is there a way to detect the type of card i.e Debit or Credit

I need to detect the card type: Debit or Credit when the customer is on website's checkout page. I am using the library i.e https://github.com/braintree/credit-card-type already to determine the card brand i.e Visa,Amex,Mastercard etc. But these…
jaison619
  • 31
  • 1
  • 3
1
2
3
13 14