title: Convert Move function in Pascal to equivalent in JavaScript
body: <p>The legacy systems use a user control component (UserControl) which in its code has the Decode function, which in turn uses the Move function. I would like to convert pascal code to JavaScript to use the same user control in an API. Is it possible to convert Move function in Pascal to equivalent in JavaScript?</p>
  
  <pre><code>function Decrypt(const S: ansistring; Key: Word): ansistring;
  begin
    Result := InternalDecrypt(PreProcess(S), Key);
  end;
  
  function InternalDecrypt(const S: ansistring; Key: Word): ansistring;
  var
    I:    Word;
    Seed: int64;
  begin
    Result := S;
    Seed   := Key;
    for I := 1 to Length(Result) do
    begin
      Result[I] := AnsiChar(byte(Result[I]) xor (Seed shr 8));
      Seed      := (byte(S[I]) + Seed) * word(C1) + word(C2);
    end;
  end;
  
  function PreProcess(const S: ansistring): ansistring;
  var
    SS: ansistring;
  begin
    SS     := S;
    Result := '';
    while SS &lt;&gt; '' do
    begin
      Result := Result + Decode(Copy(SS, 1, 4));
      Delete(SS, 1, 4);
    end;
  end;
  
  function Decode(const S: UTF8String): UTF8String;
  const
    Map: array[0..255] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
      54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
      3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
      20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30,
      31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
      46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0);
  var
    I: longint;
  begin
    case Length(S) of
      2:
      begin
        I := Map[Ord(S[1])] + (Map[Ord(S[2])] shl 6);
        SetLength(Result, 1);
        Move(I, Result[1], Length(Result));
      end;
      3:
      begin
        I := Map[Ord(S[1])] + (Map[Ord(S[2])] shl 6) + (Map[Ord(S[3])] shl 12);
        SetLength(Result, 2);
        Move(I, Result[1], Length(Result));
      end;
      4:
      begin
        I := Map[Ord(S[1])] + (Map[Ord(S[2])] shl 6) + (Map[Ord(S[3])] shl 12) + (Map[Ord(S[4])] shl 18);
        SetLength(Result, 3);
        Move(I, Result[1], Length(Result));
      end
    end;
  end;
  
  procedure Move(const Source; var Dest; count : Integer );
  var
      S, D: PChar;
      I: Integer;
  begin
      S := PChar(@Source);
      D := PChar(@Dest);
      if S = D then Exit;
      if Cardinal(D) &gt; Cardinal(S) then
          for I := count-1 downto 0 do
              D[I] := S[I]
      else
          for I := 0 to count-1 do
              D[I] := S[I];
  end;
  </code></pre>