Skip to content

Instantly share code, notes, and snippets.

@lwille
Created February 15, 2013 13:45
Show Gist options
  • Save lwille/4960462 to your computer and use it in GitHub Desktop.
Save lwille/4960462 to your computer and use it in GitHub Desktop.
Validierung der deutschen Steueridentifikationsnummer
number = '9132456781'.split('');
validation = number.pop();
var n = 11,
m = 10,
product = m,
sum = 0;
console.log("StIdNr: %s, validation: %s", number.join(''),validation);
for (var i in number) {
var c = parseInt(number[i], m);
sum = (c + product) % m;
if (sum === 0) sum = m;
product = (2*sum) % n;
console.log("%d: %d, %d, %d", i, c, sum, product);
}
var pz = n - product;
if (pz == m) pz = 0;
console.log("Checksum = %d, original=%s", pz, validation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment