J'écris un simple utilitaire de cryptage/décryptage rc4 en tant que premier projet. Je suis bloqué en essayant de convertir la chaîne donnée en un tableau d'octets qui peuvent ensuite être manipulés par l'algorithme de base. Comment convertir une chaîne en un tableau d'octets dans f # fonctionnel?F #: Conversion d'une chaîne en un tableau d'octets
//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 "-" ""
Pour votre information en C#, il ressemble à:
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();
}
Il était le premier que je avais besoin. Text.Encoding.ASCII.GetBytes (décrypté) – telesphore4