예제 #1
0
        public string Crack(List <string> plaintext, string target)
        {
            string match = "";

            byte[] plaintext_bytes   = new byte[plaintext.Count * KEY_LENGTH];
            byte[] plaintext_lengths = new byte[plaintext.Count];
            byte[] target_bytes      = new byte[KEY_LENGTH];
            byte[] match_bytes       = null;

            int encoded;

            for (int i = 0; i < plaintext.Count; i++)
            {
                encoded = Encoding.Default.GetBytes(plaintext[i], 0, plaintext[i].Length, plaintext_bytes, KEY_LENGTH * i);
                plaintext_lengths[i] = (byte)encoded;
            }

            var hexBytes = HexHelper.StringToByteArray(target);

            for (int i = 0; i < hexBytes.Length; i++)
            {
                target_bytes[i] = hexBytes[i];
            }

            CrackImpl(plaintext_bytes, plaintext_lengths, target_bytes, out match_bytes);
            int end;

            for (end = 0; end < match_bytes.Length && match_bytes[end] != 0; end++)
            {
                ;
            }

            match = Encoding.Default.GetString(match_bytes, 0, end);

            return(match);
        }