-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCRYPT.PAS
91 lines (67 loc) · 2.23 KB
/
CRYPT.PAS
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
unit crypt;
interface
type
encryption_type = (NONE,
SIMPLE,
PURPLE, UNPURPLE,
COMPLEX,
DEBUGGING_ON);
var
CryptMask : byte;
Encryption : encryption_type;
procedure cryptinit(crypt_kind : encryption_type; seed : longint);
procedure cryptstr(var s : string);
implementation
procedure cryptinit(crypt_kind : encryption_type; seed : longint);
begin
CryptMask := seed AND $FF;
Encryption := crypt_kind;
if Encryption = COMPLEX then RandSeed := seed
end; { cryptinit }
{ cryptstr
Description:
Encrypts or decrypts a string. Since all encryption methods are based
on XOR, the same method both encrypts and decrypts.
If <method> is SIMPLE, the CryptMask is simply XORed with each byte in
the string.
If <method> is PURPLE, the CryptMask is changed each time after using it,
by adding to it the lowest three bits of the result of the last encrypted
byte. This way the mask changes frequently and dynamically in a way that
is difficult to predict.
If <method> is UNPURPLE, the same algorithm as PURPLE is used except that
the next CryptMask must be determined before altering the byte under
consideration.
if <method> is COMPLEX, a pseudorandom sequence is used to alter the
CryptMask. This can make prediction well-nigh impossible.
}
procedure cryptstr(var s : string);
var
nextmask : byte;
i : integer;
begin
case Encryption of
SIMPLE :
for i := 1 to length(s) do
s[i] := chr(ord(s[i]) XOR CryptMask);
PURPLE:
for i := 1 to length(s) do begin
s[i] := chr(ord(s[i]) XOR CryptMask);
inc(CryptMask, ord(s[i]) AND $7)
end;
UNPURPLE:
for i := 1 to length(s) do begin
nextmask := CryptMask + (ord(s[i]) AND $7);
s[i] := chr(ord(s[i]) XOR CryptMask);
CryptMask := nextmask
end;
COMPLEX :
for i := 1 to length(s) do begin
s[i] := chr(ord(s[i]) XOR CryptMask);
CryptMask := random($100)
end;
end { case }
end; { cryptstr }
begin
Encryption := NONE;
CryptMask := $55
end. { unit crypt }