1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
library EncryptLib;
uses
SysUtils,
ShareMem,
Classes;
var
KeyCode : String;
function Trans(Ch1,Ch2: Char;Sens:smallint): Char;
const Alphanum='-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var a,b,r, l:integer;
begin
l:=Length(Alphanum);
a:=Pos(Ch1,Alphanum)-1;
b:=Pos(Ch2,Alphanum)-1;
r:=(a+b*sens);
if r<0 then r:=l+r;
if r>l then r:=r-l;
Result := Alphanum[r+1];
end;
function Code(S:string):string;stdcall;export;
var I,J: Integer;
S2:string;
begin
S2:='';
if (KeyCode<>'') and (S<>'') then
begin
J := 1;
for I:=1 to Length(s) do
begin
S2:=S2+Trans(S[i],KeyCode[J],-1);
J:=(J mod Length(KeyCode)) + 1;
end;
end;
Result:=S2;
end;
function Decode(S:string):string;stdcall;export;
var I,J: integer;
S2:string;
begin
S2:='';
if (KeyCode<>'') and (S<>'') then
begin
J := 1;
for I:=1 to length(S) do
begin
S2:=S2+Trans(S[i],KeyCode[J],1);
J:=(J mod Length(KeyCode)) + 1;
end;
end;
Result:=S2;
end;
procedure SetKeyCode(S:String);stdcall; export;
begin
KeyCode := S;
end;
exports SetKeyCode,Code,Decode;
{$R *.res}
begin
end. |
Partager