Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per Gradbot's request, the final code looks like:</p> <p>1) I don't like the casts to byte</p> <p>2) The main algorithm function looks very un-functional</p> <p>Constructive criticism is welcome.</p> <p>Rc4.fs</p> <pre><code>#light open System open MiscUtils open StringUtils let private key = "Mykey"B let private byteMask = 0xff let private byteMax = byteMask let private algorithm (bytes : byte[]) = let mutable j = 0 let mutable i = 0 let mutable s = [| for c in 0 .. byteMax -&gt; (byte) c |] for i in 0 .. byteMax do j &lt;- (j + (int) (s.[i] + key.[i % key.GetLength(0)])) &amp;&amp;&amp; byteMask Swap (&amp;s.[i]) (&amp;s.[j]) i &lt;- 0 j &lt;- 0 for x in 0 .. bytes.Length - 1 do i &lt;- (i + 1) &amp;&amp;&amp; byteMask j &lt;- (j + (int) s.[i]) &amp;&amp;&amp; byteMask Swap (&amp;s.[i]) (&amp;s.[j]) let mutable t = (int)(s.[i] + s.[j]) &amp;&amp;&amp; byteMask bytes.[x] &lt;- bytes.[x] ^^^ s.[t] bytes let Encrypt (decrypted : string) = Text.Encoding.ASCII.GetBytes decrypted |&gt; algorithm |&gt; BitConverter.ToString |&gt; ToLower |&gt; Replace "-" "" let Decrypt (encrypted : string) = [| for i in 0 .. 2 .. encrypted.Length - 1 -&gt; Convert.ToByte(encrypted.Substring(i, 2), 16) |] |&gt; algorithm |&gt; System.Text.Encoding.ASCII.GetString </code></pre> <p>StringUtils.Fs</p> <pre><code>#light let Replace find (repl : string) (str : string) = str.Replace(find, repl) let ToLower (str : string) = str.ToLower() </code></pre> <p>MiscUtils.fs</p> <pre><code>#light let Swap (left : 'a byref) (right : 'a byref) = let temp = left left &lt;- right right &lt;- temp </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload