home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / CLDEC87.ZIP / CRYPTBAS.LTG < prev    next >
Encoding:
Text File  |  1987-11-23  |  4.4 KB  |  190 lines

  1. Crypt listing 1
  2.  
  3. 10 REM
  4. 20 REM A quick random number coding device
  5. 30 REM
  6. 40 INPUT "File to be coded:";C$
  7. 50 INPUT "File for output:";D$
  8. 60 OPEN C$ FOR INPUT AS #1
  9. 70 OPEN D$ FOR OUTPUT AS #2
  10. 80 INPUT "Key:";K
  11. 90 RANDOMIZE K
  12. 100 INPUT "Encode or Decode";A$
  13. 110 A$=LEFT$(A$,1)
  14. 120 IF A$="E" OR A$="e" THEN A=1: GOTO 180
  15. 130 IF A$="D" OR A$="d" THEN A=-1 ELSE 100
  16. 140 REM
  17. 150 REM This is the Q$, set up for text files. R is the length
  18. 160 REM R1 is the length minus 1 computed now to save repeated calculation
  19. 170 REM
  20. 180 Q$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  21. 190 Q$=Q$+"1234567890!@#$%^&*()-=_+[]{};:`~,./<>?|\ '"+CHR$(34)
  22. 200 R=LEN(Q$)
  23. 210 R1=R-1
  24. 220 REM
  25. 230 REM Begin here
  26. 240 REM
  27. 250 IF EOF(1) THEN 490
  28. 260 X$=INPUT$(1,#1)
  29. 270 L=INSTR(Q$,X$)
  30. 280 IF L=0 THEN Y$=X$: GOTO 410
  31. 290 REM
  32. 300 REM Find a random number
  33. 310 REM
  34. 320 GOSUB 440
  35. 330 Z%=INT(R*Q/256)
  36. 340 T=L+(A*Z%)
  37. 350 REM
  38. 360 REM Adjust the parameters to be between 1 and r
  39. 370 REM
  40. 380 IF T<=0 THEN T=T+R1
  41. 390 IF T>=R THEN T=T-R1
  42. 400 Y$=MID$(Q$,T,1)
  43. 410 PRINT #2,Y$;
  44. 420 PRINT X$,X,Y$,T
  45. 430 GOTO 250
  46. 440 REM
  47. 450 REM Random number generator section. Output a value between 0-255 in Q
  48. 460 REM
  49. 470 Q=INT(256*RND)
  50. 480 RETURN
  51. 490 CLOSE #1,#2
  52. 500 END
  53.  
  54. crypt listing 2
  55. è10 REM
  56. 20 REM A cellular automata machine
  57. 30 REM
  58. 40 DEFINT A-Z
  59. 50 W=60
  60. 60 DIM R(256)
  61. 70 DIM A(1000,2)
  62. 80 Y=1:Y1=0
  63. 90 INPUT "Key:";K$
  64. 100 REM
  65. 110 REM Place the key in array by converting it to ASCII code
  66. 120 REM
  67. 130 FOR X=1 TO LEN(K$)
  68. 140 H$=MID$(K$,X,1)
  69. 150 A(X,Y1)=ASC(H$)
  70. 160 NEXT X
  71. 170 REM
  72. 180 REM Main section of the program
  73. 190 REM
  74. 200 REM Begin by getting a random number between 0 and 255
  75. 210 REM
  76. 220 GOSUB 550
  77. 230 R(Q)=R(Q)+1
  78. 240 REM
  79. 250 REM Print out the array
  80. 260 REM
  81. 270 FOR X=0 TO W+1
  82. 280 Z=A(X,Y1)
  83. 290 IF Z<32 THEN Z=32
  84. 300 PRINT CHR$(Z);
  85. 310 NEXT X
  86. 320 PRINT
  87. 330 REM
  88. 340 REM Print out the statistics if a key is touched
  89. 350 REM
  90. 360 A$=INKEY$
  91. 370 IF A$="" THEN 200
  92. 380 REM First the individual occurences
  93. 390 E#=0!
  94. 400 FOR X=0 TO 255
  95. 410 E#=E#+R(X)
  96. 420 PRINT CHR$(X);R(X),
  97. 430 NEXT X
  98. 440 E1#=E#/256!
  99. 450 Q#=0!
  100. 460 REM Next calculate the chi-squared and print it out 
  101. 470 FOR X=0 TO 255
  102. 480 Q#=Q#+ABS(R(X)-E1#)^2
  103. 490 NEXT X
  104. 500 PRINT "Difference:";Q#
  105. 510 PRINT
  106. 520 PRINT "Difference per time step:";Q#/E#
  107. 540 GOTO 220
  108. 550 REM
  109. 560 REM Random number subroutine. Updates cells and outputs Qè570 REM
  110. 580 FOR X=1 TO W
  111. 590 A(X,Y)=A(X-1,Y1) XOR (A(X,Y1) OR A(X+1,Y1))
  112. 600 NEXT X
  113. 610 REM Complete the circle by updating the ends
  114. 620 A(0,Y)=A(W+1,Y1) XOR (A(0,Y1) OR A(1,Y1))
  115. 630 A(W+1,Y)=A(W,Y1) XOR (A(W+1,Y1) OR A(0,Y1))
  116. 640 Q=A(0,Y)
  117. 650 K=Y:Y=Y1:Y1=K
  118. 660 RETURN
  119.  
  120. crypt listing 3
  121.  
  122. 10 REM
  123. 20 REM A cellular automata coding machine
  124. 30 REM
  125. 40 DEFINT A-Z
  126. 50 W=30
  127. 60 DIM R(256)
  128. 70 DIM A(1000,2)
  129. 80 Y=1:Y1=0
  130. 90 INPUT "Key:";K$
  131. 100 REM
  132. 110 REM Place the key in array by converting it to ASCII code
  133. 120 REM
  134. 130 FOR X=1 TO LEN(K$)
  135. 140 H$=MID$(K$,X,1)
  136. 150 A(X,Y1)=ASC(H$)
  137. 160 NEXT X
  138. 170 INPUT "File to be coded:";C$
  139. 180 INPUT "File for output:";D$
  140. 190 OPEN C$ FOR INPUT AS #1
  141. 200 OPEN D$ FOR OUTPUT AS #2
  142. 210 INPUT "Encode or Decode";A$
  143. 220 A$=LEFT$(A$,1)
  144. 230 IF A$="E" OR A$="e" THEN A=1: GOTO 300
  145. 240 IF A$="D" OR A$="d" THEN A=-1 ELSE 210
  146. 250 REM
  147. 260 REM This is the Q$, set up for text files. R is the length
  148. 270 REM r1 is the length minus 1 computed now
  149. 280 REM to save repeated calculations
  150. 290 REM
  151. 300 Q$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  152. 310 Q$=Q$+"1234567890!@#$%^&*()-=_+[]{};:`~,./<>?|\ '"+CHR$(34)
  153. 320 R=LEN(Q$)
  154. 330 R1=R-1
  155. 340 REM
  156. 350 REM Begin here
  157. 360 REM
  158. 370 IF EOF(1) THEN 560
  159. 380 X$=INPUT$(1,#1)
  160. 390 L=INSTR(Q$,X$)
  161. 400 IF L=0 THEN Y$=X$: GOTO 530
  162. 410 REM
  163. 420 REM Find a random numberè430 REM
  164. 440 GOSUB 580
  165. 450 Z%=INT(R*Q/256)
  166. 460 T=L+(A*Z%)
  167. 470 REM
  168. 480 REM Adjust the parameters to be between 1 and r
  169. 490 REM
  170. 500 IF T<=0 THEN T=T+R1
  171. 510 IF T>=R THEN T=T-R1
  172. 520 Y$=MID$(Q$,T,1)
  173. 530 PRINT #2,Y$;
  174. 540 PRINT X$,L,Y$,T
  175. 550 GOTO 370
  176. 560 CLOSE #1,#2
  177. 570 END
  178. 580 REM
  179. 590 REM Random number subroutine. Updates cells and outputs Q
  180. 600 REM
  181. 610 FOR X=1 TO W
  182. 620 A(X,Y)=A(X-1,Y1) XOR (A(X,Y1) OR A(X+1,Y1))
  183. 630 NEXT X
  184. 640 REM Complete the circle by updating the ends
  185. 650 A(0,Y)=A(W+1,Y1) XOR (A(0,Y1) OR A(1,Y1))
  186. 660 A(W+1,Y)=A(W,Y1) XOR (A(W+1,Y1) OR A(0,Y1))
  187. 670 Q=A(0,Y)
  188. 680 K=Y:Y=Y1:Y1=K
  189. 690 RETURN
  190.