Skip to content

Instantly share code, notes, and snippets.

@kostrse
Created September 9, 2012 20:52
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 kostrse/3687221 to your computer and use it in GitHub Desktop.
Save kostrse/3687221 to your computer and use it in GitHub Desktop.
CheckAccountNumber - checks checksum for Russian bank account number
private static bool CheckAccountNumber(string bankNumber, string accountNumber)
{
int[] mask = new[] { 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1 };
if (bankNumber.Length < 3)
{
Console.WriteLine("Incorrect bank number.");
return false;
}
if (accountNumber.Length != 20)
{
Console.WriteLine("Incorrect account number.");
return false;
}
string checkNumber = bankNumber.Substring(bankNumber.Length - 3, 3) + accountNumber;
int summ = 0;
for (int i = 0; i < checkNumber.Length; i++)
{
int digitNumber = int.Parse(checkNumber.Substring(i, 1), CultureInfo.InvariantCulture);
int digitMask = mask[i];
summ += digitNumber * digitMask % 10;
}
return summ % 10 == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment