Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
cdigit - Collection of check digit algorithms implemented in JavaScript
Node.js:
const cdigit = require('cdigit');
// Luhn (a.k.a. Mod 10) algorithm
console.log(cdigit.luhn.compute('1234')); // '4'
console.log(cdigit.luhn.generate('1234')); // '12344'
console.log(cdigit.luhn.validate('12344')); // true
Command line:
cdigit --algo damm compute 1234
cdigit --algo damm generate 1234
cdigit --algo damm validate 12340
Algorithm | cdigit name | Input string | Check character(s) |
---|---|---|---|
Luhn | luhn | Numeric (0-9) | 1 digit (0-9) |
Verhoeff | verhoeff | Numeric (0-9) | 1 digit (0-9) |
Damm | damm | Numeric (0-9) | 1 digit (0-9) |
ISO/IEC 7064, MOD 11-2 | mod11_2 | Numeric (0-9) | 1 digit or 'X' (0-9X) |
ISO/IEC 7064, MOD 37-2 | mod37_2 | Alphanumeric (0-9A-Z) | 1 digit, letter, or '*' (0-9A-Z*) |
ISO/IEC 7064, MOD 97-10 | mod97_10 | Numeric (0-9) | 2 digits (0-9) |
ISO/IEC 7064, MOD 661-26 | mod661_26 | Alphabetic (A-Z) | 2 letters (A-Z) |
ISO/IEC 7064, MOD 1271-36 | mod1271_36 | Alphanumeric (0-9A-Z) | 2 digits or letters (0-9A-Z) |
ISO/IEC 7064, MOD 11-10 | mod11_10 | Numeric (0-9) | 1 digit (0-9) |
ISO/IEC 7064, MOD 27-26 | mod27_26 | Alphabetic (A-Z) | 1 letter (A-Z) |
ISO/IEC 7064, MOD 37-36 | mod37_36 | Alphanumeric (0-9A-Z) | 1 digit or letter (0-9A-Z) |
Load cdigit
and access to an algorithm object by cdigit.name as listed in
Supported Algorithms section.
const cdigit = require('cdigit');
const algo = cdigit.mod97_10;
Algorithm objects implement the following methods.
Check if a given string is valid in accordance with the algorithm. The argument must include check digit(s) as well as the source number.
console.log(cdigit.mod97_10.validate('123482')); // true
Generate a valid number string from a given source number. The generated string includes the check digit(s) computed and placed in accordance with the algorithm.
console.log(cdigit.mod97_10.generate('1234')); // '123482'
Generate check digit(s) from a given source number. This returns the check digit(s) only.
console.log(cdigit.mod97_10.compute('1234')); // '82'
See example.js for usage examples.
Usage: cdigit [options] [command]
Options:
-a, --algo <name> specify check digit algorithm (see below)
-h, --help output usage information
Commands:
validate <string> check if string is valid
generate <string> generate valid number from string
compute <string> compute check digit from string
Supported Algorithms:
luhn Luhn Algorithm
verhoeff Verhoeff Algorithm
damm Damm Algorithm
mod11_2 ISO/IEC 7064, MOD 11-2
mod37_2 ISO/IEC 7064, MOD 37-2
mod97_10 ISO/IEC 7064, MOD 97-10
mod661_26 ISO/IEC 7064, MOD 661-26
mod1271_36 ISO/IEC 7064, MOD 1271-36
mod11_10 ISO/IEC 7064, MOD 11-10
mod27_26 ISO/IEC 7064, MOD 27-26
mod37_36 ISO/IEC 7064, MOD 37-36
(--algo defaults to `luhn' or CDIGIT_CLI_DEFAULT_ALGO env var if set)
Copyright (c) 2018 LiosK
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Collection of check digit algorithms implemented in JavaScript
The npm package cdigit receives a total of 2,420 weekly downloads. As such, cdigit popularity was classified as popular.
We found that cdigit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.