- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
public class Checker
{
public bool CheckInn(long inn)
{
var values = inn.ToArray();
switch (values.Length)
{
case 10:
#region Юр. лица
var coefficientsN10 = new byte[] { 2, 4, 10, 3, 5, 9, 4, 6, 8 };
int sumN10 = GetSumNx(values, coefficientsN10);
var checkNumberN10 = (sumN10 % 11) % 10;
return values[^1] == checkNumberN10;
#endregion
case 12:
#region Физ. лица
var coefficientsN11 = new byte[] { 7, 2, 4, 10, 3, 5, 9, 4, 6, 8 };
var coefficientsN12 = new byte[] { 3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8 };
var sumN11 = GetSumNx(values, coefficientsN11);
var checkNumberN11 = (sumN11 % 11) % 10;
var sumN12 = GetSumNx(values, coefficientsN12);
var checkNumberN12 = (sumN12 % 11) % 10;
return values[^2] == checkNumberN11 && values[^1] == checkNumberN12;
#endregion
default:
return false;
}
}
private int GetSumNx(byte[] values, byte[] coefficientsNx)
{
var sumNx = 0;
for (int i = 0; i < coefficientsNx.Length; i++)
sumNx += coefficientsNx[i] * values[i];
return sumNx;
}
}
public static class Extensions
{
public static byte[] ToArray(this long number)
{
var values = new Stack<byte>(12);
while (number != 0)
{
values.Push((byte)(number % 10));
number /= 10;
}
return values.ToArray();
}
}