问题标签 [luhn]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c - Credit program doesn't compile
I tried to make a C program that checks if a bank card is valid.
According to Luhn’s algorithm, you can determine if a credit card number is (syntactically) valid as follows:
Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products' digits together.
Add the sum to the sum of the digits that weren’t multiplied by 2.
If the total’s last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid!
That’s kind of confusing, so let’s try an example with my AmEx: 378282246310005.
For the sake of discussion, let’s first underline every other digit, starting with the number’s second-to-last digit:
378282246310005
Okay, let’s multiply each of the underlined digits by 2:
7•2 + 2•2 + 2•2 + 4•2 + 3•2 + 0•2 + 0•2
That gives us:
14 + 4 + 4 + 8 + 6 + 0 + 0
Now let’s add those products' digits (i.e., not the products themselves) together:
1 + 4 + 4 + 4 + 8 + 6 + 0 + 0 = 27
Now let’s add that sum (27) to the sum of the digits that weren’t multiplied by 2:
27 + 3 + 8 + 8 + 2 + 6 + 1 + 0 + 5 = 60
Yup, the last digit in that sum (60) is a 0, so my card is legit!
So, validating credit card numbers isn’t hard, but it does get a bit tedious by hand
The error when compiling is:
credit-card - 当我们使用 Luhn 算法验证信用卡时,为什么要反转数字?
我正在尝试实现验证信用卡的 Luhn 算法,有一个步骤是我们反转卡号,为什么需要反转卡号?
javascript - 如何在 javascript 中使用 luhn 算法获取下一个校验位
我有以下代码使用 luhn 算法模块 10 验证某个数字是否有效。
我需要另一个函数,它实际上通过给出四位数字来生成下一个校验位,因此第 5 位将是下一位校验和。
javascript - 我需要使用字母数字校验和验证输入字符串
我有以下函数验证数字输入仅包含基于 Luhn 算法的数字:
无论如何我也可以验证字母数字,所以假设我有一个有效的 ID: AC813(6) , () 是校验和。那么有没有一种方法可以防止用户输入错误的 AF813(6),这样会告诉用户不正确的 ID。
我感谢您的帮助
java - 在 Java 中对长变量使用 Luhn/Mod 10 检查
嗨,我遇到了作业问题,要求我使用 Luhn/Mod 10 检查以查看信用卡号是否符合信用卡要求。有人可以告诉我如何告诉计算机从输入的长变量中读取数字吗?谢谢,祝你有美好的一天!
java - 如何通过第一个数值识别字符串
我正在开发一个信用卡验证器程序,但我还想实现代码,该代码可识别通过其第一个数值输入的信用卡类型。如何通过第一个数值识别字符串?
algorithm - 找不到数字校验算法
我找不到用于计算我的银行参考的 2 位校验位的算法。
一些例子
由于用户帐户,我知道最后 2 位数字是校验位。
我尝试使用 Mod 97 和 Base 10 (Luhn)
我不知道其他算法,例如: Mod 22、Base 36、Algorithm 45
任何想法?
对我的样本进行分组和计数,如果有帮助的话:
Sears 和 Oxxo 的参考有一个校验位,即 Mod10 (Luhn)。
(您可以在此页面计算luhn校验位:https ://planetcalc.com/2464/ )
我如何获得88?
java - IMEI 未通过 Luhn 校验和
我有以下代码用于验证 IMEI(不是 SV)
除了我的三星 Galaxy Note 4 之外,几乎所有的 IMEI 都可以检查。
出于明显的原因,我不想在这里发布它,但同时我需要有人来验证它是否有效。
也许是我的实现不对。
请帮忙。
java - 制作 Luhn 的校验码 - Java
我一直在尝试使用 Luhn 算法在 java 中创建一个校验位,而我来到这里是出于完全的挫败感。我处于第一步,即将所有数字相加(如果加倍后大于 9,则每隔一个数字加倍并减去 9)但我无法得到接近总和的答案应该是. 如果我输入“11”作为字符串,输出总和应该是 3 时输出为 138。我不知道我的代码有什么问题,我想知道是否有更多经验的人可以帮助我。
加法:即使将代码简化为仅将每个单独数字的值相加,所述值的总和仍然相去甚远。
python - 信用卡验证 - 返回非硬编码的值
如何计算答案以使答案不是硬编码的解决方案?就像我想输入另一个信用卡号一样,我该如何返回该新信用卡的结果?另外,如何创建一个 x 列表,而不是像现在这样将值除以 2 的方式?
另外这里是原始问题供参考:
信用卡号码使用 Luhn 的公式 3 进行验证。实现一个程序,将信用卡号码作为一个多维数组(您可以假设它正好由 16 列组成),并返回一个包含值的列表Valid如果它是有效的卡号,否则无效。
进行有效性测试的一种方法如下:
1. 从最右边的数字,即校验位,向左移动,每隔一个数字加一倍;如果这个加倍运算的乘积大于 9(例如,8 2 = 16),则将乘积的数字相加(例如,16:1 + 6 = 7、18:1 + 8 = 9)。
2. 取所有数字的总和。
3.若总数能被10整除,则根据卢恩公式该数有效;否则无效。注意:您可以将卡号操作为字符串(使用索引和切片来提取数字等)或整数(使用整数除法和余数来操作数字)。
我的脚本:
有没有更简单的方法可以在没有 Numpy 的情况下做到这一点?