/// <summary> /// Decode a file /// </summary> /// <param name="filepath">the file path</param> /// <returns>The decoded string</returns> public string DecodeSingleByteXORFile(string[] text, StringHelper.StringType stringType) { string bestString = string.Empty; double bestScore = -1; foreach (string line in text) { string ret = this.DecodeSingleByteXOR(line, stringType); double retScore = this.GetFrequencyScore(ret); if (bestScore < 0 || (retScore >= 0 && retScore < bestScore)) { bestScore = retScore; bestString = ret; } } return(bestString.Trim()); }
/// <summary> /// Decode a string encrypted via a single character /// </summary> /// <param name="encryptedString"></param> /// <param name="stringType">The type of the string</param> /// <returns></returns> public string DecodeSingleByteXOR(string encryptedString, StringHelper.StringType stringType) { byte[] parsedString; switch (stringType) { case StringHelper.StringType.Hex: parsedString = StringHelper.ConvertHexStringToByteArray(encryptedString); break; case StringHelper.StringType.String: parsedString = Encoding.ASCII.GetBytes(encryptedString); break; default: parsedString = StringHelper.ConvertHexStringToByteArray(encryptedString); break; } int character = -1; string message = DecodeSingleByteXOR(parsedString, out character); return(message); }