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
26
votes
4 answers

Identify card type from card number

i have an array of card types that looks something like this var cards = new Array(); cards [0] = {name: "VISA", length: "13,16", prefixes: "4", checkdigit: true}; cards [1] = {name: "VISA_DELTA/ELECTRON", length: "16", prefixes:…
Ghatzi
  • 567
  • 2
  • 12
  • 24
17
votes
8 answers

Generating Luhn Checksums

There are lots of implementations for validating Luhn checksums but very few for generating them. I've come across this one however in my tests it has revealed to be buggy and I don't understand the logic behind the delta variable. I've made this…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
16
votes
14 answers

Implementation of Luhn algorithm

I am trying to implement simple validation of credit card numbers. I read about the Luhn algorithm on Wikipedia: Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit. Sum the digits of the…
Mithril
  • 12,947
  • 18
  • 102
  • 153
12
votes
11 answers

Implementing Luhn algorithm using C#

I am using following code to implement Luhn algorithm for credit card check in C# language, but could not get the output to generate the check sum its showing validity. Kindly help me. Thank you in advance. public class Program { private static…
user3181351
  • 147
  • 1
  • 1
  • 9
12
votes
1 answer

Identify if a "Credit card" or "Debit card" by the card number

I can initially do a check to identify if I have a valid Payment Card Number by performing Luhn check algorithm. But then I need to identify if it is a Credit card or a Debit card to perform the next task accordingly. I understand this depends on…
JibW
  • 4,538
  • 17
  • 66
  • 101
11
votes
6 answers

Client-side validation of credit cards

Does anyone have a library or JavaScript snippet to validate the check digit of credit cards before the user hits Submit?
James
  • 947
  • 2
  • 12
  • 20
11
votes
13 answers

Check Credit Card Validity using Luhn Algorithm

I tried to check the validation of credit card using Luhn algorithm, which works as the following steps: Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit…
user3126388
  • 171
  • 2
  • 2
  • 5
9
votes
10 answers

Implementation of Luhn Formula

I was trying to implement the Luhn Formula in Python. Here is my code: import sys def luhn_check(number): if number.isdigit(): last_digit = int(str(number)[-1]) reverse_sequence = list(int(d) for d in…
JChris
  • 1,638
  • 5
  • 19
  • 37
8
votes
4 answers

Converting ISBN10 to ISBN13

I have tried to convert ISBN10 codes to ISBN13 numbers with Java. From . On isbn-13.info I found the way to convert them. Example: 0-123456-47-9 Begin with prefix of “978” Use the first nine numeric characters of the ISBN (include dashes)…
MikkoP
  • 4,864
  • 16
  • 58
  • 106
7
votes
1 answer

Luhn or Verhoeff algorithm for credit card numbers

First of all, I'm not really sure if this should be on stackoverflow but I thought I would try to ask anyway. In the past I have always used the luhn algorithm for error checking in credit card numbers, but today I thought I would implement the…
Lucas
  • 10,476
  • 7
  • 39
  • 40
7
votes
7 answers

LuhnCalc and bpay MOD10 version 5

I am using the following PHP code to calculate a CRN for BPay:
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
6
votes
5 answers

Does anyone know where there is c# code or a dll which can generate sample credit card numbers

For an application we are working on I need to generate sample credit card numbers which pass the Luhn algorithm but which are also unique, so we cannot use the sample credit card numbers. We need to be able to generate around 300 card numbers at a…
Kev Hunter
  • 2,565
  • 4
  • 25
  • 39
6
votes
0 answers

Validate credit card number using luhn algorithm

I have a question regarding the following programming assignment. Credit card numbers follow certain patterns. A credit card must have between 13 and 16 digits. It must start with: • 4 for Visa cards • 5 for Master cards • 37 for American…
user3126388
  • 171
  • 2
  • 2
  • 5
5
votes
3 answers

Trying to implement Luhn's Algorithm in C

Iam trying to implement Luhn's algorithm in the C language to check credit card validity, for those who don't know... this is it: Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products’ digits…
someGuy5864
  • 63
  • 1
  • 7
5
votes
6 answers

PHP client PIN security

I'm currently developing a system which has a functionality where clients can view details of their purchases/renewals/etc by supplying a PIN "number". A PIN is being used instead of login information because of the type of clients we're targeting.…
Christian
  • 27,509
  • 17
  • 111
  • 155
1
2 3
13 14