stocker4all/luhn-mod-n
Composer 安装命令:
composer require stocker4all/luhn-mod-n
包简介
luhn-mod-n is a very simple solution to generate and verify luhn mod n checksums. Possible bases (value for n) are between 2 and 36. Luhn mod 10 is well known from the credit card number checksum. But also in different bases it can be useful to have this checksum functionality.
README 文档
README
luhn-mod-n is a very simple solution to generate and verify luhn mod n checksums. Possible bases (value for n) are between 2 and 36. Luhn mod 10 is well known from the credit card number checksum. But also in different bases it can be useful to have this checksum functionality.
Example for base 2:
Input
1001001100101100000001011010010
Output (number with checksum)
10010011001011000000010110100100
Example for base 10:
Input
1234567890
Output (number with checksum)
12345678903
Example for base 16:
Input
499602d2
Output (number with checksum)
499602d2f
Example for base 36:
Input
kf12oi
Output (number with checksum)
kf12ois
Installing
You can use Composer to add the package to your project:
composer require stocker4all/luhn-mod-n
Usage example
<?php
use S4A\LuhnModN\LuhnModN;
include 'vendor/autoload.php';
// Base 10 example
$luhnModN = new LuhnModN();
$number = 1234567890;
// Generate checksum and return it concatenated to given number
$numberWithChecksum = $luhnModN->createChecksum($number, 10);
echo $numberWithChecksum."\n";
// Generate checksum and return only checksum
$onlyChecksum = $luhnModN->createChecksum($number, 10, false);
echo $onlyChecksum."\n";
// Verify the checksum
if ($luhnModN->hasValidChecksum($numberWithChecksum, 10)) {
echo "Valid checksum\n";
}
This example will result in the following output:
12345678903
3
Valid checksum
Tests
Some very basic tests are provided in the tests/ directory. Run them with composer install --dev && vendor/bin/phpunit.
License
luhn-mod-n is licensed under MIT
stocker4all/luhn-mod-n 适用场景与选型建议
stocker4all/luhn-mod-n 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50.52k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stocker4all/luhn-mod-n 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stocker4all/luhn-mod-n 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 50.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-02