You are doing TONS of string manipulation. Each string change takes up a little memory.
First, if you want to keep the structure you should switch from ArrayList
to List<int>
to contain your list of guesses and only use strings when you are forced to when you pass the keystring in to the decrypt function. Also, never use ArrayList
for modern programming, the only reason the class exists is for backward compatibility with old code. If you really must have a list that can accept anything use a List<object>
instead but using a specific list like List<int>
or List<string>
works much better.
However posiblesClves3
is totally unnecessary, you can just put the decrypt code right inside the for loop. You can also compare to the number 0xFFFFFF
in your for loop and you don't need the string comparison. Also you can use .ToString("X6")
instead of .ToString(X).PadLeft('0',6)
which saves you a extra string per loop.
Here is a very stripped down version of your code with using as few strings as possible.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;
namespace ProyectoEspiasSergioSolorzanoAriste
{
class Program
{
static void Main(string[] args)
{
var encryptedText = "7iuYS0z/aIp/f+dNjJCkLULBY+3K5F3B4BYBSNoKEc0g8M3lcFFECqHMb2E9rv12sUCjJA/ve1uCxGNL/feZjEFBpANh0tAs/5+97+L+kuL0wZI78Ux40XhEbyTSIoEfGY4GsM7uce7PzZ1sYSb9Kql/0j6Qu9RGWXqJMPF9XYYv5FxgNLJ8y8bzoGcZVf6h7k95a5YoX6KP9T20TMPJcqUf+nEYTo2Y54K6vU8pAUC0UxTnLlxakzCT+QBIhXl0SRS6/36rbkSppNYd0GLq5HRN+/BEFvGF+0p9fRZQ5hyqEmy8OEFqFtSBeA0LotyszSHq1ZqJA56rqXjoSZZm6ljcITolbx101eNH7x0S1zjzNv1dovIsaONQfbt6ZUlldxFDSVrQrTrsso32LIO8JWGsUCp6mc8VhL5hAA8xY7d8cwSoDzlm7+46fqP6pEnL/dArS9As+vE6ZWh+JYmDQJ5pEs2KDEVTQb5o4rFB79QE8EmmysvsC23baZXsO5Qa1GqeMcUZ2mORTHUs1GTKhqY1DpOGtXbykpXs+0RlmNzvIEASf5yOqOnHOvhzxGGzjvrEiAc61t6DB/frmGlokVZEuZcziwcb883jCRwXOb21R/AtCaf4A1VHbVq/xoeS/XRExgOle6xZGibNMUHrvprtnj9Hhdwz4H0p6m6T3sR6GAzhzAl12MzMdG4VM6QFJsSND5nNQRlHByYTZ5ebWTupKbSIDPCaOu4FydZuJj4=";
Console.WriteLine("After Encryption Text = " +
encryptedText + "/n");
var solucionesDecrypt = new List<string>(0xFFFFFF); //Presize the list to hold all the values.
for (int i = 0; i <= 0xFFFFFF; i++)
{
var decryptedText = ClsTripleDES.Decrypt(encryptedText, i.ToString("X6"));
solucionesDecrypt.Add(decryptedText);
}
foreach (string decryptedText in solucionesDecrypt)
{
Console.WriteLine("After Decryption Text = " + decryptedText + "/n");
}
Console.ReadLine();
}
}
}