A Kotlin-based utility for generating and validating SNILS (Russian social security numbers) based on official rules.
The SnilsGenerator
project provides functionality for generating valid SNILS numbers, ensuring that the generated
numbers adhere to the rules governing SNILS structure and validation. The project includes a core generator class and
utilities for random number generation and checksum calculation.
SnilsGenerator
: The main class responsible for generating SNILS numbers. It ensures that the random SNILS part is valid and computes the correct check digit.RandomValuesGenerator
: A utility class used bySnilsGenerator
to generate random numeric strings that conform to SNILS generation rules.
SNILS (СНИЛС) numbers have the format XXX-XXX-XXX YY
, where XXX-XXX-XXX
is a nine-digit number and YY
is the check
number.
- Each digit of the SNILS number (excluding the check digits) is multiplied by its positional value, starting from the end.
- The products are summed up.
- The check number is determined as follows:
- If the sum is less than 100, the check number is equal to the sum.
- If the sum is 100 or 101, the check number is
00
. - If the sum is greater than 101, it is divided by 101, and the remainder is used as the check number. If the remainder
is 100 or 101, the check number is
00
.
- The SNILS number cannot contain the same digit three times in a row, ignoring hyphens.
For example,XXX-222-XXX YY
andXX2-22X-XXX YY
are invalid.
To run the tests for the project, use the following Gradle command:
./gradlew test
This will execute all unit tests, including those for SNILS generation and validation, ensuring that the implementation conforms to the specified rules.
Author: Evgeny Tumashchick
For any questions, issues, or contributions, you can reach out to me via:
- Email: tumashchick@gmail.com
- LinkedIn: Evgeny Tumashchick
- GitHub: evgeny-tumashchick
Feel free to open an issue on the GitHub repository for bug reports, feature requests, or any other inquiries.