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
2 answers

luhn algorithm with spaced strings as input c#

Trying to implement a luhn algorithm but with a spaced string as an input. I've tried Linq, some predefined string functions that might be directly related to it (Trim(), Replace()) but it dosen't print out the correct answer Here's my code: static…
SalimKazi
  • 49
  • 1
  • 9
-2
votes
1 answer

How do I convert this Java code to Rexx inorder to generate Luhn compatible credit cards?

public string GenerateCardTokenOptimised() { int[] checkArray = new int[15]; var cardNum = new int[16]; for (int d = 14; d >= 0; d--) { cardNum[d] =…
Fnechz
  • 151
  • 8
-2
votes
2 answers

how can I modify list item value using for loop in Python?

I'm trying to implement the Luhn algorithm in a program and I'm trying to modify list items if they are larger than 9. I will attach the code I'm trying to write. variable iin is defined outside of function. def luhn_checker(): account_number =…
Angel Caro
  • 93
  • 8
-2
votes
1 answer

Regarding CS50 Problem Set 1 Credit - all inputs return "INVALID"

I first attempted the code myself, then tweaked it after watching Deliberate Think's video on Youtube. While my code can be compiled, all credit card number inputs return "INVALID" e.g. when using the testing AMEX number on PayPal (378282246310005),…
-2
votes
1 answer

What is wrong with my code for CS50 credit problem?

Why is my code wrong?? I don't know why... This problem is to get a card number from the user and tell whether it is a valid card number or an invalid card number. It could either be an American Express card, MasterCard, or a Visa. American Express…
Ojou Nii
  • 244
  • 4
  • 11
-2
votes
1 answer

Excecuting Luhn's Algorithm in C - buggy code

I'm currently working through CS50x's 2018 programme and I'm completing the 'credit' part of pset1. We're supposed to be executing Luhn's algorithm, but I can't get it to work. Luhn's algorithm is an algorithm that uses checksum to determine…
PY98
  • 1
  • 3
-2
votes
1 answer

Apply Lunh algorithm in access

Someone know about how can I apply the Lahn algorithm in access, for verify the reference number with the phone number
-2
votes
1 answer

how to create conditional loop for Luhn object to check if index[0] is not 0

I am using a Luhn lib from Github. Luhn class has more methods but I am intersted in only "generate" and "valid?" methods. m = Luhn.generate(9) # generates a random number like [123456789] or [098765432] Luhn.valid?(m) # returns true or false…
gigaimage
  • 29
  • 5
-3
votes
1 answer

How can I create a credit card validator using Luhn's algorithm?

I am trying to create a simple credit card validator using Luhn's algorithm. If the check digit matches the last inputted number, then it should alert the user that it is valid. Else, say that it isn't valid. Currently, I am getting an error with my…
b07580
  • 41
  • 7
-4
votes
2 answers

need help on luhns algorithm using 'C' for CS50

The issue im having with my code is the following: line 15, not recognising the brackets as related despite that it is as well as not recognising the first semi colon in (x/10; x<10, ++count); not recognising the divide symbol and greater than…
-4
votes
1 answer

Credit Card Number Verification

I am working on the credit problem of CS50. However, I am only printing INVALID no matter what card number I put in. May I ask what is the problem with my code? It seems that there is something wrong with the part to calculate the total sum. …
mkmkmkmk
  • 47
  • 1
  • 6
-4
votes
3 answers

Luhn Algorithm sometimes work sometimes fail

If it fits the algorithm, it should have an output of true and if it doesn't, the output should be false. Any idea where it goes wrong? I tried 1586455534096 ; output : false(fail) 49927398716 ; output : true (ok) 984697300577 ; output : false…
M.H.F
  • 81
  • 2
  • 5
1 2 3
13
14