-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmycrypt.pas
More file actions
38 lines (32 loc) · 719 Bytes
/
mycrypt.pas
File metadata and controls
38 lines (32 loc) · 719 Bytes
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
unit mycrypt;
interface
function CryptString(Str, Key: String): String;
function DeCryptString(Str, Key: String): String;
implementation
function CryptString(Str, Key: String): String;
var
i, q: Integer;
begin
for i := 1 to Length(Str) do
begin
q := (Ord(Str[i]) + (Ord(Key[(Pred(i) mod Length(Key)) + 1]) - Ord('0')));
if q >= 256 then
Dec(q, 256);
Str[i] := Chr(q);
Result := Str;
end;
end;
function DeCryptString(Str, Key: String): String;
var
i, q: Integer;
begin
for i := 1 to Length(Str) do
begin
q := (Ord(Str[i]) - (Ord(Key[(Pred(i) mod Length(Key)) + 1]) - Ord('0')));
if q < 0 then
Inc(q, 256);
Str[i] := Chr(q);
Result := Str;
end;
end;
end.