Skip to content

erdh/turkish_id_check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turkish ID Check

This basic Rust script makes sure the input is an actual 11 digit Turkish ID Number (Türkiye Cumhuriyeti Kimlik Numarası/TCKN)

I got inspiration from https://github.com/ssg/TurkishId library, and for sake of learning Rust, I tried to remake it as much as I can.

I've tried to explain code with comments as much as I can, sorry if I couldn't explain the code as I should.

Output is written in Turkish and logging is written in English, also giving info about why the input is rejected.

Usage

Compile the code with Cargo cargo build

Or to use the code as release cargo build --release

Afterward, just input 11-digit ID to prompt "TC Kimlik No Giriniz:" and let the magic work.

To debug and learn why input is rejected pass RUST_LOG=info environment variable

The Algorithm

Let's say we name each digit as d(n) where the leftmost digit is called d1 and the rightmost is d11

If:

d1 > 0

and

n = (d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6 + d8)

if n < 0 then n = n + 10

d10 = n mod 10

and

d11 = sum(d1..d10) mod 10

then the ID given is valid.

About

A Rust script to validate TCKN

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages