Convert from Delphi to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mel Weaver

    Convert from Delphi to C#

    Hello,
    I'm trying to convert these to functions to c#

    const
    C1 = 52845;
    C2 = 22719;

    function Encrypt(const S: String; Key: Word): String;
    var
    I: byte;
    begin
    setlength(resul t,length(s));
    for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(Result[I]) + Key) * C1 + C2;
    end;
    end;

    function Decrypt(const S: String; Key: Word): String;
    var
    I: byte;
    begin
    setlength(resul t,length(s));
    for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(S[I]) + Key) * C1 + C2;
    end;
    end;

    Thanks
    Mel


  • needin4mation@gmail.com

    #2
    Re: Convert from Delphi to C#

    See if this helps:





    Comment

    • Nick Malik [Microsoft]

      #3
      Re: Convert from Delphi to C#

      really lousy encryption.

      You may want to consider using the encryption routines in .Net. The one you
      show is really bad. Not much better than a secret decoder ring
      (http://en.wikipedia.org/wiki/Secret_decoder_ring) on a very slightly better
      scale. Still, I wouldn't trust actual sensitive data to it.

      --
      --- Nick Malik [Microsoft]
      MCSD, CFPS, Certified Scrummaster


      Disclaimer: Opinions expressed in this forum are my own, and not
      representative of my employer.
      I do not answer questions on behalf of my employer. I'm just a
      programmer helping programmers.
      --
      "Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
      news:u%23dcfUKt FHA.616@TK2MSFT NGP11.phx.gbl.. .[color=blue]
      > Hello,
      > I'm trying to convert these to functions to c#
      >
      > const
      > C1 = 52845;
      > C2 = 22719;
      >
      > function Encrypt(const S: String; Key: Word): String;
      > var
      > I: byte;
      > begin
      > setlength(resul t,length(s));
      > for I := 1 to Length(S) do begin
      > Result[I] := char(byte(S[I]) xor (Key shr 8));
      > Key := (byte(Result[I]) + Key) * C1 + C2;
      > end;
      > end;
      >
      > function Decrypt(const S: String; Key: Word): String;
      > var
      > I: byte;
      > begin
      > setlength(resul t,length(s));
      > for I := 1 to Length(S) do begin
      > Result[I] := char(byte(S[I]) xor (Key shr 8));
      > Key := (byte(S[I]) + Key) * C1 + C2;
      > end;
      > end;
      >
      > Thanks
      > Mel
      >[/color]


      Comment

      Working...