Skip to content

Instantly share code, notes, and snippets.

@yarosla
Last active December 30, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarosla/7807711 to your computer and use it in GitHub Desktop.
Save yarosla/7807711 to your computer and use it in GitHub Desktop.
Yandex.Money account ID verification in Python
# coding=utf-8
# Author: Yaroslav Stavnichiy
def verify_account_id(acct):
if not isinstance(acct, (str, unicode)):
return False
try:
E=[int(c) for c in acct]
except:
return False
N=E[0]
if N==0: return False
if len(E)<N+4: return False
X=E[1:N+1]
Y=E[N+1:-2]
Z=E[-2]*10+E[-1]
if len(Y)>20: return False
if Z==0: return False
return account_number_redundancy(X, Y)==Z
def account_number_redundancy(X, Y):
T=Y[::-1] + [0]*(20-len(Y)) + X[::-1] + [0]*(10-len(X)) # [::-1] reverses the list
Z=0
A=70
for TI in T:
TI=10-(-TI%10)
Z=(Z + TI*A % 99) % 99
A=A*13 % 99
return Z+1
if __name__=='__main__':
# контрольные примеры счетов
print verify_account_id('512345678925')
print verify_account_id('498765432131')
print verify_account_id('41001100113')
print verify_account_id('41001123494')
print verify_account_id('41002100117')
print verify_account_id('41002123498')
print verify_account_id('41003100121')
print verify_account_id('41003123403')
# негативный тест - ошибка в одной цифре счета
print verify_account_id('41003103403')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment