public void MD5ST(List <Usuario> Base, int times) { List <Usuario> mock = new List <Usuario>(); List <double> elapsedTimes = new List <double>(); using (BaseConverter cc = new BaseConverter()){ for (int i = 0; i < times; i++) { var watchDe = System.Diagnostics.Stopwatch.StartNew(); mock = cc.ToMD5(Base, false); watchDe.Stop(); elapsedTimes.Add(watchDe.Elapsed.TotalMilliseconds); } } double average = elapsedTimes.Average(); double sumOfSquaresOfDifferences = elapsedTimes.Select(val => (val - average) * (val - average)).Sum(); double sd = Math.Sqrt(sumOfSquaresOfDifferences / elapsedTimes.Count()); Console.WriteLine("-----------------------------------------------------------------------------------------------------------------"); Console.WriteLine("Average Elaspsed time to convert base to MD5 (In " + times.ToString() + " samples): " + average + " Miliseconds"); Console.WriteLine("Standard deviation of time to convert base to MD5 (In " + times.ToString() + " samples): " + sd + " Miliseconds"); Console.WriteLine("-----------------------------------------------------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); }
static void Main(string[] args) { //Perguntar ao usuario o caminho do txt Console.Write("Please insert the absolute path of the base to be converted: "); string filePath = Console.ReadLine(); //Ler linhas do arquivo .txt que contem as senhas e os usuarios string[] lines = System.IO.File.ReadAllLines(filePath); //Init lista de usuarios List <Usuario> usuarios_as_is = new List <Usuario>(); List <Usuario> usuarios_decrypt = new List <Usuario>(); List <Usuario> usuarios_md5 = new List <Usuario>(); List <Usuario> usuarios_sha1 = new List <Usuario>(); List <Usuario> usuarios_sha256 = new List <Usuario>(); List <Usuario> usuarios_md5_salted = new List <Usuario>(); List <Usuario> usuarios_sha1_salted = new List <Usuario>(); List <Usuario> usuarios_sha256_salted = new List <Usuario>(); CaesarCypher CaesarC = new CaesarCypher(); Console.Clear(); Console.WriteLine("Decrypting selected base, please wait..."); //Itera sobre as linhas do arquivo para traduzir para uma List var watchDe = System.Diagnostics.Stopwatch.StartNew(); foreach (string line in lines) { Usuario temp = new Usuario(); Usuario asis = new Usuario(); asis.nome = line.Split("|")[0]; asis.senha = line.Split("|")[1]; usuarios_as_is.Add(asis); temp.nome = line.Split("|")[0]; temp.senha = line.Split("|")[1]; temp.senha = CaesarC.Decrypt(temp.senha); usuarios_decrypt.Add(temp); } watchDe.Stop(); Console.WriteLine("---------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to decrypt base: " + watchDe.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("---------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); Console.Clear(); Console.WriteLine("Loading the program, please wait..."); using (BaseConverter converter = new BaseConverter()) { usuarios_md5 = converter.ToMD5(usuarios_decrypt, false); usuarios_sha1 = converter.ToSHA1(usuarios_decrypt, false); usuarios_sha256 = converter.ToSHA256(usuarios_decrypt, false); usuarios_md5_salted = converter.ToMD5(usuarios_decrypt, true); usuarios_sha1_salted = converter.ToSHA1(usuarios_decrypt, true); usuarios_sha256_salted = converter.ToSHA256(usuarios_decrypt, true); } bool exit = false; while (!exit) { switch (ConsoleMenu.RunMenu()) { case "1": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_md5 = converter.ToMD5(usuarios_decrypt, false); watch.Stop(); Console.WriteLine("---------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to MD5: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("---------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "2": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_sha1 = converter.ToSHA1(usuarios_decrypt, false); watch.Stop(); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to SHA1: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("----------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "3": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_sha256 = converter.ToSHA256(usuarios_decrypt, false); watch.Stop(); Console.WriteLine("---------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to SHA256: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("---------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "4": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_md5_salted = converter.ToMD5(usuarios_decrypt, true); watch.Stop(); Console.WriteLine("-------------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to salted MD5: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("-------------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "5": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_sha1_salted = converter.ToSHA1(usuarios_decrypt, true); watch.Stop(); Console.WriteLine("--------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to salted SHA1: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("--------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "6": using (BaseConverter converter = new BaseConverter()) { var watch = System.Diagnostics.Stopwatch.StartNew(); usuarios_sha256_salted = converter.ToSHA256(usuarios_decrypt, true); watch.Stop(); Console.WriteLine("-------------------------------------------------------------------"); Console.WriteLine("Elaspsed time to convert base to salted SHA256: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("-------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "7": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"8": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"9": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"10": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"11": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"12": using (BaseValidator validator = new BaseValidator()) { Usuario temp = new Usuario(); Console.Clear(); Console.Write("User: "******"Password: "******"13": using (CaesarCypher cc = new CaesarCypher()) { var watch = System.Diagnostics.Stopwatch.StartNew(); cc.DecryptBase(lines); watch.Stop(); Console.WriteLine("---------------------------------------------------------"); Console.WriteLine("Elaspsed time to decrypt base: " + watch.Elapsed.TotalMilliseconds + " Miliseconds"); Console.WriteLine("---------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); } break; case "14": using (StressTest st = new StressTest()) { st.MD5ST(usuarios_decrypt, 30); } break; case "15": using (StressTest st = new StressTest()) { st.SHA1ST(usuarios_decrypt, 30); } break; case "16": using (StressTest st = new StressTest()) { st.SHA256ST(usuarios_decrypt, 30); } break; case "20": Console.Clear(); Console.WriteLine(" ----------------------------------------------------------------------------------------------"); Console.WriteLine("| Usuario | Senha |"); Console.WriteLine(" ----------------------------------------------------------------------------------------------"); foreach (var item in usuarios_decrypt) { Console.WriteLine("|" + item.nome + "|" + item.senha + "|"); } Console.WriteLine(" ----------------------------------------------------------------------------------------------"); Console.Write("Press any key to continue..."); Console.ReadKey(); break; case "q": Console.Clear(); exit = true; break; default: Console.WriteLine("Bad instruction"); Console.Write("Press any key to continue..."); Console.ReadKey(); break; } } }