{ *********************************************************************** }
{ }
{ Source Code of Delphi on Village Library }
{ Encryption Standard Unit }
{ }
{ Copyright (c) 2000-2004 Village Software Corporation }
{ }
{ *********************************************************************** }
unit Encryption;
interface
uses
SysUtils;
function EnCrypt(CharCode : string):string;
function DeCrypt(CharCode : string):string;
implementation
function ChangeChar(DesCodeChar:byte;huruf:char):char;
begin
result:=chr(ord(huruf)+DesCodeChar);
end;
function DeChangeChar(DesCodeChar:byte;huruf:char):char;
begin
result:=chr(ord(huruf)-DesCodeChar);
end;
function DeCrypt(CharCode : string):String;
var
LongStr,
i,DesCodeCrypt : byte;
Sort,DeKeyWord : string;
UnChange : char;
begin
LongStr := LENGTH(CharCode);
DesCodeCrypt:=ord(CharCode[1])+ord(CharCode[LongStr]);
for i:=2 to LongStr-2 do
begin
if (i mod 2)=0 then
begin
Sort:=CharCode[i]+CharCode[i+1];
UnChange:=DeChangeChar(DesCodeCrypt,sort[2]);
DeKeyWord:=DeKeyWord+UnChange;
end;
end;
Result:=DeKeyWord;
end;
function Encrypt(CharCode : String):string;
var
LongStr,
LongStrKey,
i,a,DesCodeCrypt : byte;
insert,CodeCrypt,KeyWord : string;
CharFirst,CharLast : char;
begin
LongStr := LENGTH(CharCode);
CodeCrypt := CharCode[1]+CharCode[LongStr];
DesCodeCrypt:=ord(CharCode[1])+ord(CharCode[LongStr]);
LongStrKey:=2;
a:=1;
for i:=1 to LongStr do
begin
CharFirst:= ChangeChar(DesCodeCrypt,CodeCrypt[a]);
CharLast:= ChangeChar(DesCodeCrypt,CharCode[i]);
insert:=CharFirst+CharLast;
KeyWord:=KeyWord+insert;
if a>=LongStrKey then
a:=1
else
a:=a+1;
end;
Result:=CharCode[1]+KeyWord+CharCode[LongStr];
end;
end.
contoh hasilnya, bila memasukkan karakter :
"ini adalah fungsi encryption dan decryption asli bikinanku di tahun 2004"
hasilnya :
i Ñ Ñ½ þÑ þÑ þÑ ½Ñ Ñ Ñ Ñ½ Ñ
Tidak ada komentar:
Posting Komentar