-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompressCrypt.Mod
More file actions
41 lines (36 loc) · 1.12 KB
/
Copy pathCompressCrypt.Mod
File metadata and controls
41 lines (36 loc) · 1.12 KB
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
(* ETH Oberon, Copyright 2001 ETH Zuerich Institut fuer Computersysteme, ETH Zentrum, CH-8092 Zuerich.
Refer to the "General ETH Oberon System Source License" contract available at: http://www.oberon.ethz.ch/ *)
MODULE CompressCrypt; (** portable *) (* ejz *)
IMPORT Files, Strings, Compress;
PROCEDURE *Decrypt(VAR Rin: Files.Rider; nIn: LONGINT; VAR Rout: Files.Rider; key: ARRAY OF CHAR; VAR res: INTEGER);
VAR
i, n: LONGINT;
ch: CHAR;
BEGIN
n := Strings.Length(key); i := 0;
WHILE i < nIn DO
Files.Read(Rin, ch);
Files.Write(Rout, CHR( (ORD(ch)+ORD(key[i MOD n])) MOD 256 ) );
INC(i)
END;
res := Compress.Done
END Decrypt;
PROCEDURE *Encrypt(VAR Rin: Files.Rider; nIn: LONGINT; VAR Rout: Files.Rider; key: ARRAY OF CHAR; VAR res: INTEGER);
VAR
i, n: LONGINT;
ch: CHAR;
BEGIN
n := Strings.Length(key); i := 0;
WHILE i < nIn DO
Files.Read(Rin, ch);
Files.Write(Rout, CHR( (ORD(ch)-ORD(key[i MOD n])) MOD 256 ) );
INC(i)
END;
res := Compress.Done
END Encrypt;
PROCEDURE Install*;
BEGIN
Compress.Decrypt := Decrypt;
Compress.Encrypt := Encrypt
END Install;
END CompressCrypt.