home *** CD-ROM | disk | FTP | other *** search
- Crypt listing 1
-
- 10 REM
- 20 REM A quick random number coding device
- 30 REM
- 40 INPUT "File to be coded:";C$
- 50 INPUT "File for output:";D$
- 60 OPEN C$ FOR INPUT AS #1
- 70 OPEN D$ FOR OUTPUT AS #2
- 80 INPUT "Key:";K
- 90 RANDOMIZE K
- 100 INPUT "Encode or Decode";A$
- 110 A$=LEFT$(A$,1)
- 120 IF A$="E" OR A$="e" THEN A=1: GOTO 180
- 130 IF A$="D" OR A$="d" THEN A=-1 ELSE 100
- 140 REM
- 150 REM This is the Q$, set up for text files. R is the length
- 160 REM R1 is the length minus 1 computed now to save repeated calculation
- 170 REM
- 180 Q$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- 190 Q$=Q$+"1234567890!@#$%^&*()-=_+[]{};:`~,./<>?|\ '"+CHR$(34)
- 200 R=LEN(Q$)
- 210 R1=R-1
- 220 REM
- 230 REM Begin here
- 240 REM
- 250 IF EOF(1) THEN 490
- 260 X$=INPUT$(1,#1)
- 270 L=INSTR(Q$,X$)
- 280 IF L=0 THEN Y$=X$: GOTO 410
- 290 REM
- 300 REM Find a random number
- 310 REM
- 320 GOSUB 440
- 330 Z%=INT(R*Q/256)
- 340 T=L+(A*Z%)
- 350 REM
- 360 REM Adjust the parameters to be between 1 and r
- 370 REM
- 380 IF T<=0 THEN T=T+R1
- 390 IF T>=R THEN T=T-R1
- 400 Y$=MID$(Q$,T,1)
- 410 PRINT #2,Y$;
- 420 PRINT X$,X,Y$,T
- 430 GOTO 250
- 440 REM
- 450 REM Random number generator section. Output a value between 0-255 in Q
- 460 REM
- 470 Q=INT(256*RND)
- 480 RETURN
- 490 CLOSE #1,#2
- 500 END
-
- crypt listing 2
- è10 REM
- 20 REM A cellular automata machine
- 30 REM
- 40 DEFINT A-Z
- 50 W=60
- 60 DIM R(256)
- 70 DIM A(1000,2)
- 80 Y=1:Y1=0
- 90 INPUT "Key:";K$
- 100 REM
- 110 REM Place the key in array by converting it to ASCII code
- 120 REM
- 130 FOR X=1 TO LEN(K$)
- 140 H$=MID$(K$,X,1)
- 150 A(X,Y1)=ASC(H$)
- 160 NEXT X
- 170 REM
- 180 REM Main section of the program
- 190 REM
- 200 REM Begin by getting a random number between 0 and 255
- 210 REM
- 220 GOSUB 550
- 230 R(Q)=R(Q)+1
- 240 REM
- 250 REM Print out the array
- 260 REM
- 270 FOR X=0 TO W+1
- 280 Z=A(X,Y1)
- 290 IF Z<32 THEN Z=32
- 300 PRINT CHR$(Z);
- 310 NEXT X
- 320 PRINT
- 330 REM
- 340 REM Print out the statistics if a key is touched
- 350 REM
- 360 A$=INKEY$
- 370 IF A$="" THEN 200
- 380 REM First the individual occurences
- 390 E#=0!
- 400 FOR X=0 TO 255
- 410 E#=E#+R(X)
- 420 PRINT CHR$(X);R(X),
- 430 NEXT X
- 440 E1#=E#/256!
- 450 Q#=0!
- 460 REM Next calculate the chi-squared and print it out
- 470 FOR X=0 TO 255
- 480 Q#=Q#+ABS(R(X)-E1#)^2
- 490 NEXT X
- 500 PRINT "Difference:";Q#
- 510 PRINT
- 520 PRINT "Difference per time step:";Q#/E#
- 540 GOTO 220
- 550 REM
- 560 REM Random number subroutine. Updates cells and outputs Qè570 REM
- 580 FOR X=1 TO W
- 590 A(X,Y)=A(X-1,Y1) XOR (A(X,Y1) OR A(X+1,Y1))
- 600 NEXT X
- 610 REM Complete the circle by updating the ends
- 620 A(0,Y)=A(W+1,Y1) XOR (A(0,Y1) OR A(1,Y1))
- 630 A(W+1,Y)=A(W,Y1) XOR (A(W+1,Y1) OR A(0,Y1))
- 640 Q=A(0,Y)
- 650 K=Y:Y=Y1:Y1=K
- 660 RETURN
-
- crypt listing 3
-
- 10 REM
- 20 REM A cellular automata coding machine
- 30 REM
- 40 DEFINT A-Z
- 50 W=30
- 60 DIM R(256)
- 70 DIM A(1000,2)
- 80 Y=1:Y1=0
- 90 INPUT "Key:";K$
- 100 REM
- 110 REM Place the key in array by converting it to ASCII code
- 120 REM
- 130 FOR X=1 TO LEN(K$)
- 140 H$=MID$(K$,X,1)
- 150 A(X,Y1)=ASC(H$)
- 160 NEXT X
- 170 INPUT "File to be coded:";C$
- 180 INPUT "File for output:";D$
- 190 OPEN C$ FOR INPUT AS #1
- 200 OPEN D$ FOR OUTPUT AS #2
- 210 INPUT "Encode or Decode";A$
- 220 A$=LEFT$(A$,1)
- 230 IF A$="E" OR A$="e" THEN A=1: GOTO 300
- 240 IF A$="D" OR A$="d" THEN A=-1 ELSE 210
- 250 REM
- 260 REM This is the Q$, set up for text files. R is the length
- 270 REM r1 is the length minus 1 computed now
- 280 REM to save repeated calculations
- 290 REM
- 300 Q$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- 310 Q$=Q$+"1234567890!@#$%^&*()-=_+[]{};:`~,./<>?|\ '"+CHR$(34)
- 320 R=LEN(Q$)
- 330 R1=R-1
- 340 REM
- 350 REM Begin here
- 360 REM
- 370 IF EOF(1) THEN 560
- 380 X$=INPUT$(1,#1)
- 390 L=INSTR(Q$,X$)
- 400 IF L=0 THEN Y$=X$: GOTO 530
- 410 REM
- 420 REM Find a random numberè430 REM
- 440 GOSUB 580
- 450 Z%=INT(R*Q/256)
- 460 T=L+(A*Z%)
- 470 REM
- 480 REM Adjust the parameters to be between 1 and r
- 490 REM
- 500 IF T<=0 THEN T=T+R1
- 510 IF T>=R THEN T=T-R1
- 520 Y$=MID$(Q$,T,1)
- 530 PRINT #2,Y$;
- 540 PRINT X$,L,Y$,T
- 550 GOTO 370
- 560 CLOSE #1,#2
- 570 END
- 580 REM
- 590 REM Random number subroutine. Updates cells and outputs Q
- 600 REM
- 610 FOR X=1 TO W
- 620 A(X,Y)=A(X-1,Y1) XOR (A(X,Y1) OR A(X+1,Y1))
- 630 NEXT X
- 640 REM Complete the circle by updating the ends
- 650 A(0,Y)=A(W+1,Y1) XOR (A(0,Y1) OR A(1,Y1))
- 660 A(W+1,Y)=A(W,Y1) XOR (A(W+1,Y1) OR A(0,Y1))
- 670 Q=A(0,Y)
- 680 K=Y:Y=Y1:Y1=K
- 690 RETURN