# VBForums CodeBank > CodeBank - Other >  [DELPHI] - Encrypting String Values

## Madboy

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

or view the 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;
```

----------


## Madboy

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

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

*Encrypt:*


```
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:*


```
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;
```

----------


## conipto

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

----------


## Madboy

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

----------

