Created
September 7, 2020 06:46
-
-
Save adilkhash/cca3e4ee73e75c2fc405af901d7672f6 to your computer and use it in GitHub Desktop.
Валидация ИИН/БИН Республики Казахстан
This file contains 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
import re | |
from operator import add, mul | |
from functools import reduce | |
from typing import List | |
def multiply(iin: str, weights: List[int]) -> int: | |
result = reduce( | |
add, | |
map(lambda i: mul(*i), zip(map(int, iin), weights)) | |
) | |
return result | |
def validate_iin(iin: str) -> bool: | |
if not re.match(r'[0-9]{12}', iin): | |
return False | |
w1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] | |
w2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2] | |
check_sum = multiply(iin, w1) % 11 | |
if check_sum == 10: | |
check_sum = multiply(iin, w2) % 11 | |
if check_sum != int(iin[-1]): | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment