bastien.monsarrat 6 years ago
parent
commit
99f7ccde3a
4 changed files with 120 additions and 0 deletions
  1. 6 0
      Adv2015.sln
  2. 9 0
      D11.1/D11.csproj
  3. 97 0
      D11.1/Program.cs
  4. 8 0
      D11.1/Properties/launchSettings.json

+ 6 - 0
Adv2015.sln

@@ -41,6 +41,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D10.1", "D10.1\D10.1.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D10.2", "D10.2\D10.2.csproj", "{F7E0673F-04A5-414D-9DD6-7E442DEAAE24}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D11", "D11.1\D11.csproj", "{D4001022-526D-4548-BB09-6F9DFD03B743}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -123,6 +125,10 @@ Global
 		{F7E0673F-04A5-414D-9DD6-7E442DEAAE24}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{F7E0673F-04A5-414D-9DD6-7E442DEAAE24}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{F7E0673F-04A5-414D-9DD6-7E442DEAAE24}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D4001022-526D-4548-BB09-6F9DFD03B743}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D4001022-526D-4548-BB09-6F9DFD03B743}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D4001022-526D-4548-BB09-6F9DFD03B743}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D4001022-526D-4548-BB09-6F9DFD03B743}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D11.1/D11.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D11._1</RootNamespace>
+  </PropertyGroup>
+
+</Project>

+ 97 - 0
D11.1/Program.cs

@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace D11._1
+{
+    class Program
+    {
+        static string Increment(string input)
+        {
+            if (input.Length == 0) return input;
+
+            StringBuilder sb = new StringBuilder();
+
+            var pos = input.Length - 1;
+            var nchar = input[pos] + 1;
+
+            if (nchar == 'i' || nchar == 'l' || nchar == 'o')
+                nchar++;
+
+            if (nchar > 'z')
+            {
+                nchar = 'a';
+                var inc = Increment(input.Substring(0, pos));
+                sb.Append(inc);
+                sb.Append((char) nchar);
+            }
+            else
+            {
+                sb.Append(input.Substring(0, pos));
+                sb.Append((char) nchar);
+            }
+
+            return sb.ToString();
+        }
+
+        static bool IsValid(string pwd)
+        {
+            bool hasIncreasing = false;
+            bool hasForbiddenLettres = false;
+            int repetitions = 0;
+            bool repetitionExists = false;
+
+            char last = '\0', lalast = '\0';
+            int same = 1;
+            foreach (var c in pwd)
+            {
+                if (c == 'i' || c == 'l' || c == 'o')
+                {
+                    hasForbiddenLettres = true;
+                    break;
+                }
+
+                if (c == last) same++;
+                else same = 1;
+
+                if (same == 4) repetitionExists = true;
+                if (repetitionExists == false && same == 2)
+                {
+                    repetitions++;
+                    repetitionExists = repetitions >= 2;
+                }
+
+                if (lalast + 1 == last && last + 1 == c)
+                    hasIncreasing = true;
+
+                lalast = last;
+                last = c;
+            }
+
+            return hasForbiddenLettres == false && hasIncreasing && repetitionExists;
+        }
+
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            string input = args[0];
+
+            input = NexPassword(input);
+            Console.WriteLine($"The next password is : {input}");
+
+            input = NexPassword(input);
+            Console.WriteLine($"The next password is : {input}");
+        }
+
+        private static string NexPassword(string input)
+        {
+            bool isValid = false;
+            do
+            {
+                input = Increment(input);
+                isValid = IsValid(input);
+            } while (isValid == false);
+            return input;
+        }
+    }
+}

+ 8 - 0
D11.1/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D11.1": {
+      "commandName": "Project",
+      "commandLineArgs": "vzbxkghb"
+    }
+  }
+}