$OPTION EXPLICIT
$INCLUDE "rapidq.inc"
DECLARE SUB bc
DIM form AS QFORM
DIM button AS QBUTTON
button.PARENT = form
button.CAPTION = "encrypt a file"
button.onclick = bc
form.center
form.SHOWMODAL
SUB bc
DIM opendialog AS QOPENDIALOG
DIM file1 AS QFILESTREAM
DIM file2 AS QFILESTREAM
DIM linesread AS INTEGER
DIM cwl AS INTEGER
DIM templine$ AS STRING
DIM b AS INTEGER
DIM outfname$ AS STRING
DIM plainline$ AS STRING
DIM cryptchar$ AS STRING
DIM textchar$ AS STRING
DIM codechar$ AS STRING
DIM codeword$ AS STRING
DIM cryptline$ AS STRING
codeword$ = "tigerlily"
IF opendialog.EXECUTE THEN
file1.OPEN(opendialog.filename, fmopenread)
outfname$ = opendialog.filename
outfname$ = LEFT$(outfname$, INSTR(outfname$, ".")-1)
outfname$ = outfname$ + ".cde"
file2.OPEN(outfname$, fmcreate)
linesread = 0
WHILE NOT file1.eof
plainline$ = file1.readline()
linesread = linesread + 1
IF linesread = 1 THEN
file2.writeline(plainline$)
ELSE
IF LEFT$(plainline$, 1)="'" THEN
ELSE
templine$=plainline$+"#"
FOR b = INT(RND*6) TO 6+INT(RND*20)
templine$=templine$+CHR$(48+INT(RND*74))
NEXT b
templine$ = reverse$(templine$)
cryptline$ = ""
FOR b = 1 TO LEN(templine$)
cwl = b MOD LEN(codeword$)
IF cwl = 0 THEN
cwl = LEN(codeword$)
END IF
codechar$ = MID$(codeword$, cwl, 1)
textchar$ = MID$(templine$, b, 1)
cryptchar$ = CHR$(40 + (ASC(textchar$) - 40) + (ASC(codechar$) - 40))
cryptline$ = cryptline$ + cryptchar$
NEXT b
file2.writeline (cryptline$)
END IF
END IF
WEND
file1.CLOSE
file2.CLOSE
SHOWMESSAGE outfname$ +" created"
END IF
END SUB
|