Results 1 to 4 of 4

Thread: [DELPHI] - Encrypting String Values

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    [DELPHI] - Encrypting String Values

    You can find this article here: http://bdn.borland.com/article/0,1410,28325,00.html

    or view the code:

    Code:
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Button2: TButton;
        Edit3: TEdit;
        procedure Button1Click(Sender: TObject);
        function EnDeCrypt(const Value : String) : String;
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    function TForm1.EnDeCrypt(const Value : String) : String;
    var
      CharIndex : integer;
    begin
      Result := Value;
      for CharIndex := 1 to Length(Value) do
        Result[CharIndex] := chr(not(ord(Value[CharIndex])));
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit2.Text := EnDeCrypt(Edit1.Text);
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Edit3.Text := EnDeCrypt(Edit2.Text);
    end;

  2. #2

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: [DELPHI] - Encrypting String Values

    This example can also be used to achieve the same thing:

    Note: Edit the Random(x) value for different randon encryption

    Encrypt:
    Code:
    procedure Encrypt;
        var S:String;
        i:integer;
        Begin
           Randseed:= 12;
           S:= '';
           for i:=1 to length(txtMain.text) do
           Begin
              S:= S + chr(ord(txtMain.text[i]) + Random(10) + 1);
           end;
        txtMain.text:=S;
        end;
    Decrypt:
    Code:
    Procedure Decrypt;
        Var S:string;
        i:integer;
        Begin
           Randseed:= 12;
           S:= '';
           for i:=1 to length(txtMain.text) do
           Begin
              S:= S + chr(ord(txtMain.text[i]) - Random(10) - 1);
           end;
        txtMain.text:= S;
        end;

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: [DELPHI] - Encrypting String Values

    Is Delphi's random number generation only dependant on the seed value? Seems almost a risky way to go about it if it's not, it doesn't depend on hardware configuration, clock time, or anything else?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: [DELPHI] - Encrypting String Values

    There are many different methods, this is only basic. I had one before which truly encrypted the text. Handled large documents too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width