-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENCRYPT.BAS
395 lines (371 loc) · 7.83 KB
/
ENCRYPT.BAS
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
'function declarations
DECLARE FUNCTION decodestring$ (str1$, pass$)
DECLARE FUNCTION encodestring$ (str1$, pass$)
DECLARE FUNCTION boxinput$ (n$, y%, pass%)
DECLARE SUB start ()
DECLARE SUB draws ()
DECLARE SUB clears ()
DECLARE SUB encode ()
DECLARE SUB decode ()
DECLARE SUB statusbox (n$, y%, size%)
DECLARE SUB percent (done&, total&, y%)
'keys
CONST backspc = 8, enter = 13, htab = 9, esc = 27
CONST left = 75, right = 77, up = 72, down = 80
CONST uplt = 71, uprt = 73, dnlt = 79, dnrt = 81
CONST insert = 82, home = 73, pageup = 71, del = 83, endk = 81, pagedn = 79
CONST kf1 = 59, kf2 = 60, kf3 = 61, kf4 = 62, kf5 = 63, kf6 = 64, kf7 = 65, kf8 = 66, kf9 = 67, kf10 = 68, kf11 = 133, kf12 = 134
'constants
CONST loadsize = 1000
'start
CLS
draws
GOTO mainmenu
comeback:
SELECT CASE sel%
CASE 0
clears
LOCATE 5, 25
COLOR 14, 0
PRINT "ENCRYPT FILE:";
COLOR 15, 1
file$ = boxinput$("File Name:", 6, 0)
COLOR 7, 0
LOCATE 20, 4
PRINT "* Longer passwords give better protection.";
LOCATE 21, 4
PRINT "** Multi-encoded file are more secure."
DO
COLOR 15, 1
pass$ = boxinput$("Password:", 6, 1)
COLOR 15, 1
pas2$ = boxinput$("Retype Password:", 6, 1)
COLOR 7, 2
LOCATE 18, 6
PRINT "Password doesn't match.";
LOOP UNTIL pass$ = pas2$
clears
COLOR 15, 1
out$ = boxinput$("Encrypted file name:", 6, 0)
start
encode
CASE 1
clears
LOCATE 5, 25
COLOR 14, 0
PRINT "DECRYPT FILE:";
COLOR 15, 1
file$ = boxinput$("Encrypted File Name:", 6, 0)
COLOR 7, 0
LOCATE 20, 4
PRINT "* An Encrypted file may have password of 1-55 characters.";
LOCATE 21, 4
PRINT "** An Encrypted file may be Multi-Encrypted file."
DO
COLOR 15, 1
pass$ = boxinput$("Password:", 6, 1)
COLOR 15, 1
pas2$ = boxinput$("Retype Password:", 6, 1)
COLOR 7, 2
LOCATE 18, 6
PRINT "Password doesn't match.";
LOOP UNTIL pass$ = pas2$
clears
COLOR 15, 1
out$ = boxinput$("Decrypted file name:", 6, 0)
start
decode
CASE ELSE
END SELECT
mainmenu:
clears
LOCATE 4, 25, 0
PRINT "Select Option:";
sel% = 0
GOSUB dispoptmain
DO
k$ = ""
WHILE k$ = ""
k$ = INKEY$
WEND
SELECT CASE k$
CASE CHR$(esc)
CLS
COLOR 15, 0
PRINT "Thank You for using FILE ENCRYPT."
PRINT
PRINT
PRINT "developed by: Subhajit Sahu"
k$ = INPUT$(1)
SYSTEM
CASE (CHR$(0) + CHR$(up))
sel% = (sel% + 1) MOD 2
GOSUB dispoptmain
CASE (CHR$(0) + CHR$(down))
sel% = (sel% + 1) MOD 2
GOSUB dispoptmain
CASE ELSE
END SELECT
LOOP UNTIL k$ = CHR$(enter)
GOTO comeback
dispoptmain:
IF (sel% = 0) THEN
COLOR 15, 14
LOCATE 5, 30, 0
PRINT "- Encrypt File";
COLOR 15, 0
LOCATE 6, 30, 0
PRINT "- Decrypt File";
ELSE
COLOR 15, 0
LOCATE 5, 30, 0
PRINT "- Encrypt File";
COLOR 15, 14
LOCATE 6, 30, 0
PRINT "- Decrypt File";
END IF
RETURN
FUNCTION boxinput$ (n$, y%, pass%)
COLOR 13, 4
LOCATE y%, 10, 0
PRINT "Õ"; STRING$(58, "Í"); "¸";
LOCATE y% + 1, 10, 0
PRINT "³ "; n$; STRING$(57 - LEN(n$), " "); "³";
LOCATE y% + 2, 10, 0
PRINT "Ã"; STRING$(58, "Ä"); "´";
LOCATE y% + 3, 10, 0
PRINT "³"; STRING$(58, " "); "³";
LOCATE y% + 4, 10, 0
PRINT "À"; STRING$(58, "Í"); "Ù";
COLOR 14, 0
y1% = y% + 3
LOCATE y1%, 12, 0
PRINT STRING$(56, " ");
LOCATE y1%, 12, 1
a$ = ""
DO
k% = ASC(INPUT$(1))
IF (k% = backspc) THEN
IF (LEN(a$) <> 0) THEN
x% = 11 + LEN(a$)
LOCATE y1%, x%, 0
PRINT " ";
a$ = LEFT$(a$, LEN(a$) - 1)
x% = x%
LOCATE y1%, x%, 1
END IF
ELSEIF (k% = esc) THEN
a$ = ""
LOCATE y1%, 12, 0
PRINT STRING$(56, " ");
LOCATE y1%, 12, 1
ELSEIF (k% = enter) THEN
EXIT DO
ELSEIF (k% >= 32 AND k% <= 126) THEN
IF (LEN(a$) < 55) THEN
b$ = CHR$(k%)
x% = 12 + LEN(a$)
LOCATE y1%, x%, 0
IF (pass%) THEN PRINT "è"; ELSE PRINT b$;
a$ = a$ + b$
x% = x% + 1
LOCATE y1%, x%, 1
END IF
END IF
LOOP
COLOR 7, 0
FOR k% = 0 TO 4
LOCATE y% + k%, 10
PRINT STRING$(60, " ");
NEXT
boxinput$ = a$
END FUNCTION
SUB clears
COLOR 15, 0
FOR i% = 4 TO 23
LOCATE i%, 2
PRINT SPACE$(78);
NEXT
END SUB
SUB decode
SHARED file$, pass$, out$, oldchksum&, newchksum&
OPEN "B", #1, file$
OPEN "B", #2, out$
total& = LOF(1)
IF (total& = 0) THEN
clears
LOCATE 8, 5
COLOR 7, 2
PRINT "File "; file$; " does not exist.";
GOTO enddecode
END IF
dat$ = INPUT$(7, #1)
IF (dat$ <> "ENCODED") THEN
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "File "; file$; " is not an Encrypted file.";
LOCATE 10, 7, 0
PRINT "Press any key";
k$ = INPUT$(1)
GOTO enddecode
END IF
chksum$ = INPUT$(8, #1)
p& = 1
statusbox "DECRYPTING:", 5, 9
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "Decrypting of file "; file$; " is in progress.";
LOCATE 10, 7, 0
PRINT "Decrypted file is "; out$; ".";
total& = LOF(1) - 16
done& = 0
DO
dat$ = INPUT$(loadsize, #1)
dat$ = decodestring$(dat$, pass$)
PUT #2, p&, dat$
p& = p& + loadsize
done& = done& + loadsize
percent done&, total&, 15
LOOP UNTIL LEN(dat$) < loadsize
chkgot$ = MKL$(oldchksum&) + MKL$(newchksum&)
CLOSE #1, #2
IF (chkgot$ = chksum$) THEN
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "Decrypting of file "; file$; " is complete. ";
LOCATE 10, 7, 0
PRINT "Decrypted file is "; out$; ".";
LOCATE 11, 7, 0
PRINT "Press any key"
k$ = INPUT$(1)
ELSE
KILL out$
clears
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "FATAL ERROR: File "; file$; " could not be decrypted.";
LOCATE 10, 7, 0
PRINT "File "; out$; " could not be created. Check Password.";
LOCATE 11, 7, 0
PRINT "Press any key";
k$ = INPUT$(1)
END IF
enddecode:
END SUB
FUNCTION decodestring$ (str1$, pass$)
SHARED passpoint%, oldchksum&, newchksum&
b$ = ""
FOR i% = 1 TO LEN(str1$)
newchar% = ASC(MID$(str1$, i%, 1))
newchksum& = newchksum& + newchar%
oldchar% = (512 - 128 + (newchar% - ASC(MID$(pass$, passpoint% + 1, 1)))) MOD 256
oldchksum& = oldchksum& + oldchar%
b$ = b$ + CHR$(oldchar%)
passpoint% = (passpoint% + 1) MOD (LEN(pass$))
NEXT
decodestring$ = b$
END FUNCTION
SUB draws
PRINT "É"; STRING$(78, "Í"); "»"
PRINT "º"; STRING$(33, " "); "FILE ENCRYPT"; STRING$(33, " "); "º"
PRINT "Ì"; STRING$(78, "Í"); "¹"
FOR i% = 4 TO 23
PRINT "º"; STRING$(78, " "); "º"
NEXT
PRINT "È"; STRING$(78, "Í"); "¼";
END SUB
SUB encode
SHARED file$, pass$, out$, oldchksum&, newchksum&
OPEN "B", #1, file$
OPEN "B", #2, out$
total& = LOF(1)
IF (total& = 0) THEN
clears
LOCATE 8, 5
COLOR 7, 2
PRINT "File "; file$; " does not exist.";
GOTO endencode
END IF
dat$ = "ENCODED" + STRING$(8, 0)
PUT #2, 1, dat$
p& = 16
statusbox "ENCRYPTING:", 5, 9
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "Encrypting of file "; file$; " is in progress.";
LOCATE 10, 7, 0
PRINT "Encrypted file is "; out$; ".";
total& = LOF(1)
done& = 0
DO
dat$ = INPUT$(loadsize, #1)
dat$ = encodestring$(dat$, pass$)
PUT #2, p&, dat$
p& = p& + loadsize
done& = done& + loadsize
percent done&, total&, 15
LOOP UNTIL LEN(dat$) < loadsize
dat$ = MKL$(oldchksum&) + MKL$(newchksum&)
PUT #2, 8, dat$
CLOSE #1, #2
COLOR 7, 2
LOCATE 9, 7, 0
PRINT "Encrypting of file "; file$; " is complete. ";
LOCATE 10, 7, 0
PRINT "Encrypted file is "; out$; ".";
LOCATE 11, 7, 0
PRINT "Press any key";
k$ = INPUT$(1)
endencode:
END SUB
FUNCTION encodestring$ (str1$, pass$)
SHARED passpoint%, oldchksum&, newchksum&
b$ = ""
FOR i% = 1 TO LEN(str1$)
oldchar% = ASC(MID$(str1$, i%, 1))
oldchksum& = oldchksum& + oldchar%
newchar% = (oldchar% + ASC(MID$(pass$, passpoint% + 1, 1)) + 128) MOD 256
newchksum& = newchksum& + newchar%
b$ = b$ + CHR$(newchar%)
passpoint% = (passpoint% + 1) MOD (LEN(pass$))
NEXT
encodestring$ = b$
END FUNCTION
SUB percent (done&, total&, y%)
LOCATE y%, 7, 0
COLOR 13, 6
sz% = CINT((done& / total&) * 65 + .5)
IF (sz% > 65) THEN sz% = 65
PRINT STRING$(sz%, "°");
COLOR 15, 0
END SUB
SUB start
SHARED passpoint%, oldchksum&, newchksum&
passpoint% = 0
oldchksum& = 0
newchksum& = 0
END SUB
SUB statusbox (n$, y%, size%)
COLOR 15, 2
LOCATE y%, 5, 0
PRINT "Õ"; STRING$(68, "Í"); "¸";
LOCATE y% + 1, 5, 0
PRINT "³ "; n$; STRING$(67 - LEN(n$), " "); "³";
LOCATE y% + 2, 5, 0
PRINT "Ã"; STRING$(68, "Ä"); "´";
FOR i% = 0 TO size%
LOCATE y% + 3 + i%, 5, 0
PRINT "³"; STRING$(68, " "); "³";
NEXT
ly% = y% + 4 + size%
LOCATE ly%, 5, 0
PRINT "À"; STRING$(68, "Ä"); "Ù";
ly% = ly% - 4
COLOR 14, 3
LOCATE ly%, 6, 0
PRINT "Ú"; STRING$(66, "Ä"); "¿";
LOCATE ly% + 1, 6, 0
PRINT "³"; STRING$(66, " "); "³";
LOCATE ly% + 2, 6, 0
PRINT "À"; STRING$(66, "Í"); "Ù";
END SUB