choval/damm

Damm algorithm functions, a check digit algorithm that detects single-digit errors and adjacent transposition errors

Maintainers

Details

github.com/choval/damm

Source

Issues

Installs: 1 102

Dependents: 1

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/choval/damm

v0.1.1 2021-05-08 14:44 UTC

This package is auto-updated.

Last update: 2025-10-09 00:49:30 UTC


README

Damm algorithm functions.

In error detection, the Damm algorithm is a check digit algorithm that detects all single-digit errors and adjacent transposition errors. It was presented by H. Michael Damm in 2004.

-- Wikipedia

Install

composer require choval/damm

Usage

damm_digit(string $number) : int
damm_valid(string $number[, string $digit]) : bool

Both functions take a string as parameter to allow numbers larger than PHP_INT_MAX.
They still have to be numeric.

Examples:

echo damm_digit(572);
// 4

echo damm_digit('572');
// 4

echo damm_digit('0000572');
// 4

echo damm_valid(572, 4);
// true

echo damm_valid(572, 3);
// false

echo damm_valid(5724);
// true

echo damm_valid('000005724');
// true

License

MIT, see LICENSE