You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
// See https://aka.ms/new-console-template for more information
|
|
Console.WriteLine("Hello, World!");
|
|
|
|
while (true)
|
|
{
|
|
string mode = "NULL"; int givenCheckNo = 0;
|
|
|
|
Console.Write("Pls input complete EAN:\n-> ");
|
|
string input = Console.ReadLine();
|
|
|
|
if (input == null || input == "") continue;
|
|
|
|
if (input == "q")
|
|
{
|
|
Console.WriteLine("Bye bye!");
|
|
return;
|
|
}
|
|
|
|
string[] split = input.Select(x => x.ToString()).ToArray();
|
|
|
|
if (split.Count() == 13) mode = "VALIDATE";
|
|
if (split.Count() == 12) mode = "GENERATE";
|
|
|
|
if (mode == "NULL") continue;
|
|
|
|
bool skip = false;
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < split.Count(); i++)
|
|
{
|
|
string sign = split[i];
|
|
int val;
|
|
|
|
if (!int.TryParse(sign, out val))
|
|
{
|
|
skip = true;
|
|
break;
|
|
}
|
|
|
|
Console.WriteLine($"no: {val} | sum: {sum}");
|
|
|
|
if (i == 12) givenCheckNo = val;
|
|
|
|
if (i % 2 == 1)
|
|
{
|
|
val *= 3;
|
|
}
|
|
|
|
if (i < 12) sum += val;
|
|
}
|
|
if (skip) continue;
|
|
|
|
int temp = Convert.ToInt32(Math.Ceiling(sum / 10f));
|
|
|
|
int nextFullTen = temp * 10;
|
|
|
|
int checksum = nextFullTen - sum;
|
|
|
|
string msg = $"Generated Checksum: {checksum}";
|
|
|
|
if (mode== "VALIDATE")
|
|
{
|
|
msg += $"\nGiven Checksum: {givenCheckNo}";
|
|
msg += $"\nThey do{(givenCheckNo == checksum ? "" : "n't")} match";
|
|
}
|
|
|
|
Console.WriteLine(msg);
|
|
}
|
|
|