Enkripsi dan Deskripsi


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function Decrypt(S: string): string;
function Encrypt(S: string): string;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.Encrypt(S: string): string;
var
Angka, i: Integer;
begin
Result := ‘ ‘ + S;
Angka := 32;
for i := 1 to Length(S) do begin
Angka := Angka + Ord(S[i]);
while Angka > 126 do
Angka := Angka – 95;
end;
Result[1] := Chr(Angka);
for i := 2 to Length(Result) do begin
Angka := Ord(Result[i]) + Ord(Result[i – 1]);
while Angka > 126 do
Angka := Angka – 95;
Result[i] := Chr(Angka);
end;
end;

function TForm1.Decrypt(S: string): string;
var
Angka1, Angka2,
Angka, i: Integer;
begin
Result := S;
for i := Length(S) downto 2 do begin
Angka1 := Ord(S[i]);
Angka2 := Ord(S[i – 1]);
if Angka1 >= Angka2 then
Angka := Angka1 – Angka2
else
Angka := (Angka1 + 95) – Angka2;
while Angka < 32 do
Angka := Angka + 95;
Result[i] := Chr(Angka);
end;
Delete(Result, 1, 1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text := Encrypt(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit3.Text := Decrypt(Edit2.Text);
end;

end.

TransCODE Software



Satu pemikiran pada “Enkripsi dan Deskripsi

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s