T
T
TempUserForToster2014-02-15 22:07:01
Algorithms
TempUserForToster, 2014-02-15 22:07:01

How to generate a correct taxpayer tax record number (TIN)?

The TIN of an individual for Russia consists of 12 digits:
1 and 2 - the code of the subject of the Russian Federation (region code)
2 and 3 - the number of the local tax office
4 - 10 - the number of the taxpayer's tax record
11 and 12 - control digits
Please tell me how to generate the correct number of the taxpayer's tax record or there can be completely arbitrary numbers?
UPD:
I forgot to write, if I understood correctly, then the numbers 4-10 are generated in random order from 000000 to 999999. When creating the TIN, I took the first 4 digits correct, based on the list of codes \ numbers, 4-10 arbitrary numbers, 11-12 created by algorithm. As a result, when checking the generated numbers on the TIN verification site, all the values ​​turned out to be correct.
If I'm wrong, I'll be glad to be corrected.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
Foo Bar, 2016-06-29
@atomheart

I’ll do my bit in Python + the TIN validity check function:

def inn_ctrl_summ(nums, type):
    """
    Подсчет контрольной суммы
    """
    inn_ctrl_type = {
        'n2_12': [7, 2, 4, 10, 3, 5, 9, 4, 6, 8],
        'n1_12': [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8],
        'n1_10': [2, 4, 10, 3, 5, 9, 4, 6, 8],
    }
    n = 0
    l = inn_ctrl_type[type]
    for i in range(0, len(l)):
        n += nums[i] * l[i]
    return n % 11 % 10


def inn_gen(l=None):
    """
    Генерация ИНН (10 или 12 значный)
    На входе указывается длина номера - 10 или 12.
    Если ничего не указано, будет выбрана случайная длина.
    """
    if not l:
        l = list((10, 12))[rnd(0, 1)]
    if l not in (10, 12):
        return None
    nums = [
        rnd(1, 9) if x == 0
        else rnd(0, 9)
        for x in range(0, 9 if l == 10 else 10)
    ]
    if l == 12:
        n2 = inn_ctrl_summ(nums, 'n2_12')
        nums.append(n2)
        n1 = inn_ctrl_summ(nums, 'n1_12')
        nums.append(n1)
    elif l == 10:
        n1 = inn_ctrl_summ(nums, 'n1_10')
        nums.append(n1)
    return ''.join([str(x) for x in nums])


def inn_check(inn):
    """
    Проверка ИНН на корректность
    В соответствии с алгоритмом, описанным по ссылке:
        https://ru.wikipedia.org/wiki/Контрольное_число
    """
    sinn = str(inn)
    nums = [int(x) for x in sinn]
    if len(sinn) == 10:
        n1 = inn_ctrl_summ(nums, 'n1_10')
        return n1 == nums[-1]
    elif len(sinn) == 12:
        n2 = inn_ctrl_summ(nums, 'n2_12')
        n1 = inn_ctrl_summ(nums, 'n1_12')
        return n2 == nums[-2] and n1 == nums[-1]
    else:
        return False

O
Oleg, 2014-02-15
@makol

Read carefully and refer to them, en.wikipedia.org/wiki/%D0%98%D0%B4%D0%B5%D0%BD%D1%... they will just generate for you, if necessary. :) And the next time you want to generate a passport form for a Russian citizen, then immediately contact the Federal Migration Service. :)

D
Dmitry., 2014-02-15
@gravity

function INN(const INN: string): Boolean;
const
  factor1: array[0..8] of byte = (2, 4, 10, 3, 5, 9, 4, 6, 8);
  factor2: array[0..9] of byte = (7, 2, 4, 10, 3, 5, 9, 4, 6, 8);
  factor3: array[0..10] of byte = (3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8);
var
  i: byte;
  sum: word;
  sum2: word;
begin
  Result := False;

  try
    if Length(INN) = 10 then begin
      sum := 0;
      for i := 0 to 8 do
        sum := sum + StrToInt(INN[i + 1]) * factor1[i];
      sum := sum mod 11;
      sum := sum mod 10;
      Result := StrToInt(INN[10]) = sum;
    end
    else if Length(INN) = 12 then begin
      sum := 0;
      for i := 0 to 9 do
        sum := sum + StrToInt(INN[i + 1]) * factor2[i];
      sum := sum mod 11;
      sum := sum mod 10;
      sum2 := 0;
      for i := 0 to 10 do
        sum2 := sum2 + StrToInt(INN[i + 1]) * factor3[i];
      sum2 := sum2 mod 11;
      sum2 := sum2 mod 10;
      Result := (StrToInt(INN[11]) = sum) and
        (StrToInt(INN[12]) = sum2);
    end; //
  except
    Result := False;
  end; // try
end;

Check number check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question