Created
February 15, 2013 13:45
-
-
Save lwille/4960462 to your computer and use it in GitHub Desktop.
Validierung der deutschen Steueridentifikationsnummer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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