home *** CD-ROM | disk | FTP | other *** search
/ UpTime Volume 2 #3 / utv2n3s2.d64 / cryptogram.exe (.txt) < prev    next >
Encoding:
Commodore BASIC  |  1988-01-01  |  22.3 KB  |  753 lines

  1. 10 rem 'cryptogram assistant' for the commodore 64
  2. 20 :
  3. 30 rem (c) 1988  by ian adam   vancouver, british columbia
  4. 40 :
  5. 50 rem published by softdisk publishing incorporated
  6. 60 :
  7. 70 rem these extra functions available:
  8. 80 :
  9. 90 rem sys 828 ,r [,c] move cursor:
  10. 100 rem sys 853 ,w ,v screens 4, 8, 12
  11. 110 rem sys 883 unlink screen
  12. 120 rem sys 894 printer check
  13. 130 :
  14. 140 gosub 2660, data
  15. 150 gosub 2890, instructions
  16. 160 gosub 5240, printer controls
  17. 170 dim s(255), xr(128), e(128)
  18. 180 :
  19. 190 rem ****   main control loop   ****
  20. 200 :
  21. 210 gosub 4990:rem print menu, screen 3
  22. 220 gosub 5730
  23. 230 if ff then on ff gosub 380, 340, 6120, 340, 2890, 3100, 5240, 260:goto 210
  24. 240 goto 220
  25. 250 :
  26. 260 m$(2)="[150] [197]nd the [208]rogram"
  27. 265 if peek(56)=128 then if peek(32768)=76 then up=1
  28. 270 if up then m$(3)="[150] & [210]eturn to [213]p[212]ime"
  29. 280 m$(5)=" -[193]re you [211]ure? [217]/[206]"
  30. 290 gosub 7260, message box
  31. 300 gosub 5730, response
  32. 310 if a$<>"y" then return
  33. 320 poke 44,8:poke 2048,0:sys 853,4,4
  34. 330 if up then sys 32772
  35. 335 end
  36. 340 return
  37. 350 :
  38. 360 : *****    puzzle solution    *****
  39. 370 :
  40. 380 print"[147]";:sys 853,8,12:gosub 3580
  41. 390 print "[159]enter the message you want to decode,"
  42. 400 print "then press return when finished, or:"
  43. 410 print " press f3 for a sample puzzle to solve."
  44. 420 print " press f5 to retrieve a puzzle you"
  45. 430 print "              saved earlier."
  46. 440 print " press f7 to quit and go to the menu."
  47. 450 sys 853,8,8:print"[142]";:sys 828,20:print"[192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
  48. 460 s1=8:sl=9:ex=0
  49. 470 gosub 1970
  50. 480 :
  51. 490 if ff=3 then gosub 5810:goto 510
  52. 500 if ff=5 then gosub 1840
  53. 510 if n<2 thenreturn
  54. 520 s1=4
  55. 530 sys 853,4,4:gosub 2270:gosub 2120
  56. 540 sys 853,8,4:gosub 2280:gosub 1050
  57. 550 :
  58. 560 rem **  solution loop  **
  59. 570 :
  60. 580 for m=1 to 2 step 0
  61. 590 if p1<0 then poke 53265,11:sys 853,12,s1:sys 883:gosub 1080:gosub 2280,paint
  62. 600 if p1>3 then sys 853,4,s1:gosub 2270:gosub 2200:sys 853,8,s1:gosub 2270
  63. 610 if p1 and 1 then gosub 1520,do pg 1
  64. 620 if p1>1 then gosub 1050, do pg 2
  65. 630 p1=0:b$="":sys 853,s1,s1
  66. 640 :
  67. 650 sys 828,22:print "                                       [145]":rem clear input
  68. 660 print b$;
  69. 670 print "[166][157]";:poke 204,.:gosub 5730:poke 204,1
  70. 680 :
  71. 690 if as>=k then if as<=l then b$=b$+a$:goto 650
  72. 700 if as=j then gosub 1220:next
  73. 710 if as=20 or as=157 then if b$>"" then print " [157][157] [157]";:b$=left$(b$,len(b$)-1):goto 670
  74. 720 if a$="_" then s1=12-s1:next:change screens
  75. 730 for i=1 to 3
  76. 740 if a$=mid$("+-*",i,1) then print a$;:on i gosub 1360, 1450, 960:next m
  77. 750 next
  78. 760 on ff goto 2440, 1680, 1600, 2110, 810, 770, 2500, 2580
  79. 770 next
  80. 780 :
  81. 790 : **  print trial solution  **
  82. 800 :
  83. 810 poke 2,sa:sys 894
  84. 820 if peek(144)<k7 then 870:rem is printer there?
  85. 830 close 4
  86. 840 print"[150]can't find the printer- press space bar";
  87. 850 gosub 5730:next m
  88. 860 :
  89. 870 print#4:close 4:open 4,4,sa:cmd 4
  90. 880 print:print "[195]ryptogram [193]ssistant":print
  91. 890 print "[195]ryptogram entered:":print:print r$:print
  92. 900 print "[212]rial solution:":print:gosub 1550:print:print
  93. 910 print:gosub 1110:print#4
  94. 920 close 4:next m
  95. 930 :
  96. 940 : **  offsets  **
  97. 950 :
  98. 960 s1=4:poke 648,4:sys 828,22
  99. 970 print "[158][208]ress [193]ny [203]ey to [211]top..."
  100. 980 for a=k to l:gosub 1380:if peek(kb)=0 then next:return
  101. 990 poke kb,0:a=a-k+1:for i=k to l:e(i)=e(i)+a:if e(i)>l then e(i)=e(i)-k3
  102. 1000 next:if os<l then os=os+a:if os>25 then os=os-k3
  103. 1010 return
  104. 1020 :
  105. 1030 : **  count letters  **
  106. 1040 :
  107. 1050 for i=k to l:xr(i)=.:next
  108. 1060 for i=1 to n:xr(s(i))=xr(s(i))+1:next
  109. 1070 sys 853,8,s1
  110. 1080 print "[159]";
  111. 1090 for i=0 to j:print "                                       ":next
  112. 1100 print "[159]";
  113. 1110 print "frequency:      cipher:                ";
  114. 1120 if os<l then sys 828,0,28:print "offset:"os;
  115. 1130 sys 883:poke 646,1
  116. 1140 print:for i=k to 77:ii=i+j
  117. 1150 print chr$(i) spc(1+(xr(i)>9)) xr(i) "   " chr$(ii) spc(1+(xr(ii)>9)) xr(ii);
  118. 1160 print "   " chr$(i) "  " chr$(e(i)) "    " chr$(ii) "  " chr$(e(ii))
  119. 1170 next
  120. 1180 return
  121. 1190 :
  122. 1200 rem **  exchange letters  **
  123. 1210 :
  124. 1220 if len(b$)<2 then b$=c$
  125. 1230 a=asc(b$):if a<k or a>l then return
  126. 1240 for i=2 to len(b$):c=asc(mid$(b$,i)):if c<k or c>l then next:return
  127. 1250 for i=1 to n:if s(i)=a then s(i)=c:next:goto 1280
  128. 1260 if s(i)=c then s(i)=a
  129. 1270 next
  130. 1280 for i=k to l:if e(i)=a then e(i)=c:next:goto 1310
  131. 1290 if e(i)=c then e(i)=a
  132. 1300 next
  133. 1310 os=l:c$=b$:p1=3
  134. 1320 return
  135. 1330 :
  136. 1340 : **  advance alphabet  **
  137. 1350 :
  138. 1360 for i=k to l:e(i)=e(i)+1+k3*(e(i)=l):next
  139. 1370 if os<l then os=(os+1)*abs(os<25)
  140. 1380 for i=1 to n
  141. 1390 if s(i)=l then s(i)=k:next:goto 1520
  142. 1400 if s(i)>=k then if s(i)<l then s(i)=s(i)+1
  143. 1410 next:p1=2:goto 1520
  144. 1420 :
  145. 1430 : **  retract alphabet  **
  146. 1440 :
  147. 1450 for i=k to l:e(i)=e(i)-1-k3*(e(i)=k):next
  148. 1460 if os<l then os=(os-1)-k3*(os<-11)
  149. 1470 for i=1 to n:if s(i)>=k then if s(i)<=l then s(i)=s(i)-1-k3*(s(i)=k)
  150. 1480 next:p1=2
  151. 1490 :
  152. 1500 rem **  show solution  **
  153. 1510 :
  154. 1520 sys 853,4,s1
  155. 1530 sys 828,sl
  156. 1540 print "";
  157. 1550 for i=1 to n:print chr$(s(i));:next
  158. 1560 sys 883:return
  159. 1570 :
  160. 1580 : **  modify puzzle  **
  161. 1590 :
  162. 1600 sys 853,8,s1
  163. 1610 print "[147]modify puzzle."
  164. 1620 print "[158]make necessary changes, then return:[159]"
  165. 1630 sys 853,8,8:gosub 1980
  166. 1640 goto 510, start again
  167. 1650 :
  168. 1660 : **  save puzzle  **
  169. 1670 :
  170. 1680 sys 853,12,s1
  171. 1690 print "[147][158][211]ave [212]his [208]uzzle:"
  172. 1700 print "[159][213]p to 8 cryptograms may be held in"
  173. 1710 print " temporary program buffers."
  174. 1720 if sp=0 then 1760
  175. 1730 print:print "[194]uffers occupied:";
  176. 1740 for i=1 to 8:if b(i) then print i;
  177. 1750 next:print
  178. 1760 print:print "[159][208]ress [198]1 to [198]8 to designate the"
  179. 1770 print "buffer, any other key to cancel:"
  180. 1780 sys 853,12,12:poke 204,1:gosub 5730:print ff
  181. 1790 if ff then sp$(ff)=r$:sp=1:b(ff)=1
  182. 1800 p1=-8:next
  183. 1810 :
  184. 1820 : **  retrieve saved puzzle  **
  185. 1830 :
  186. 1840 n=0:ii=0:print "[147][210]etrieve [211]aved [208]uzzle:  [158]";
  187. 1850 if sp=0 then print:print "[206]o saved puzzles in memory!![159]":gosub 5590:return
  188. 1860 :
  189. 1870 for c=1 to 8
  190. 1880 if b(c)=0 then 1910
  191. 1890 if peek(214)>19 then if len(sp$(c))>79 then if ii=0 then gosub 5520
  192. 1900 print:print "[158][208]ress "c"[157][157][157][198]: [159]" sp$(c);:if c<8 then print
  193. 1910 next
  194. 1920 gosub 5730:if ff then r$=sp$(ff):n=len(r$)
  195. 1930 return
  196. 1940 :
  197. 1950 : **  enter puzzle  **
  198. 1960 :
  199. 1970 r$="":n=0:poke 53272,37
  200. 1980 sys 828,21
  201. 1990 print r$;:for n=n to 158
  202. 2000 poke 204,0
  203. 2010 gosub 5730:if ff or as=j then 2070
  204. 2020 as=as and k7
  205. 2030 if as>=k2 then 2060
  206. 2040 if a$=chr$(20) then if n then print a$;:n=n-1:r$=left$(r$,n)
  207. 2050 goto 2000
  208. 2060 print a$;:r$=r$+a$:next
  209. 2070 poke 204,1:print "[147]":return
  210. 2080 :
  211. 2090 : **  organize & display puzzle  **
  212. 2100 :
  213. 2110 gosub 2120:s1=4:p1=2:next m:rem from submenu
  214. 2120 c$="aa"
  215. 2130 for i=1 to n:s(i)=asc(mid$(r$,i)) and k7
  216. 2140 if s(i)<k2 then s(i)=k2
  217. 2150 next
  218. 2160 for i=k to l:e(i)=i:next:os=0
  219. 2170 :
  220. 2180 rem **  display page 1  **
  221. 2190 :
  222. 2200 sys 853,4,s1:print "[159] ":print "[195][210][217][208][212][207][199][210][193][205] [197][206][212][197][210][197][196]:":print r$
  223. 2210 sys 828,sl*.85:print "[212][210][201][193][204] [211][207][204][213][212][201][207][206]:"
  224. 2220 gosub 1530:sys 853,4,4
  225. 2230 return
  226. 2240 :
  227. 2250 rem **  command area  **
  228. 2260 :
  229. 2270 print "[147]"
  230. 2280 sys 828,14
  231. 2290 print "[158][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][181]";
  232. 2300 print "[150]  [195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]    [194]y [201]an [193]dam  [158][146][181][157][181][157][181][157][181][157][181][157][181][157][181][157][181][157][181]";
  233. 2310 print"[150] [208]ublished by [211]oftdisk [208]ublishing, [201]nc.":poke56295,7:poke2023,117
  234. 2320 sys 883:sys 828,16
  235. 2330 print "[159][197]nter two letters to exchange, or:"
  236. 2340 print "_ [211]witch  +- [207]ffset   * [204]oop [193]dvance"
  237. 2350 print "[198]1 [201]nstructions    [198]2 [210]emember this"
  238. 2360 print "[198]3 [205]odify [208]uzzle   [198]4 [210]estore [208]uzzle"
  239. 2370 print "[198]5 [208]rint [208]uzzle    [198]7 [209]uit [208]uzzle"
  240. 2380 poke 53265,27:if ex then print "[145][198]8 [211]ee [211]olution"
  241. 2390 print "              "
  242. 2400 return
  243. 2410 :
  244. 2420 : **  help  **
  245. 2430 :
  246. 2440 gosub 2890, instructions
  247. 2450 print "[147]":s1=4:p1=7
  248. 2460 c=0:gosub 5690:next m
  249. 2470 :
  250. 2480 : **  scrap puzzle  **
  251. 2490 :
  252. 2500 sys 828,22
  253. 2510 print "[150][193]bandon this [208]uzzle: [193]re [217]ou [211]ure? [217]/[206]"
  254. 2520 gosub 5730
  255. 2530 if a$="y" then ex=0:print "[147][145]":return
  256. 2540 next m
  257. 2550 :
  258. 2560 : **  see solution  **
  259. 2570 :
  260. 2580 if ex=0 then next m
  261. 2590 s1=4:sys 853,s1,s1:sys 828,sl
  262. 2600 print "[150]"s$"";:sys 883
  263. 2610 sys 828,22:gosub 5600:gosub 5730
  264. 2620 p1=1:next m
  265. 2630 :
  266. 2640 : **  setup & instr'ns  **
  267. 2650 :
  268. 2660 print "[147]":for i=828 to 920:read a:poke i,a:next
  269. 2670 l=90:k=65:k3=26:j=13
  270. 2680 dim c,ii,os,ff,as,ex,s1,n,m,p1,sp,a$,b$,c$,r$,s$
  271. 2690 k2=32:k7=127:sl=9:kb=198:c0=53280:c1=c0+1:sa=7
  272. 2700 return
  273. 2710 rem -------
  274. 2720 :
  275. 2730 data 32, 241, 183, 138, 72, 160, 1, 136, 177, 122, 201, 44, 208
  276. 2740 data 5, 32, 241, 183, 138, 168, 104, 170, 24, 76, 240, 255
  277. 2750 rem -------
  278. 2760 :
  279. 2770 data 32, 241, 183, 134, 210, 142, 136, 2, 162, 0, 134, 209, 134, 243
  280. 2780 data 162, 216, 134, 244, 32, 241, 183, 138, 10, 10, 9, 7, 141, 24, 208, 96
  281. 2790 rem -------
  282. 2800 :
  283. 2810 data 162, 24, 54, 217, 56, 118, 217, 202, 208, 248, 96
  284. 2820 rem -------
  285. 2830 :
  286. 2840 data 169, 4, 32, 195, 255, 162, 4, 138, 164, 2, 32, 186, 255
  287. 2850 data 169, 0, 32, 189, 255, 32, 192, 255, 162, 4, 32, 201, 255, 96
  288. 2860 :
  289. 2870 rem **  instructions  **
  290. 2880 :
  291. 2890 b$=chr$(j)
  292. 2900 gosub 3510:rem print page 1
  293. 2910 if ff then return
  294. 2920 sys 853,4,8:gosub 3840:rem print 2
  295. 2930 sys 853,8,4:gosub 4060:rem print 3
  296. 2940 a=1:gosub 5660:rem user, show #2
  297. 2950 if ff then return
  298. 2960 gosub 4250:rem print #4
  299. 2970 a=2:gosub 5660:rem show #3
  300. 2980 if ff then return
  301. 2990 gosub 4510:rem print #5
  302. 3000 a=1:gosub 5660:rem show #4
  303. 3010 if ff then return
  304. 3020 gosub 4770:rem print #6
  305. 3030 if ff then return
  306. 3040 a=2:c=0:gosub 5670:rem show #5
  307. 3050 sys 853,4,4:gosub 5520:rem hold #6
  308. 3060 return
  309. 3070 :
  310. 3080 : **  print instructions  **
  311. 3090 :
  312. 3100 sys 853,12,s1:b$=""
  313. 3110 print "[147][158]" tab(49) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]":print
  314. 3120 print "[158][208]rint the [201]nstructions:"
  315. 3130 print "   [197]nsure printer is turned on, and"
  316. 3140 print "   lined up at the top of the page."
  317. 3150 print:print:print "[158][208]ress:"
  318. 3160 print:print "   [198]1  [208]roceed to [208]rint"
  319. 3170 print:print "   [198]3  [195]hange [211]econdary [193]ddress"
  320. 3180 print:print "   [198]5  [195]ancel"
  321. 3190 sys 853,12,12:s1=12:c=6:gosub 5690:gosub 5730
  322. 3200 if ff=1 then 3250
  323. 3210 if ff=3 then gosub 5240:goto 3100
  324. 3220 if ff=5 or ff=7 then return
  325. 3230 goto 3190
  326. 3240 :
  327. 3250 print "[158][208][210][201][206][212][201][206][199]...."
  328. 3260 poke 2,sa:sys 894
  329. 3270 if peek(144)<k7 then 3370:rem is printer there?
  330. 3280 :
  331. 3290 close 4:rem no printer
  332. 3300 m$(2)="[150] can't find"
  333. 3310 m$(3)="[150] the printer!!"
  334. 3320 m$(5)=" press space bar"
  335. 3330 c=0:gosub 5690
  336. 3340 gosub 7260
  337. 3350 gosub 5730:return
  338. 3360 :
  339. 3370 print:print:print "    [195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212] for the 64":print:print
  340. 3380 print "(c) [201]an [193]dam [214]ancouver [194].[195]. and [211]oftdisk [208]ublishing [201]nc.":print
  341. 3390 gosub 3700:print:rem 1st page
  342. 3400 gosub 3850:rem 2nd page
  343. 3410 gosub 4070:rem 3rd page
  344. 3420 gosub 4260:rem 4th page
  345. 3430 print chr$(12)
  346. 3440 gosub 4520:rem 5th page
  347. 3450 gosub 4780:rem 6th page
  348. 3460 print#4:print#4, chr$(12)
  349. 3470 close 4:return
  350. 3480 :
  351. 3490 : **  1st page instructions  **
  352. 3500 :
  353. 3510 print "[147]":poke 648,4:print "[147]"
  354. 3520 sys 853,8,4
  355. 3530 gosub 3580:gosub 3700
  356. 3540 poke c1,0:poke c0,0:poke 53272,37
  357. 3550 gosub 5520
  358. 3560 print "[147]":return
  359. 3570 :
  360. 3580 print "[147][142]" tab(9) "[158][169] [223]  [223]    [223]   [169] [223]"
  361. 3590 print tab(9) "          "
  362. 3600 print tab(9) "   [146][169][223] [146][169]  [146][169]   "
  363. 3610 print tab(9) "  [146][223][223]     "
  364. 3620 print tab(9) "[223] [146][169] [146][223][223]   [146][223] [146][169]"
  365. 3630 print "[164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164]"
  366. 3640 print tab(8) "[149][169]  [146][169][169][146][169][169][146][169][169][146][169][169][146][169][169][146][169][169][146][169]"
  367. 3650 print tab(7) "[169][146][169][185][206][169] [183][146][169][169] [183][183][146][169][169][146][169][169][146][169]"
  368. 3660 print tab(6) "[169][146][169][169][146][169][223][223] [169][146][169][169][146][169][169][146][169][169][146][169]"
  369. 3670 print tab(6) "  [146][169]   [146][169]  [146][169] [146][169]  [146][169]"
  370. 3680 return
  371. 3690 :
  372. 3700 print "welcome to cryptogram assistant!":print
  373. 3710 print "  -  the cryptogram is a form of secret ";
  374. 3720 print "message that can be read by means of"
  375. 3730 print "a code, or cipher.  each letter of the "b$;
  376. 3740 print "alphabet is replaced by another letter."
  377. 3750 print "the encoded message appears at first to ";
  378. 3760 print "be just a random collection of letters;"
  379. 3770 print "however, once you know the code, it is "b$;
  380. 3780 print "easy to discover the original message,"
  381. 3790 print "by restoring the letters.";
  382. 3800 return
  383. 3810 :
  384. 3820 : **  2nd page instructions  **
  385. 3830 :
  386. 3840 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]"
  387. 3850 print:print "[211]olving a cryptogram will require "b$;
  388. 3860 print "considerable ingenuity on your part."
  389. 3870 print "[212]rial and error is not a practical way "b$;
  390. 3880 print "of discovering the code:  the number of"
  391. 3890 print "possible ciphers is 26 factorial, about ";
  392. 3900 print "400 million billion billion!  [201]f you"
  393. 3910 print "programmed a computer to search for all ";
  394. 3920 print "the possible solutions, it would take"
  395. 3930 print "more time than the universe has been in ";
  396. 3940 print "existence just to print them out.":print b$
  397. 3950 print "[195]learly, deciphering a message depends "b$;
  398. 3960 print "on finding some clues to narrow the"
  399. 3970 print "range of solutions.  [212]he combination of ";
  400. 3980 print "human intellect and the computer's"
  401. 3990 print "speed can be very successful in solving ";
  402. 4000 print "the puzzle."
  403. 4010 if len(b$) then print:print "[208]ress [198]7 to bypass instructions, or..."
  404. 4020 return
  405. 4030 :
  406. 4040 : **  3rd page instructions  **
  407. 4050 :
  408. 4060 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]"
  409. 4070 print:print "[212]his program will help in several ways. ";
  410. 4080 print "[198]irst, it keeps track of how often each"
  411. 4090 print "letter appears in the puzzle, because "b$;
  412. 4100 print "this often gives clues when deciding"
  413. 4110 print "on substitutions.  [211]econd, the program ";
  414. 4120 print "will assist you by making the changes"
  415. 4130 print "you have requested quickly and easily.  ";
  416. 4140 print "[198]inally, if the cipher consists of a"
  417. 4150 print "simple offset, then there are only 26 "b$;
  418. 4160 print "solutions, a more manageable total!"
  419. 4170 print "[212]he program will generate and display "b$;
  420. 4180 print "all possible results for you.":print
  421. 4190 print "* - [212]he most common letters, in order:":print
  422. 4195 print "e  t  o  a  n  i  r  s  h":print
  423. 4200 print "[212]he most common combinations:":print
  424. 4205 print "th  he  an  er  on  re  the  and  tha"
  425. 4210 return
  426. 4220 :
  427. 4230 : **  4th page instructions  **
  428. 4240 :
  429. 4250 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]"
  430. 4260 print:print "[197]ach substitution is made by trading a "b$;
  431. 4270 print "pair of letters.  [193]t the prompt, simply"
  432. 4280 print "type the two letters to be exchanged & "b$;
  433. 4290 print "press [210][197][212][213][210][206].  [212]he modified puzzle will"
  434. 4300 print "be updated and displayed.  [201]f the result";
  435. 4310 print " [157]isn't [207][203], press [210][197][212][213][210][206] to reverse the"
  436. 4320 print "exchange.  [212]his makes it easy to "b$;
  437. 4330 print "experiment.  [215]ith successive exchanges,"
  438. 4340 print "the cipher is completed.  [212]o see this, ";
  439. 4350 print " choose 'demonstration solution'.":print
  440. 4360 print "[212]he program deals with two basic kinds "b$;
  441. 4370 print "of cryptogram.  [201]n the most common kind"
  442. 4380 print "the code is completely random, so you "b$;
  443. 4390 print "need to know or deduce all the letters"
  444. 4400 print "to solve the puzzle.  [212]his is the more "b$;
  445. 4410 print "difficult kind of message to decipher."
  446. 4420 print "[193]s mentioned, the second kind of puzzle ";
  447. 4430 print "is easier to solve, because each letter"
  448. 4440 print "is offset by a fixed number of places "b$;
  449. 4450 print "in the alphabet: in order to solve it,"
  450. 4460 print "you only need know the offset amount.";
  451. 4470 return
  452. 4480 :
  453. 4490 : **  5th page instructions  **
  454. 4500 :
  455. 4510 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]"
  456. 4520 print:print "[217]ou can actually use the program three "b$;
  457. 4530 print "different ways.  [198]irst, it is used for"
  458. 4540 print "decoding secret messages.  [211]econd, the ";
  459. 4550 print "program has four cryptograms in memory,"
  460. 4560 print "to solve as exercises.  [198]inally, you can";
  461. 4570 print "use it in reverse: type in an original"
  462. 4580 print "message, and use the program to encode "b$;
  463. 4590 print "it.  [194]e sure that you have the cipher"
  464. 4600 print "recorded, so that the original message "b$;
  465. 4610 print "can be reconstructed later.  [215]hen you"
  466. 4620 print "display the message on your printer, "b$;
  467. 4630 print "this data will be shown automatically.":print
  468. 4640 print "[193]s you work on a solution, the program "b$;
  469. 4650 print "will print the original message at the"
  470. 4660 print "top of the screen and the evolving "b$;
  471. 4670 print "solution immediately below.  [212]here is a"
  472. 4680 print "second screen showing the frequency of "b$;
  473. 4690 print "each letter in the solution and the"
  474. 4700 print "current status of the cipher.  [201]f you "b$;
  475. 4710 print "examine the frequency of the letters,"
  476. 4720 print "you can often gain valuable clues."
  477. 4730 return
  478. 4740 :
  479. 4750 : **  6th page instructions  **
  480. 4760 :
  481. 4770 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]":print
  482. 4780 print:print "[200]ere are your command options while "b$;
  483. 4790 print "solving the puzzle:":print
  484. 4800 print "2 letters & [210][197][212][213][210][206]:"
  485. 4810 print "         [197]xchange positions of letters"
  486. 4820 print "[210][197][212][213][210][206]   [210]everse previous exchange.":print
  487. 4830 print "+ or -   [207]ffset letters by 1 position."
  488. 4840 print "*        [209]uickly advance through whole"
  489. 4850 print "             alphabet (any key = quit.)"
  490. 4860 print "_        [207]ther screen: [208]uzzle or [195]ipher."
  491. 4870 print "[198]1       [200]elp - [210]eview [201]nstructions."
  492. 4880 print "[198]2       [211]ave [208]uzzle in [195]urrent [205]emory."
  493. 4890 print "[198]3       [205]odify [208]uzzle & [211]tart [193]gain."
  494. 4900 print "[198]4       [210]estore [208]uzzle (as modified.)"
  495. 4910 print "[198]5       [208]rint the [212]rial [211]olution."
  496. 4920 print "[198]7       [193]bandon [208]uzzle, get [205]ain [205]enu."
  497. 4930 print "[198]8       [211]ee [211]olution of [211]ample [208]uzzle."
  498. 4940 poke 646,1:print
  499. 4950 return
  500. 4960 :
  501. 4970 rem ****  main menu  ****
  502. 4980 :
  503. 4990 poke 648,4:print"[147]":sys 853,12,4
  504. 5000 print "[147][158]"tab(10)"[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212][154]"
  505. 5010 rem (c) 1988  by ian adam   vancouver, british columbia
  506. 5020 :
  507. 5030 print "   [182][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][181]"
  508. 5040 print "   [182] [158]     [208]ress:                   [154][146] [181]"
  509. 5050 print "   [182][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][181]"
  510. 5060 for i=1 to 8
  511. 5070 print "   [182]" spc(32) "[181]":next
  512. 5080 print "   [182][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][181]"
  513. 5090 print "[153]"
  514. 5100 print tab(6) "[198]1  [211]olve a [195]ryptogram"
  515. 5110 print tab(6) "[198]3  [196]emonstration [211]olution"
  516. 5120 print tab(6) "[198]5  [210]eview [201]nstructions"
  517. 5130 print tab(6) "[198]6  [208]rint the [201]nstructions"
  518. 5140 print tab(6) "[198]7  [211]et [208]rinter [195]ontrol"
  519. 5150 print tab(6) "[198]8  [197]nd the [208]rogram[154]"
  520. 5160 print "[182][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][181]";
  521. 5170 print "[182]  [194]y [201]an [193]dam   [214]ancouver [194].[195].  1988  [154][181]";
  522. 5180 print "[182][208]ublished by [211]oftdisk [208]ublishing, [201]nc.[154][181]";
  523. 5190 print "[182][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][181]";
  524. 5200 poke c1,0:poke c0,0:sys 853,12,12:return
  525. 5210 :
  526. 5220 rem **  printer control  **
  527. 5230 :
  528. 5240 b$="":s1=12:print "[147]":poke 648,s1
  529. 5250 print "[147][158]" tab(9) "[195][210][217][208][212][207][199][210][193][205] [193][211][211][201][211][212][193][206][212]"
  530. 5260 print " [217]our cryptograms, their solutions, and"
  531. 5270 print " program instructions can be sent to"
  532. 5280 print " your printer.  [212]he printer file will"
  533. 5290 print " be opened with a secondary address of"
  534. 5300 print sa "to produce upper and lower case,"
  535. 5310 print " with line feeds.  [201]f this is [207][203], or if"
  536. 5320 print " you're not using a printer, then"
  537. 5330 print " press the space bar."
  538. 5340 print " [201]f your combination of printer and"
  539. 5350 print " interface requires a different"
  540. 5360 print " secondary address, then enter the"
  541. 5370 print " number now and press [210][197][212][213][210][206]:"
  542. 5380 c=6:gosub 5690:sys 853,12,12:sys 828,19,1
  543. 5390 gosub 5730
  544. 5400 if as=13 or as=32 then 5450
  545. 5410 if a or as=48 then print a$;:b$=b$+a$
  546. 5420 if as=20 and b$>"" then print a$;:b$=left$(b$,len(b$)-1)
  547. 5430 goto 5390
  548. 5440 :
  549. 5450 if len(b$) then sa=val(b$) and 255
  550. 5460 print "[147]":c=0:gosub 5690:return
  551. 5470 :
  552. 5480 rem **  message, switches  **
  553. 5490 :
  554. 5500 :  gosub 5520: flash message, wait for space bar
  555. 5510 :
  556. 5520 ii=1
  557. 5530 on ii gosub 5590, 5610
  558. 5540 for i=1 to 25:gosub 5740:if as then 5610
  559. 5550 next:ii=3-ii:goto 5530
  560. 5560 :
  561. 5570 :  gosub 5590: move cursor & print message only
  562. 5580 :
  563. 5590 sys 828,24,6
  564. 5600 print "[150]...press the space bar to proceed[145]";:return
  565. 5610 sys 828,24,6:print "                                 [145]";:return
  566. 5620 :
  567. 5630 :  gosub 5660: switch colour, switch screen, & wait
  568. 5640 :  gosub 5670: leave colour, switch screen, & wait
  569. 5650 :
  570. 5660 c=10-a*4
  571. 5670 s1=4*a
  572. 5680 sys 853,s1,s1:gosub 5520:sys 853,s1,12-s1
  573. 5690 poke c0,c:poke c1,c:return
  574. 5700 :
  575. 5710 :  gosub 5730:get input, translate
  576. 5720 :
  577. 5730 poke198,0:wait kb,7
  578. 5740 get a$:a=val(a$):as=asc(a$+chr$(0))
  579. 5750 if as<133 or as>141 then ff=.:return
  580. 5760 ff=2*as-265:if ff>7 then ff=ff-7
  581. 5770 a=ff:return
  582. 5780 :
  583. 5790 : ****  exercises  ****
  584. 5800 :
  585. 5810 print "[147][158][211]elect a sample puzzle to solve."
  586. 5820 print "[158][208]ress [198]1 for:[159]"
  587. 5830 gosub 5940:print r$
  588. 5840 print "[158][208]ress [198]3 for:[159]"
  589. 5850 gosub 5980:print r$
  590. 5860 print "[158][208]ress [198]5 for:[159]"
  591. 5870 gosub 6020:print r$
  592. 5880 print "[158][208]ress [198]7 for:[159]"
  593. 5890 gosub 6060:print r$;
  594. 5900 ex=0:gosub 5730
  595. 5910 on ff gosub 5940, 5920, 5980, 5920, 6020, 5920, 6060
  596. 5920 print "[147]":n=len(r$):return
  597. 5930 :
  598. 5940 r$="ctp upem fcjwecwjp ih ctp djnuqp nf v hkvc rkvcp jwggngq pvfc-ypfc, rvjvkkpk ci ctp jiwcp.  nc'f ig v 2-upqjpp fkirp, ynct qiiu veepff hjio pvet fnup."
  599. 5950 s$="[212]he deck structure of the bridge is a flat plate running east-west, parallel to the route.  [201]t's on a 2-degree slope, with good access from each side."
  600. 5960 ex=1:return
  601. 5970 :
  602. 5980 r$="[204]m. [197]hnbl lvhkxw makxx mhnvawhpgl bg max ybgte mph fbgnmxl mh pbg bml ybklm ahfx hixgxk bg 12 rxtkl.  [205]hgbzam max [218]btgml mktoxe mh [214]abvtzh."
  603. 5990 s$="[211]t. [204]ouis scored three touchdowns in the final two minutes to win its first home opener in 12 years.  [212]onight the [199]iants travel to [195]hicago."
  604. 6000 ex=1:return
  605. 6010 :
  606. 6020 r$="[212]lx ctxgnw amrr kevynx fj vyn xmznx'w nhkn tp [195]xmhej nznpmpk ecvnx hexo.  [214]yn mpzewmtp amrr veon sregn tp [215]evlxhej ev heap; ctrrta vyn newvnxp xtlvn."
  607. 6030 s$="[207]ur forces will gather by the river's edge on [198]riday evening after dark.  [212]he invasion will take place on [211]aturday at dawn; follow the eastern route."
  608. 6040 ex=1:return
  609. 6050 :
  610. 6060 r$="[209]b ouiv luyo psa boa gizpn u lzpgiog xsigv  [211]e alua aspjzo'v zaaoiupfo boa [203] npsx alo vszpg. [213]ia alsz psa isqos upg u qspaujzo?    [216]khhkuq [214]lunovrouio"
  611. 6070 s$="[205]y ears have not yet drunk a hundred words  [207]f that tongue's utterance yet [201] know the sound. [193]rt thou not [210]omeo and a [205]ontague?    [215]illiam [211]hakespeare"
  612. 6080 ex=1:return
  613. 6090 :
  614. 6100 : ***  demonstration solution  ***
  615. 6110 :
  616. 6120 print "[147][145]":sl=6:s1=4:b$=chr$(j)
  617. 6130 r$="vw'r wvyq wn dqhtq wjq znyafwqs uns h ijvdq hol znyq wn wjq whbdq uns lvooqs."
  618. 6140 n=len(r$):poke 648,8:print "[147]"
  619. 6150 sys 853,4,12:gosub 2270:gosub 2120, setup
  620. 6160 sys 853,8,4:gosub 2280:gosub 1050, page 2
  621. 6170 sys 853,4,4
  622. 6180 :
  623. 6190 m$(1)="[129] [212]he cryptogram is printed above,"
  624. 6200 m$(2)="[129] then the solution just beneath."
  625. 6210 m$(3)="[129] [217]our input goes in the area below."
  626. 6220 m$(4)=" [204]et's give it a try..."
  627. 6230 gosub 7180:gosub 7340:if ff then 7130
  628. 6240 :
  629. 6250 m$(1)="[153] [212]his sample puzzle appears to be"
  630. 6260 m$(2)="[153] meaningless.  [200]owever, with a"
  631. 6270 m$(3)="[153] little care it is easily decoded,"
  632. 6280 m$(4)="[153] in this case in seven easy steps."
  633. 6290 gosub 7330:if ff then 7130
  634. 6300 :
  635. 6310 m$(1)="[158] [211]tep 1:  [129][204]et's see if it's a"
  636. 6320 m$(2)="[129]  simple offset puzzle by pressing"
  637. 6330 m$(3)="[129]  '*' and watching a few of the"
  638. 6340 m$(4)="[129]  26 solutions that are generated."
  639. 6350 :
  640. 6360 b$="*":gosub 7410
  641. 6370 if ff then 7130
  642. 6380 for a=k to 71:gosub 1380:a=a+k*peek(kb):next:poke kb,.
  643. 6390 for i=1 to n:s(i)=asc(mid$(r$,i,1)) and k7:next
  644. 6400 for i=k to l:e(i)=i:next:os=0:gosub 1520
  645. 6410 :
  646. 6420 m$(1)="        - [206]o [204]uck [212]here -"
  647. 6430 m$(2)="[153]     [208]ress _ to view the"
  648. 6440 m$(3)="[153]     second screen, and check"
  649. 6450 m$(4)="[153]     the frequency of letters."
  650. 6460 b$="_":gosub 7410
  651. 6470 s1=8:if ff then 7130
  652. 6480 :
  653. 6490 poke 53265,11:sys 853,8,8:gosub 1080:poke 53265,27
  654. 6500 m$(1)=" [158][211]tep 2: [153][209] appears"
  655. 6510 m$(2)=" [153]most often, but [197]"
  656. 6520 m$(3)=" [153]is most common in"
  657. 6530 m$(4)=" [153][197]nglish.  [211]witch"
  658. 6540 m$(5)=" [153]these two letters"
  659. 6550 m$(6)=" [153]by pressing 'qe':"
  660. 6560 b$="qe":gosub 7410:if ff then 7130
  661. 6570 :
  662. 6580 gosub 1050:sys 853,8,8
  663. 6590 m$(1)="  [158][212]hat's better!"
  664. 6600 m$(3)="  [158][208]ress '_' to"
  665. 6610 m$(4)="  [158]see the first"
  666. 6620 m$(5)="  [158]screen again..."
  667. 6630 b$="_":gosub 7410
  668. 6640 s1=4:if ff then 7130
  669. 6650 :
  670. 6660 poke 53265,11:gosub 1520
  671. 6670 m$(1)=" [158][211]tep 3:  [129][204]ook at the puzzle: the"
  672. 6680 m$(2)=" [129]one-letter word in the middle must"
  673. 6690 m$(3)=" [129]be [193] or [201].  [204]et's assume it's [193],"
  674. 6700 m$(4)=" [129]and enter 'ha' to switch these:"
  675. 6710 b$="ha":gosub 7410:if ff then 7130
  676. 6720 sys 853,4,4
  677. 6730 :
  678. 6740 m$(1)=" [158][211]tep 4:  [153][206]ote the 3-letter word"
  679. 6750 m$(2)=" [153]ending in [197]: 'wje'.  [211]ince it"
  680. 6760 m$(3)=" [153]occurs twice, assume it's [212][200][197]."
  681. 6770 m$(4)=" [153][197]nter 'wt', then 'jh' to switch:"
  682. 6780 b$="wt":gosub 7410:sys 853,4,4:if ff then 7130
  683. 6790 b$="jh":gosub 7420:sys 853,4,4:if ff then 7130
  684. 6800 :
  685. 6810 m$(1)=" [158][211]tep 5:  [129][212]he apostrophe has one"
  686. 6820 m$(2)=" [129]letter after- likely [211] or [212], and"
  687. 6830 m$(3)=" [129]since we've already solved for [212],"
  688. 6840 m$(4)=" [129]it must be [211].  [197]nter 'rs':"
  689. 6850 b$="rs":gosub 7410:if ff then 7130
  690. 6860 sys 853,4,4
  691. 6870 :
  692. 6880 m$(1)=" [158][211]tep 6:  [153][195]heck the 1st word again."
  693. 6890 m$(2)=" [153][215]e've identified [164][212]'[211], so the 1st"
  694. 6900 m$(3)=" [153]letter must be a vowel, likely"
  695. 6910 m$(4)=" [153][201].  [210]eplace the letter [214] with [201]:"
  696. 6920 b$="vi":gosub 7410:if ff then 7130
  697. 6930 sys 853,4,4
  698. 6940 :
  699. 6950 m$(1)=" [158][211]tep 7: [150][212]he third word must be [212][207]."
  700. 6960 m$(2)=" [150][212]he second is likely [212][201][205][197]."
  701. 6970 m$(3)=" [150][212]here are now enough clues to"
  702. 6980 m$(4)=" [150]make the remaining substitutions:"
  703. 6990 b$="no":gosub 7330:if ff then 7130
  704. 7000 gosub 7450:sys 853,4,4
  705. 7010 b$="ym":gosub 7450
  706. 7020 b$="dl":gosub 7450
  707. 7030 b$="zc":gosub 7450
  708. 7040 b$="jp":gosub 7450
  709. 7050 b$="uf":gosub 7450
  710. 7060 b$="wv":gosub 7450
  711. 7070 :
  712. 7080 m$(1)="      [214]oila:  [212]he message"
  713. 7090 m$(2)="      has been decoded!"
  714. 7100 m$(3)="[159]      [217]ou would now print the"
  715. 7110 m$(4)="[159]      solution, or exit."
  716. 7120 gosub 7330
  717. 7130 print"[147][145]":return
  718. 7140 :
  719. 7150 : **  message (NULL)  **
  720. 7160 :
  721. 7170 if s1=8 then 7260
  722. 7180 sys 828,8,2:print "[156][180][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][170]"
  723. 7190 for i=1 to 4
  724. 7200 print tab(2) "[156][180][146]                                   [170][145]"
  725. 7210 print tab(3) m$(i):m$(i)=""
  726. 7220 next
  727. 7230 print "[156]  [180][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][170]"
  728. 7240 return
  729. 7250 :
  730. 7260 c$="[156][182]                    [181][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157]":b=17:c=828
  731. 7270 sys 828,6,b:print "[156][182][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][181]"
  732. 7280 for i=1 to 6:print tab(b) c$ m$(i):next
  733. 7290 print tab(b) "[156][182][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][181]"
  734. 7300 for i=1 to 6:m$(i)="":next
  735. 7310 return
  736. 7320 :
  737. 7330 gosub 7170
  738. 7340 sys 828,13,9:print "[181] [208]ress the [211]pace [194]ar [146][156][182]"
  739. 7350 for i=1 to 1500:gosub 5740:if as=32 then return
  740. 7360 if a$=right$(b$,1) then return
  741. 7370 if a$=left$(b$,1) then sys 828,22:print a$ "[166][157]";
  742. 7380 if ff then return
  743. 7390 next:return
  744. 7400 :
  745. 7410 gosub 7170:poke 53265,27
  746. 7420 sys 828,22:print "[159][166]  [157][157][157]";
  747. 7430 sys 828,22:poke 204,0
  748. 7440 gosub 7350:poke 204,1
  749. 7450 sys 828,22:print "[159]"b$"[166]"
  750. 7460 gosub 1230:if s1=4 then gosub 1520
  751. 7470 return
  752. 7480 :
  753.