![]() |
|||||
gwbasic311 random numbers for code
|
|||||
|
USEING the gwbasic random number generater to make a rudimentry codeing program.The first program makes a host text file,
in which the coded messages will be enbedded.This file will be 75 lines loge,each line will be 75 characters long, this file
is named "blog.txt".The second program is the encodeing and decodeing one.When run you will have three options ,make new message,decode
message,or exit to windows.You will be asked to enter a number,to be used for the random generation,it will be the key to
decode the message.To make the message,after entering the number key,just type in the message.Do not use a question mark in
the message,as it is used to see the end of a line,by the program.On option 2 you will be asked to enter the number key to
decode the message.It must be the same as used to code the message.While decodeing one line of text will be displayed on each
enter. The way the program workes is,for each character in the message, two random numbers are used,one number is the line the
other is the position in that line,where the character will be placed in the host file.The process is reversed to decode the
message. The text file can be posted on a blog,and the message read by someone wiht the program and knows the number key.This program
does not check if a random number is used more than once.If the message is not small some characters may be over writen by
other characters. These programs will work in gwbasic 3.11,gwbasic 3.23 and Qbasic. However Qbasic's random generater makes different numbers then the earlier ver's of basic.A message coded by Qbasic can't
be decoded by the other ver's of gwbasic. The next program is the one that makes the host file 10
'MAKFILE[.TXT MAKES FILE 75X75=5625 20
CLS:FILES 25
C=5625 30
INPUT"NUMBER FOR RND ";R:O$="BLOG.TXT" 40
OPEN "O",#1, O$ 45
RANDOMIZE R 50
FOR A=1 TO C 55
B=RND*126:IF B<48 THEN 55 60
PRINT #1,CHR$(B);:NEXT A 80
CLOSE 100
END the next program is the codeing program 10
'CODE-1.TXT 20
PRINT CHR$(10):INPUT "NEW MEMMO = 1, OR READ CODED MEMMO = 2,or exit = 3 ";GO:IF GO<1 OR GO>3 THEN 20 30
ON GO GOTO 40,1000,2000 40
CLEAR ,,2000:DIM A$(50):I$="BLOG.TXT" 50
INPUT"number ";R 60
CLS 70
OPEN "R",#1, I$, 75:IF LOF(1)=0 THEN CLOSE:KILL I$:GOTO 60 80
CLS:PRINT"TYPE MEMMO TWO ENTERS TO CODE" 90
FOR B=1 TO 100 100
LINE INPUT" ",A$(B):IF LEN (A$(B))=0 GOTO 120 110
NEXT 120
FOR C=1 TO B-1 130
PRINT"#";C;:PRINT A$(C) 140
NEXT C 150
INPUT "CHANGE ANY LINES YES=1 ,OR ADD LINES=2";H:IF H=1 THEN GOTO 290 160
IF H=2 THEN GOTO 100 165
A$(B)="QQQ" 170
INPUT "ENTER TO CODE";CR 180
FIELD #1, 75 AS N$:RANDOMIZE R'START RND 190
FOR D=1 TO B 200
A$(D)=A$(D)+"?" 210
FOR E=1 TO LEN(A$(D)) 220
E$=MID$(A$(D),E,1) 230
X=INT(RND*74)+1:Y=INT(RND*74)+1 240
GET #1,X:MID$(N$,Y,1)=E$ 250
PUT #1,X 260
NEXT E 270
NEXT D 280
CLOSE:CLEAR:run 290
INPUT"LINE # TO CHANGE";F:IF F>C-1 THEN 290 300
PRINT A$(F):LINE INPUT " ",A$(F) 310
GOTO 120 1000
CLEAR ,,2000 1010
INPUT"number ";R 1020
CLS:I$="BLOG.TXT" 1030
OPEN "R",#1, I$, 75:IF LOF(1)=0 THEN CLOSE:KILL I$:GOTO 1020 1040
FIELD #1, 75 AS N$:RANDOMIZE R'START RND 1045
CLS 1050
FOR E=1 TO 1000:ON ERROR GOTO 1140 1060
X=INT(RND*74)+1:Y=INT(RND*74)+1 1070
GET #1,X:E$=MID$(N$,Y,1):IF E$="?" THEN GOTO 1090 1080
D$=D$+E$:NEXT E 1090
IF D$="QQQ" THEN PRINT"THE END":CLOSE:run 1100
PRINT D$; 1110
INPUT"",BS$ 1120
D$="" 1130
GOTO 1060 1140
PRINT"wrong key ":run 2000
SYSTEM As mentioned before the longer the message the more times some numbers will be used more then once,overwriting other characters
in the message.Below is a program that keeps track of the random numbers used,and when a set of numbers has been used before
it sends the prog back to make another set of numbers. 10
PRINT"ctrl break to EXIT":DIM M(75,75)'array to hold numbers 20
INPUT "number for random ";R'sum-2 30
RANDOMIZE(R) 40
FOR I=1 TO 1000 50
A=CINT(RND*80):IF A>75 THEN 50 60
IF A<1 THEN 50'no zeros 70
B=CINT(RND*78):IF B>75 THEN 70 80
IF B<1 THEN 70 90
IF M(A,B)=1 THEN GOTO 200'check array if A,B used go to 200 95
M(A,B)=1'load array A,B 100
PRINT A;B, 110
NEXT I 120
PRINT"overrites = ";D:RUN 200
D=D+1'number of overwrites that would have happened 210
GOTO 50'skip to 50,don't use these numbers The
program that codes the message can be modified to stop overwrites.I'll post a new one soon. any
questions E-mail me |
||||
|
The
program below check for number repeats.Line 45 sets up the array to store the numbers in.Line 230 Checks
the array to see if the numbers have been used.If they have been used,a new set is generated. Line
235 makes each d(x,y) equal to 1 10 'CODE-2.TXT check
for overrites 20 PRINT CHR$(10):INPUT
"NEW MEMMO = 1, OR READ CODED MEMMO = 2,or exit to windows = 3 ";GO:IF GO<1 OR GO>3 THEN 20 30 ON GO GOTO 40,1000,2000 40 CLEAR ,,2000:DIM A$(500):I$="BLOG.TXT" 45 DIM D(75,75)'array
to check for overrites 50 INPUT"number ";R 60 CLS 70 OPEN "R",#1, I$, 75:IF
LOF(1)=0 THEN CLOSE:KILL I$:GOTO 60 80 CLS:PRINT"TYPE MEMMO
TWO ENTERS TO CODE" 90 FOR B=1 TO 100 100 LINE INPUT" ",A$(B):IF
LEN (A$(B))=0 GOTO 120 110 NEXT 120 FOR C=1 TO B-1 130 PRINT"#";C;:PRINT
A$(C) 140 NEXT C 150 INPUT "CHANGE ANY
LINES YES=1 ,OR ADD LINES=2";H:IF H=1 THEN GOTO 290 160 IF H=2 THEN GOTO
100 165 A$(B)="QQQ" 170 INPUT "ENTER TO CODE";CR 180 FIELD #1, 75 AS N$:RANDOMIZE
R'START RND 190 FOR D=1 TO B 200 A$(D)=A$(D)+"?" 210 FOR E=1 TO LEN(A$(D)) 220 E$=MID$(A$(D),E,1) 230 X=INT(RND*74)+1:Y=INT(RND*74)+1:IF
D(X,Y)>0 THEN 230'chech for overrites 235 D(X,Y)=1'load array
to check 240 GET #1,X:MID$(N$,Y,1)=E$ 250 PUT #1,X 260 NEXT E 270 NEXT D 280 CLOSE:CLEAR:RUN 290 INPUT"LINE # TO CHANGE";F:IF
F>C-1 THEN 290 300 PRINT A$(F):LINE
INPUT " ",A$(F) 310 GOTO 120 1000 CLEAR ,,2000 1005 DIM D(75,75)'array
to check for overrites 1010 INPUT"number ";R 1020 CLS:I$="BLOG.TXT" 1030 OPEN "R",#1, I$,
75:IF LOF(1)=0 THEN CLOSE:KILL I$:GOTO 1020 1040 FIELD #1, 75 AS
N$:RANDOMIZE R'START RND 1045 CLS 1050 FOR E=1 TO 1000:ON
ERROR GOTO 1140 1060 X=INT(RND*74)+1:Y=INT(RND*74)+1:IF
D(X,Y)>0 THEN 1060 1065 D(X,Y)=1'LOAD ARRAY
to check 1070 GET #1,X:E$=MID$(N$,Y,1):IF
E$="?" THEN GOTO 1090 1080 D$=D$+E$:NEXT E 1090 IF D$="QQQ" THEN
PRINT"THE END":CLOSE:RUN 1100 PRINT D$; 1110 INPUT"",BS$ 1120 D$="" 1130 GOTO 1060 1140 PRINT"wrong key
":RUN 2000 SYSTEM |
||||
|
|
||||