public void DecodeCryptogram(string key) { byte[] result = new byte[cryptogramByte.Count]; byte[] pass = Encoding.ASCII.GetBytes(key); try { RC4Engine rc4 = new RC4Engine(); KeyParameter keyParam = new KeyParameter(pass); rc4.Init(true, keyParam); rc4.ProcessBytes(cryptogramByte.ToArray(), 0, cryptogramByte.Count, result, 0); } catch (Exception e) { Console.WriteLine(e.Message); } if (CheckDecryptedText(result)) { Console.Write("klucz: " + key + ": "); foreach (var c in result) { if (c != 0) { Console.Write((char)c); } } Console.WriteLine(); } }
public void ThreadRun() { int i = 0; byte[] clearText = new byte[kryptogram.Length]; string czescKlucza1 = ""; while (i <= szukaj.max) { i = szukaj.wykonane(); if (i <= szukaj.max) { czescKlucza1 = i.ToString("X"); while (czescKlucza1.Length < 8) { czescKlucza1 = "0" + czescKlucza1; } String klucz = czescKlucza1.ToLower() + czescKlucza2; try { RC4Engine rc4 = new RC4Engine(); KeyParameter keyParam = new KeyParameter(System.Text.Encoding.ASCII.GetBytes(klucz)); rc4.Init(false, keyParam); rc4.ProcessBytes(kryptogram, 0, kryptogram.Length, clearText, 0); } catch (Exception e) { } bool zgodne = true; for (int j = 0; j < clearText.Length; j++) { if (!alfabet.lista_znakow.Contains((char)clearText[j])) { zgodne = false; } } //jeśli znalazl dobry klucz if (zgodne) { Console.Write("Wiadomosc : "); foreach (byte x in clearText) { Console.Write("{0} ", (char)x); } Console.WriteLine(""); Console.WriteLine(" klucz: {0}",klucz); szukaj.ileZrobiono = szukaj.max; } } } }
public RC4(byte[] key) { rc4 = new RC4Engine(); rc4.Init(true, new KeyParameter(key)); }