

Damm algorithm - tkmcc
http://en.wikipedia.org/wiki/Damm_algorithm

======
danieltillett
The Damm algorithm is an amazingly useful algorithm. I put together a Base32
version that I use for checking passwords that users enter [1]. It is only in
C and PHP right now - I need to get around to porting it javascript [2].

[1] [http://www.tillett.info/2014/06/12/base32-implementation-
of-...](http://www.tillett.info/2014/06/12/base32-implementation-of-the-damn-
error-detection-algorithm-in-c/)

[2]
[https://github.com/DanielTillett/Damm32](https://github.com/DanielTillett/Damm32)

~~~
nly
Question, in what context is it even possible, or advisable, to catch mistyped
passwords?

~~~
danieltillett
Whenever you want to catch user errors client side rather than server side. It
does not remove the need for security server side, but in my case it allows me
to simplify the security aspects of my service and allow me to immediately
drop any connection that is not using a potentially valid password. If a
potentially valid password has been received then I do further checks on the
actual password. Basically defence in layers.

Another potential use is for checking coupon codes client side. Of course a
JavaScript port would be good for this.

------
ozh
Took me at least 1 minute to notice that it was not "damn", which was quite
puzzling me...

~~~
ChrisArchitect
yeah I was kind of hoping this was an elaborate wikipedia joke article

------
jcampbell1
So this is an improvement on the Luhn algorithm which is used for credit
cards?

~~~
tkmcc
Pretty much.

First there's the Luhn algorithm, which "will detect any single-digit error,
as well as almost all transpositions of adjacent digits. It will not, however,
detect transposition of the two-digit sequence 09 to 90 (or vice versa). It
will detect 7 of the 10 possible twin errors (it will not detect 22 ↔ 55, 33 ↔
66 or 44 ↔ 77)." [0]

Then came the Verhoeff algorithm, which "was the first decimal check digit
algorithm which detects all single-digit errors, and all transposition errors
involving two adjacent digits, which was at the time thought impossible with
such a code." [1]

The Damm algorithm was developed in 2004 and was a further improvement:

> The Damm algorithm is similar to the Verhoeff algorithm. It too will detect
> all occurrences of the two most frequently appearing types of transcription
> errors,[1] namely altering one single digit, and transposing two adjacent
> digits (including the transposition of the trailing check digit itself and
> the digit preceding it). But the Damm algorithm has the benefit that it
> makes do without the dedicatedly constructed permutations and its position
> specific powers being inherent in the Verhoeff scheme. Furthermore, a table
> of inverses can be dispensed with provided all main diagonal entries of the
> operation table are zero.

> The Damm algorithm does not suffer from exceeding the number of 10 possible
> values, resulting in the need for using a non-digit character (as the X in
> the 10-digit ISBN check digit scheme).

> Prepending leading zeros does not affect the check digit.

> There are totally anti-symmetric quasigroups that detect all phonetic errors
> associated with the English language (13 ↔ 30, 14 ↔ 40, ..., 19 ↔ 90). The
> table used in the illustrating example is based on an instance of such kind.

> Despite its desirable properties in typical contexts where similar
> algorithms are used, the Damm algorithm is largely unknown and scarcely used
> in practice.

That last point is also why I submitted this :)

[0]
[http://en.wikipedia.org/wiki/Luhn_algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm)

[1]
[http://en.wikipedia.org/wiki/Verhoeff_algorithm](http://en.wikipedia.org/wiki/Verhoeff_algorithm)

------
oliv__
Damm

