{"id":23773141,"url":"https://github.com/ctkqiang/luhnalgorithm","last_synced_at":"2025-09-05T18:31:06.795Z","repository":{"id":109216963,"uuid":"371746185","full_name":"ctkqiang/LuhnAlgorithm","owner":"ctkqiang","description":"Luhn算法，也被称为Mod 10算法，是数据完整性验证领域的一个重要基石。它主要用于验证各种身份编码，如信用卡号码、IMEI码，甚至包括加拿大社会保险号码，其重要性超越了其简单性。  Luhn算法的优雅之处在于其系统化的方法，用于确认身份代码的真实性。这个历史悠久的技术利用模数算术的威力创建校验和，经得起审查，实现了无缝的身份编码验证。","archived":false,"fork":false,"pushed_at":"2024-06-04T03:47:19.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-04T04:44:53.603Z","etag":null,"topics":["card","credit-card","erlang","johnmelodyme","luhn-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctkqiang.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-28T15:35:43.000Z","updated_at":"2024-06-04T03:47:23.000Z","dependencies_parsed_at":"2023-11-12T12:39:41.776Z","dependency_job_id":"815364fd-2c6f-4667-9254-edb31b52e1bc","html_url":"https://github.com/ctkqiang/LuhnAlgorithm","commit_stats":null,"previous_names":["ctkqiang/luhnalgorithm"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctkqiang%2FLuhnAlgorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctkqiang%2FLuhnAlgorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctkqiang%2FLuhnAlgorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctkqiang%2FLuhnAlgorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctkqiang","download_url":"https://codeload.github.com/ctkqiang/LuhnAlgorithm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232052260,"owners_count":18465722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["card","credit-card","erlang","johnmelodyme","luhn-algorithm"],"created_at":"2025-01-01T05:35:53.493Z","updated_at":"2025-01-01T05:35:54.354Z","avatar_url":"https://github.com/ctkqiang.png","language":"Erlang","readme":"# Luhn算法：加强身份验证的数据安全\n\nLuhn算法，也被称为Mod 10算法，是数据完整性验证领域的一个重要基石。它主要用于验证各种身份编码，如信用卡号码、IMEI码，甚至包括加拿大社会保险号码，其重要性超越了其简单性。\n\nLuhn算法的优雅之处在于其系统化的方法，用于确认身份代码的真实性。这个历史悠久的技术利用模数算术的威力创建校验和，经得起审查，实现了无缝的身份编码验证。\n\n## 解析公式\n\n让我们通过一个假想的借记卡/信用卡号码示例 ```4716 2495 3356 7731``` 来深入了解这个算法的内部运作。过程从将卡号分割成数组开始，然后将数组中偶数索引位置的每个数字加倍。\n\n随后，算法通过对加倍值的各个数字进行求和来继续进行。值得注意的是，如果任何一个加倍的数字超过了9，只需简单地减去9，即可确保校验和的准确性。\n\n下一步涉及对数组中未被操作的数字进行求和 - 即位于奇数索引位置的数字。将偶数索引位置的数字的总和与奇数索引位置的数字的总和相结合，得到一个累积值。\n\n就在这时，Luhn算法的独创性浮出水面。如果总和可以被10整除，验证就是成功的，确认了身份编码的有效性。\n\n**Mod 10魔法的复杂性**\n\n除了其数学精度，Luhn算法还流露出一种优雅和实用。在一个越来越依赖安全身份机制的世界中，这个算法是一个哨兵，确保各种应用中的身份编码的完整性。\n\n在支付系统、电信网络和官方文件中，Luhn算法代表了数学与技术进步之间的协同作用。在我们继续航行数据安全至上的时代时，Luhn算法仍然是一个坚定的伙伴，保障着我们最关键身份编码的真实性。\n\n| 4 | 7 | 1 | 6 | 2 | 4 | 9 | 5 | 3 | 3 | 5 | 6 | 7 | 7 | 3 | 0 |\n|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n|   | 14 |   | 12 |  | 8 |  | 10 |   | 6 |  | 12 |  | 14 |  | 0 |\n\n其次，如果双精度值大于9，则将这些数字分开\n到数组中，并得到两者的和。\n\n| 4 | 7 | 1 | 6 | 2 | 4 | 9 | 5 | 3 | 3 | 5 | 6 | 7 | 7 | 3 | 0 |\n|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n|   | 14 |   | 12 |  | 8 |  | 10 |   | 6 |  | 12 |  | 14 |  |  |\n|   | 5 |   | 3 |  |  |  | 1 |   |  |  | 3 |  | 5 |  |  |\n\n现在将9之前的值覆盖到现有卡号，\n\n```latex\n\n4 + 7 + 1 + 6 + 2 + 8 + 9 + 5 + 3 + 6 + 5 + 6 + 7 + 7 + 3 + 0 = 79\n\n\\newline\n\\therefore 此卡无效：：不是10的倍数\n```\n\n# 编译和运行指南\n\n这是一个简短的指南，说明如何编译和运行 Erlang 模块 `luhn`。\n\n## 编译步骤\n\n1. 将 `luhn.erl` 文件保存到本地计算机。\n2. 打开终端或命令提示符。\n3. 使用 `cd` 命令导航到包含 `luhn.erl` 文件的目录。\n4. 在终端中输入 `erl` 并按 Enter 键启动 Erlang shell。\n5. 在 Erlang shell 中，输入以下命令来编译 `luhn.erl` 文件：\n\n```erlang\nc(luhn).\n```\n\n## 运行示例\n\n编译完成后，您可以通过以下步骤运行示例：\n\n1. 在 Erlang shell 中调用 `start/1` 函数，并传入卡号作为参数。\n\n```erlang\nluhn:start(\"1234567890\").\n```\n\n请将 `\"1234567890\"` 替换为您要检查的实际卡号。\n\n## 注意事项\n\n- 确保在您的系统上安装了 Erlang。\n- 在编译和运行模块时，请使用正确的文件路径和文件名。\n- 您可以根据需要调用其他函数，或者在模块中添加自定义功能。\n\n\n### 个人捐赠支持\n如果您认为该项目对您有所帮助，并且愿意个人捐赠以支持其持续发展和维护，🥰我非常感激您的慷慨。\n您的捐赠将帮助我继续改进和添加新功能到该项目中。 通过财务捐赠，您将有助于确保该项目保持免\n费和对所有人开放。即使是一小笔捐款也能产生巨大的影响，也是对我个人的鼓励。\n\n以下是我的支付宝二维码，您可以扫描二维码进行个人捐赠：\n\n\u003cbr /\u003e\n\u003cdiv style=\"display: flex; justify-content: space-between; margin-bottom: 20px;\"\u003e\n  \u003cimg src=\"https://github.com/ctkqiang/ctkqiang/blob/main/assets/IMG_9863.jpg?raw=true\" style=\"height: 500px !important; width: 350px !important;\"\u003e\n \n  \u003cimg src=\"https://github.com/ctkqiang/ctkqiang/blob/main/assets/IMG_9859.JPG?raw=true\" style=\"height: 500px !important; width: 350px !important;\"\u003e\n\u003c/div\u003e\n\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F5VCZJU)\n\n\n\n## 爱心捐款\n\u003ca href=\"https://qr.alipay.com/fkx19369scgxdrkv8mxso92\"\u003e\u003cimg src=\"https://img.shields.io/badge/alipay-00A1E9?style=for-the-badge\u0026logo=alipay\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://ko-fi.com/F1F5VCZJU\"\u003e\u003cimg src=\"https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge\u0026logo=ko-fi\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://www.paypal.com/paypalme/ctkqiang\"\u003e\u003cimg src=\"https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\u0026logo=paypal\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://donate.stripe.com/00gg2nefu6TK1LqeUY\"\u003e\u003cimg src=\"https://img.shields.io/badge/Stripe-626CD9?style=for-the-badge\u0026logo=Stripe\u0026logoColor=white\"\u003e\u003c/a\u003e\n\n## 关注我\n\u003ca href=\"https://twitch.tv/ctkqiang\"\u003e\u003cimg src=\"https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge\u0026logo=twitch\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://open.spotify.com/user/22sblyn4dsymya3xinw3umhai\"\u003e\u003cimg src=\"https://img.shields.io/badge/Spotify-1ED760?\u0026style=for-the-badge\u0026logo=spotify\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://www.tiktok.com/@ctkqiang\"\u003e\u003cimg src=\"https://img.shields.io/badge/TikTok-000000?style=for-the-badge\u0026logo=tiktok\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://stackoverflow.com/users/10758321/%e9%92%9f%e6%99%ba%e5%bc%ba\"\u003e\u003cimg src=\"https://img.shields.io/badge/Stack_Overflow-FE7A16?style=for-the-badge\u0026logo=stack-overflow\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://www.facebook.com/JohnMelodyme/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge\u0026logo=facebook\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://github.com/ctkqiang\"\u003e\u003cimg src=\"https://img.shields.io/badge/GitHub-100000?style=for-the-badge\u0026logo=github\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://www.instagram.com/ctkqiang\"\u003e\u003cimg src=\"https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge\u0026logo=instagram\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://www.linkedin.com/in/ctkqiang/\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://linktr.ee/ctkqiang.official\"\u003e\u003cimg src=\"https://img.shields.io/badge/linktree-39E09B?style=for-the-badge\u0026logo=linktree\u0026logoColor=white\"\u003e\u003c/a\u003e \u003ca href=\"https://github.com/ctkqiang/ctkqiang/blob/main/assets/IMG_9245.JPG?raw=true\"\u003e\u003cimg src=\"https://img.shields.io/badge/WeChat-07C160?style=for-the-badge\u0026logo=wechat\u0026logoColor=white\"\u003e\u003c/a\u003e\n\n","funding_links":["https://ko-fi.com/F1F5VCZJU","https://www.paypal.com/paypalme/ctkqiang"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctkqiang%2Fluhnalgorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctkqiang%2Fluhnalgorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctkqiang%2Fluhnalgorithm/lists"}