Skip to content

Instantly share code, notes, and snippets.

@fatihbahceci
Created November 21, 2021 21:07
Show Gist options
  • Save fatihbahceci/15c213d993f54bcea2e7fcef792aec0b to your computer and use it in GitHub Desktop.
Save fatihbahceci/15c213d993f54bcea2e7fcef792aec0b to your computer and use it in GitHub Desktop.
Verify TCKNo - TCKNO Doğrulama
public static bool IsValidTCK(long tck)
{
byte[] digits = (tck + "").Select(x => byte.Parse(x + "")).ToArray();
//11 Basamak ve ilk Basamak 0 olamaz
if ((digits.Length == 11) && (digits[0] > 0))
{
//Tek basamakları topla (1,3,5,7,9)
int sumOdds = digits[0] + digits[2] + digits[4] + digits[6] + digits[8];
//Çift basamakları topla (2,4,6,8)
int sumEvens = digits[1] + digits[3] + digits[5] + digits[7];
//(Tekiller * 7) mod 10 = 9'uncu basamak
int c1 = ((sumOdds * 7) - sumEvens) % 10;
if (c1 == digits[9])
{
//(Tek + Çift + 9'uncu basamak) mod 10 = 11'inci basamak
int c2 = (sumOdds + sumEvens + c1) % 10;
if (c2 == digits[10])
{
return true;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment