A simple yet effective C# console application that validates credit card numbers using the Luhn Algorithm and identifies the card type (VISA, Mastercard, AMEX).
The Luhn Algorithm (also known as the "modulus 10" or "mod 10" algorithm) is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and IMEI numbers, to protect against accidental errors. It was created by IBM scientist Hans Peter Luhn.
The algorithm works as follows:
- Start from the rightmost digit (the check digit) and move left.
- Double the value of every second digit. If the result of this doubling operation is greater than 9 (e.g., 14), then add the digits of the product (e.g., 1 + 4 = 5) or simply subtract 9 from the product.
- Take the sum of all the digits.
- If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid.
The main objective of this project is to implement the Luhn Algorithm in C# and verify whether a credit card number inputted by the user is valid.
When a user inputs a number, the application:
- Validates the number according to the Luhn algorithm.
- If valid, it identifies the card type (VISA, Mastercard, American Express, etc.) based on its starting digits and length.
Follow these steps to run the application on your local machine:
- .NET SDK must be installed on your system.
- Clone the repository (or download the source code):
git clone <repository-url>
- Navigate to the project directory:
cd Luhn - Run the application:
dotnet run
- Usage: The console will prompt you to enter a card number. Type the number without spaces and press "Enter" to see the validation result and card type.
This project is licensed under the MIT License. See the LICENSE file for details.