From d482ed88724b9dc84ee5f2b70252d4aab6b837d9 Mon Sep 17 00:00:00 2001 From: Debulois Date: Wed, 19 Oct 2022 12:43:49 +0200 Subject: Initial commit --- WinKeyRecover/keyManager/CheckIsValid.cs | 41 ++++++++++++++++++++++++++ WinKeyRecover/keyManager/CountMissingChars.cs | 27 +++++++++++++++++ WinKeyRecover/keyManager/GeneratePattern.cs | 37 +++++++++++++++++++++++ WinKeyRecover/keyManager/GetMissingPositons.cs | 26 ++++++++++++++++ WinKeyRecover/keyManager/ReplaceMissings.cs | 32 ++++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 WinKeyRecover/keyManager/CheckIsValid.cs create mode 100644 WinKeyRecover/keyManager/CountMissingChars.cs create mode 100644 WinKeyRecover/keyManager/GeneratePattern.cs create mode 100644 WinKeyRecover/keyManager/GetMissingPositons.cs create mode 100644 WinKeyRecover/keyManager/ReplaceMissings.cs (limited to 'WinKeyRecover/keyManager') diff --git a/WinKeyRecover/keyManager/CheckIsValid.cs b/WinKeyRecover/keyManager/CheckIsValid.cs new file mode 100644 index 0000000..5b6775b --- /dev/null +++ b/WinKeyRecover/keyManager/CheckIsValid.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinKeyRecover +{ + internal class CheckIsValid + { + private string key; + + public bool CheckKey(char[] validChars, string key) + { + this.key = key.ToUpper(); + + if (this.key != string.Empty + && this.key.Length == 29 + && this.key.Contains('*') + ) + { + for (int i = 0; i < key.Length; i++) + { + if (this.key[i] != '-' + && this.key[i] != '*' + && !validChars.Contains(this.key[i]) + ) + { + return false; + } + } + } + else + { + return false; + } + + return true; + } + } +} diff --git a/WinKeyRecover/keyManager/CountMissingChars.cs b/WinKeyRecover/keyManager/CountMissingChars.cs new file mode 100644 index 0000000..b92b357 --- /dev/null +++ b/WinKeyRecover/keyManager/CountMissingChars.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace WinKeyRecover +{ + internal class CountMissingChars + { + private int missing = 0; + + public int Count(string key) + { + for (int i = 0; i < key.Length; i++) + { + if (key[i] == '*') + { + missing++; + } + } + + return missing; + } + } +} diff --git a/WinKeyRecover/keyManager/GeneratePattern.cs b/WinKeyRecover/keyManager/GeneratePattern.cs new file mode 100644 index 0000000..dbd0809 --- /dev/null +++ b/WinKeyRecover/keyManager/GeneratePattern.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace WinKeyRecover +{ + internal class GeneratePattern + { + private readonly List generatedPatterns = new List(); + + public List Generate(char[] patternChars, int patternLength, string patternBase = "") + { + if (patternLength == 1) + { + for (int i = 0; i < patternChars.Length; i++) + { + generatedPatterns.Add(patternBase + patternChars[i]); + } + } + else + { + for (int i = 0; i < patternChars.Length; i++) + { + string patternNew = patternBase + patternChars[i]; + _ = Generate(patternChars, patternLength - 1, patternNew); + } + } + + return generatedPatterns; + } + } +} + + diff --git a/WinKeyRecover/keyManager/GetMissingPositons.cs b/WinKeyRecover/keyManager/GetMissingPositons.cs new file mode 100644 index 0000000..14bf8e8 --- /dev/null +++ b/WinKeyRecover/keyManager/GetMissingPositons.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinKeyRecover +{ + internal class GetMissingPositions + { + private readonly List missingPosition = new List(); + + public List GetPositions(string key) + { + for (int i = 0; i < key.Length; i++) + { + if (key[i] == '*') + { + missingPosition.Add(i); + } + } + + return missingPosition; + } + } +} diff --git a/WinKeyRecover/keyManager/ReplaceMissings.cs b/WinKeyRecover/keyManager/ReplaceMissings.cs new file mode 100644 index 0000000..6e5e1ae --- /dev/null +++ b/WinKeyRecover/keyManager/ReplaceMissings.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinKeyRecover +{ + internal class ReplaceMissings + { + private readonly string key; + private readonly List missingPosition; + + public ReplaceMissings(string key, List missingPosition) + { + this.key = key; + this.missingPosition = missingPosition; + } + + public string Replace(string pattern) + { + char[] finalKey = new List(key).ToArray(); + + for (int i = 0; i < pattern.Length; i++) + { + finalKey[missingPosition[i]] = pattern[i]; + } + + return new string(finalKey); + } + } +} -- cgit v1.2.3