Im trying to decrypt a word which letters have been replaced with random other letters (but not 2 different letters into the same one).
The goal:
Im searching for a word which lenght and letter-pattern is known.
What I know:
The pattern itself means if searching for "guests" I know "123454" which shows the position of unique letters in this word. And for sure I know its an english word correctly written.
Software side:
I've created a DataGridView
which headers are titled by the pattern. I want to populate each Column
(pattern) with its possible combinations of all letters a-z
.
What I've tried:
Ill start at the end => I've successfully implemented a spell-checker. So in the end I thought about just going through the columns and check for each result to find the actual word.
From the starting point seen I've written this so far:
private string[] alpha = new string[] { "a", "b", "c", ..."z"};
private int[] digits = new int[] { 0, 1, 2, 3, 4,....9 };
private void bruteforce()
{
// Each Column
foreach(DataGridViewColumn col in dgvResults.Columns)
{
// HeaderText to CharArray to IntArray (-48 to switch from ASCII to INT).
int[] pattern = Array.ConvertAll(col.HeaderText.ToCharArray(), c => c - 48);
// Prepare an result-array with the same length as the pattern.
string[] resultSet = Enumerable.Repeat("-", pattern.Length).ToArray();
// For each digit 0-9.
foreach(int digit in digits)
{
// In pattern search for each digit and save the index.
int[] indexes = pattern.FindAllIndexof(digit);
// If index is found.
if(indexes.Length > 0)
{
// Custom function ReplaceAtIndex.
// Replace resultSet-Values at given Indexes with unique letter
resultSet.ReplaceAtIndex(indexes, alpha[digit]);
}
}
}
}
Current result:
A pattern of 0112344
will be saved (resultSet
) as abbcdee
.
Now I would need to loop the letters while staying on the same pattern.
This step feels even more complicated then the stuff before. I thought, before continuing blowing away my head, Im going to see if there are some genius guys out there on stackoverflow who can provide a shorter easier way (maybe some shortcuts with LINQ).
So please, is there anyone thinking "easy doin" about this who could help me? I appreciate every help in here. Thanks