summaryrefslogtreecommitdiff
path: root/system/std.zusatz/1.8.7/src/crypt
blob: b04728a319662c8131bf370be3464056348c97a9 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(* ------------------- VERSION 2 vom 21.04.86 ------------------- *)
PACKET cryptograf DEFINES                     (* Autor: J.Liedtke *)

  crypt ,
  decrypt :
 
TEXT VAR char , in buffer, out buffer ;
INT VAR in pos , key index ;
DATASPACE VAR scratch space ;
FILE VAR in, out;
 
PROC crypt (TEXT CONST file, key) :
 
  open (file) ;
  initialize crypt (key) ;
  WHILE NOT eof REP
    read char ;
    crypt char ;
    write char
  PER ;
  close (file) .
 
crypt char :
  char := code (( character + random char + key char ) MOD 250) ;
  IF key index = LENGTH key
    THEN key index := 1
    ELSE key index INCR 1
  FI .
 
character   : code (char) .
 
random char : random (0,250).
 
key char    : code (key SUB key index) .
 
ENDPROC crypt ;
 
PROC decrypt (TEXT CONST file, key) :
 
  open (file) ;
  initialize crypt (key) ;
  WHILE NOT eof REP
    read char ;
    decrypt char ;
    write char
  PER ;
  close (file) .
 
decrypt char :
  char := code (( character - random char - key char ) MOD 250) ;
  IF key index = LENGTH key
    THEN key index := 1
    ELSE key index INCR 1
  FI .
 
character   : code (char) .
 
random char : random (0,250) .
 
key char    : code (key SUB key index) .
 
ENDPROC decrypt ;
 
PROC initialize crypt (TEXT CONST key) :
 
  INT VAR random key := 0 ;
  FOR key index FROM 1 UPTO LENGTH key REP
    random key := (random key + code (key SUB key index)) MOD 32000
  PER ;
  initialize random (random key) ;
  key index := 1
 
ENDPROC initialize crypt ;
 
PROC open (TEXT CONST source file) :
 
  in := sequential file (input, source file) ;
  getline (in, in buffer) ;
  in pos := 1 ;
  forget (scratch space) ; 
  scratch space := nilspace ; 
  out := sequential file (output, scratch space) ;
  out buffer := "" .
 
ENDPROC open ;
 
PROC close (TEXT CONST source file) :
 
  IF out buffer <> ""
    THEN putline (out, out buffer)
  FI ;
  forget (source file, quiet) ;
  copy (scratch space, source file) ;
  forget (scratch space) .
 
ENDPROC close ;
 
BOOL PROC eof :
 
  IF in pos > LENGTH in buffer
    THEN eof (in)
    ELSE FALSE
  FI
 
ENDPROC eof ;
 
PROC read char :
 
  IF in pos > 250
    THEN getline (in, in buffer) ;
         in pos := 1 ;
         read char
  ELIF in pos > LENGTH in buffer
    THEN in pos := 1 ;
         getline (in, in buffer) ;
         char := ""13""
    ELSE char := in buffer SUB in pos ;
         in pos INCR 1
  FI .
 
ENDPROC read char ;
 
PROC write char :
 
  IF char = ""13""
    THEN putline (out, out buffer) ;
         out buffer := ""
    ELSE out buffer CAT char
  FI ;
  IF LENGTH out buffer = 250
    THEN putline (out, out buffer) ;
         out buffer := ""
  FI .
 
ENDPROC write char ;
 
ENDPACKET cryptograf ;