diff --git a/EANValidator/EANValidator.sln b/EANValidator/EANValidator.sln new file mode 100644 index 0000000..d713e14 --- /dev/null +++ b/EANValidator/EANValidator.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32112.339 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EANValidator", "EANValidator\EANValidator.csproj", "{6FB2C33C-C18F-425A-BE4C-9176F622EA7C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6FB2C33C-C18F-425A-BE4C-9176F622EA7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FB2C33C-C18F-425A-BE4C-9176F622EA7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FB2C33C-C18F-425A-BE4C-9176F622EA7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FB2C33C-C18F-425A-BE4C-9176F622EA7C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {05DCC730-96C0-43C6-A882-F091287D481B} + EndGlobalSection +EndGlobal diff --git a/EANValidator/EANValidator/EANValidator.csproj b/EANValidator/EANValidator/EANValidator.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/EANValidator/EANValidator/EANValidator.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/EANValidator/EANValidator/Program.cs b/EANValidator/EANValidator/Program.cs new file mode 100644 index 0000000..052d830 --- /dev/null +++ b/EANValidator/EANValidator/Program.cs @@ -0,0 +1,70 @@ +// 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 == "q") + { + Console.WriteLine("Bye bye!"); + return; + } + + if (input == null || input == "") continue; + + 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)) + { + 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); +} +