我正在编写一个简单的 rc4 加密/解密实用程序作为第一个项目。我一直试图将给定的字符串转换为字节数组,然后可以由核心算法进行操作。如何在功能 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 "-" ""
在 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();
}