-1

I have a program that checks millions of results to brute force a 3DES password, but I want it to show me just the correct one instead of millions of results of gibberish also, so I was thinking of ways to get rid of the results with nonASCII characters and tried with ifs like.

[Posible Solution that worked for me]

//check for words that might appear on the decripted text, removing the ASCII just makes it easier but the result in my case did also have 3 redundant ascii as an extra so we couldnt make it that way, but it should normally work.

if(decryptedText.Contains("WORDS")||...lots)
{
   Console.WriteLine(key);
   Console.WriteLine("Correct Text ="+decryptedText);
}

I also tried turning it all to ASCII, but it gives almost the same and the same number of millions of results since the correct result had 3 redundant non ASCII characters at the end .

var textoLimpio = LimpiarASCII.ReturnCleanASCII(decryptedText);

example of a gibberish result

Community
  • 1
  • 1
Sergio
  • 55
  • 7
  • Why are you loading everything into memory? 17M strings for keys, 17 M for decrypted values? You can find a more efficient way. Still, by compiling to 64 bit, you should not hit any memory limit. What is the memory usage of your program when it crashes? Did you observe it? – Oguz Ozgul Apr 12 '20 at 21:01
  • Windows crashed so i had to restart the computer, i have 16GB of RAM but the computer always crashes at the middle, Visual Studio showed in memory usage in the graphic that appears it was full, and by the way if i only do 1M possibilities it works. – Sergio Apr 12 '20 at 21:04
  • You don't have to fill all the decryption output into an ArrayList though. Who is going to read all those garbage (16.999.999 of them will be garbage, while only one of them will be a valid string). I am no expert, but trying to read how it should be done will be better I guess. – Oguz Ozgul Apr 12 '20 at 21:05
  • the problem is i dont know what to do to exclude all the gibberish, i tried if(!decryptedText.Contains("?")) but i doesnt work – Sergio Apr 12 '20 at 21:10
  • 1
    @SergioSolórzanoAriste the `?` is not a `?`, it is what the console uses for a non printable character. Try checking for characters that are not in the ASCII printable range. If you find one it is likely your string is not a valid one. – Scott Chamberlain Apr 12 '20 at 21:47
  • Solved kind of, i tried lots of words the text given could contain, and key (clave in spanish) was on it, its a solution that needs a foreseer or a lot of luck but it works i guess, thanks for everyones help. – Sergio Apr 13 '20 at 18:46

1 Answers1

0

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();
        }
    }
}
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • thanks, this worked, i also erased solucionesDecrypt and just did an if(decryptedText.Contains("")){ WriteLine...} and tried lots of words and one worked after lots of tries, i dont have enough reputation to give you an up vote but i would if i could. – Sergio Apr 13 '20 at 20:29