German Tax ID – Calculate the Check Sum using Python/ Steuer-Identifikationsnummer – Prüfsummenberechnung mit Python

Calculate the Check Sum for a German Tax ID number using Python:

#!/usr/local/env python
# -*- coding: utf-8 -*-

class CalcCheckCipher(object):
    @staticmethod
    def getCheckCipher( idnrString):
        n = 11;
        m = 10;

        product = m;

        for cipher in idnrString:
            sum = (int(cipher) + product) % m
            if sum == 0: sum = m
            product = (2*sum) % n

        checkCipher = (n - product)%m
        return checkCipher


def main ():
    print("0107249563 -> %s" % CalcCheckCipher.getCheckCipher("0107249563"))

if __name__ == "__main__":
    main()

Resources

Comments