我正在寫一個簡單的rc4加密/解密實用程序作爲第一個項目。我堅持試圖將給定的字符串轉換爲可由核心算法操縱的字節數組。如何將字符串轉換爲函數f#中的字節數組?F#:將字符串轉換爲字節數組
//From another thread
let private replace find (repl : string) (str : string) = str.Replace(find, repl)
//let private algorithm bytes = blah blah blah
let Encrypt (decrypted : string) =
decrypted.Chars
|> Array.map(fun c -> byte.Parse(c)) // This line is clearly not working
// |> algorithm
|> BitConverter.ToString
|> replace "-" ""
FYI在C#中,它看起來像:
public static string Encrypt(string decrypted)
{
byte[] bytes = new byte[decrypted.Length];
for (int i = 0; i < decrypted.Length; ++i)
bytes[i] = (byte)decrypted[i];
Algorithm(ref bytes);
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
這是我所需要的第一個。 Text.Encoding.ASCII.GetBytes(解密) – telesphore4 2009-07-21 21:23:06