I think it's just ging to be something stupid that I've missed since the program itself runs, though doesn't solve the decrypted text. I've included the text from the decrypted file below the code and any help would be great.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Frequency_Analysis
{
class Program
{
static void Main(string[] args)
{
//array to hold the english language letters
char[] aLetter = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
//variable that holds the amount of words in the text
int wCount = 0;
//Read the task_2 text file into lines array
string[] lines = System.IO.File.ReadAllLines(@"task_2.txt");
foreach (string line in lines)
{
//creates a new string builder for the string 'line'
StringBuilder b = new StringBuilder(line);
int i = 0;
//Prints the encrypted text to console screen
Console.WriteLine("Encrypted text");
Console.Write("\n" + line);
Console.WriteLine("\n");
//initializes a new instance of the KeyValuePair structure with the specified key and value
foreach (KeyValuePair<char, int> letter in GetLetterCounts(line).OrderByDescending(letter => letter.Value))
{
//Character checker
if (char.IsLetterOrDigit(letter.Key))
{
//prints out the letter and how many times its occured
Console.WriteLine("Letter " + letter.Key + " : " + letter.Value);
//replaces the current letter with the english letter equivalent
b.Replace(letter.Key, aLetter[i]);
i++;
}
//checks for spacing
else if (letter.Key == ' ')
{
//puts the values of the letter into word count
wCount = letter.Value;
}
}
//prints out the amount of words to the console
Console.Write("\nTotal Words: " + wCount);
Console.WriteLine("\n");
//prints the string builders to console
Console.WriteLine(b + "\n");
}
//keep window open til user is finished
Console.WriteLine("Press any key to finish");
System.Console.ReadKey();
}
//create dictionary function
static Dictionary<char, int> GetLetterCounts(string myString)
{
//Contains char and intager
Dictionary<char, int> letter = new Dictionary<char, int>();
//loop to check each character inside the string
foreach (char c in myString)
//checks to see if character is within
if (letter.ContainsKey(c))
{
//increment myDict character by one
letter[c]++;
}
else
{
//makes the characters have a count of one, if its sent to 0 it undercounts the letters and words
letter[c] = 1;
}
//Returns the value
return letter;
}
}
}
BERMN GWNDN BUUBANOG WZNARTIVUWZHD PBD B QZTJAN RQ NMZKNOGIV UZHGRAZBI ZOGNOG, GWRJTW ZGD ZLUANDDZROZDGZH NSNHJGZRO QRAEBKN B MNAV HINBA ZKNB RQ ZGD OBGJAN. ZG DNNLNK GR EN B DRAG RQ LRODGNA, RA DVLERI ANUANDNOGZOT B LRODGNA, RQ B
QRAL PWZHW ROIV B KZDNBDNK QBOHV HRJIK HROHNZMN. ZQ Z DBV GWBG LV DRLNPWBG NSGABMBTBOG ZLBTZOBGZRO VZNIKNK DZLJIGBONRJD UZHGJAND RQ BO RHGRUJD, B KABTRO, BOK B WJLBO HBAZHBGJAN, Z DWBII ORG EN JOQBZGWQJI GR GWN DUZAZG RQ GWN GWZOT. B UJIUV, GNOGBHINK WNBK DJALRJOGNK B TARGNDXJN BOK DHBIV ERKV PZGW AJKZLNOGBAV PZOTD, EJG ZG PBD GWN
TNONABI RJGIZON RQ GWN PWRIN PWZHW LBKN ZG LRDG DWRHFZOTIV QAZTWGQJI.