globals [ ;; variables for managing the user's work in the model and for avoiding clashes between procedures ;; that occur when users press buttons counter to the logic of the model instructions am-I-set-up? key-exists? abort-create-key? all-order-match? all-no-order-match? wait-a-moment? patches-in-block ;; variables for keeping track of accumulating statistical data through an experiment count-steps #choices color-list dice-list colorotation dice-rotation no-order-choices no-order-choices-check no-order-success? count-order-successes #order-successes-per-sample-list mean-order-per-sample samples-counter count-no-order-successes #no-order-successes-per-sample-list mean-no-order-per-sample ] patches-own [my-color my-shape] breeds [frames dice] ;; frames are the black perimeters of patches that help the user distinguish between ;; neighboring patches of same color. The frames are constant throughout the experiment ;; and are never part of the statistical analysis. to startup initialize ask patches [set pcolor brown] set instructions "Hi! " + " Try the preset slider values or set your own now (and not later!) and then press Setup." end to initialize ca ;; Please see the NetLogo turtorial for the rationale of these color numbers set color-list [55 105 125 85 135 0] ;; Please see the Shapes Editor in the Tools drop-down menu to relate between ;; items in the dice-list and their corresponding images. set dice-list ["one" "two" "three" "four" "five" "six"] ;; These two variables track the key search according to the two interpretation of what a success is (see Info tab) set all-order-match? false set all-no-order-match? false ;; Variables for managing use of the model set key-exists? false set am-I-set-up? false ;; Variables for selecting and searching values set colorotation [] set dice-rotation [] set no-order-choices [] set #order-successes-per-sample-list [] set #no-order-successes-per-sample-list [] set display? true set bars? true set wait-a-moment? false set abort-create-key? false set #choices how-many-choices? end ;;-------------------------------------------------------------------------------------------------------- ;;-------------------------------------------------------------------------------------------------------- to setup locals [running?] set running? count-steps wait .1 if running? != count-steps [set wait-a-moment? true wait .5 set instructions "First, unpress 'search-key'" set wait-a-moment? false stop] display initialize create-block create-frames set instructions "OK, you have created a " + width + "-by-" + height + " block with " + count patches-in-block + " patches in it. Now press 'create-key.'" set am-I-set-up? true end ;; The following procedure is perhaps more elaborate than is called for, but it is powerful in that ;; it will work if you decide to modify the 'width' and 'height' setting to greater maximum values to create-block locals [x-pos x-neg y-pos y-neg] ifelse (width / 2) = floor (width / 2) [set x-pos (width / 2) set x-neg (- ( (width / 2) - 1))] [set x-pos floor (width / 2) set x-neg (- (floor (width / 2)))] ifelse (height / 2) = floor (height / 2) [set y-pos (height / 2) set y-neg (- ( (height / 2) - 1))] [set y-pos floor (height / 2) set y-neg (- (floor (height / 2)))] set patches-in-block patches with [pxcor <= x-pos and pxcor >= x-neg and pycor <= y-pos and pycor >= y-neg] ask patches-in-block [set pcolor green] ask patches with [pcolor != green] [set pcolor brown] end to create-frames ;;the patch perimeters set-default-shape frames "frame" ask patches-in-block [ sprout 1 [ set breed frames set color black ] ] end to create-key set display? true if not dice? [ask dice [die]] if abort-create-key? [stop] if not am-I-set-up? [alert-setup stop] set instructions "1) Mouse-click on the patches to create your key. " + " Repeated clicks will change appearance. 2) UNPRESS the button. 3) Press 'hide-key'." ifelse dice? [set-dice-rotation] [set-colorotation] assign-color-or-image ;; explaining to the user the order of actions that is suitable for running this model if (dice? and (how-many-choices? != #choices) ) or (not dice? and (how-many-choices? != #choices ) ) [set how-many-choices? #choices set instructions "Sorry. You can't change the 'how-many-choices?' slider now. If this is what you want," + " please unpress 'create-key', set the slider and press setup." wait 5] how-many-of-each-choice? set key-exists? true end ;; coordinating between user's clicks on the patches in the key and values of these patches to assign-color-or-image if mouse-down? [ ask patches-in-block with [(pxcor = round mouse-xcor) and (pycor = round mouse-ycor) ] [ ifelse dice? [ ifelse count dice-here < 1 [ sprout 1 [ set breed dice set color black set shape "one" ] ] [ ;; see NETLOGO FEATURE in the Information window. ask dice-here [set shape item ((1 + position shape dice-rotation) mod #choices) dice-rotation ] ] ] [ ;; see NETLOGO FEATURE in the Information window. set pcolor item ((1 + position pcolor colorotation) mod #choices) colorotation ] wait .3 ] ] ask patches-in-block [ ifelse dice? [ask dice-here [set my-shape shape ]] [set my-color pcolor] ] end ;; For the no-order condition, counts up how many values of each choice to how-many-of-each-choice? locals [rotation-counter] set rotation-counter 0 set no-order-choices [] repeat #choices [ ifelse dice? [set no-order-choices lput count dice with [shape = item rotation-counter dice-rotation] no-order-choices] [set no-order-choices lput count patches-in-block with [pcolor = item rotation-counter colorotation ] no-order-choices] set rotation-counter rotation-counter + 1 ] end ;; Creates list from part of the color-list. See also NETLOGO FEATURE in the Information window. to set-colorotation locals [color-list-counter] ifelse length colorotation = #choices [stop] [set colorotation [] ] repeat #choices [ set colorotation lput (item color-list-counter color-list) colorotation set color-list-counter color-list-counter + 1 ] end ;; Creates list from part of the dice-list. See also NETLOGO FEATURE in the Information window. to set-dice-rotation locals [dice-list-counter] ifelse length dice-rotation = #choices [stop] [set dice-rotation [] ] repeat #choices [ set dice-rotation lput (item dice-list-counter dice-list) dice-rotation set dice-list-counter dice-list-counter + 1 ] end to hide-key if not am-I-set-up? or not key-exists? [alert-setup stop] set abort-create-key? true set instructions "You are now ready for the stochastic key hacking. If you give up, press 'reveal-key.'" + " Now press 'search-key.'" ;; Patches in the key remember their values but change into a neutral appearance if dice? [ask dice [ht] stop] ask patches-in-block [set pcolor yellow] end to search-key locals [calc-order-help calc-no-order-help] ;; managing the user-code interface if not am-I-set-up? or not key-exists? [alert-setup stop] set abort-create-key? true if wait-a-moment? [wait 4 display] if not wait-a-moment? [set instructions "Patches are repeatedly and simultaneously" + " choosing one of the choices randomly and recording " + " the number of times the secret key is matched."] if dice? and count dice = 0 [set instructions "You are in dice mode. Please first set up your dice or change to color mode" stop] ifelse dice? [set how-many-choices? length dice-rotation] [set how-many-choices? length colorotation] ;; These two Boolean variables track whether a search is successful. The point is that by default the search is ;; considered a success, that is the guessed key matches the secret key, but in the check procedure if ;; there is a mismatch it is found out. set all-order-match? true set all-no-order-match? true ask patches-in-block [guess] ask patches-in-block [check] check-no-order set count-steps count-steps + 1 ;; In case of a match between the guessed and checked key, the search is "called off" and either it starts again, or ;; in the case of single-success, the model stops running. This applies both to order-matters, and, below, to no-order. if order-matters? != "no" [ if all-order-match? [ call-off-order-search if single-success? [ display set calc-order-help ( length #order-successes-per-sample-list * sample-size ) + count-steps set instructions "Congratulations! You hacked the hidden key in " + calc-order-help + " steps. " + "Set up and try again." wait .5 set count-steps 0 set count-order-successes 0 set #order-successes-per-sample-list [] stop ] ] ] if ( order-matters? = "no" ) or ( order-matters? = "both" ) [ if all-no-order-match? [ call-off-no-order-search if single-success? [ display set calc-no-order-help ( length #no-order-successes-per-sample-list * sample-size ) + count-steps set instructions "Congratulations! You hacked the hidden key in " + calc-no-order-help + " steps. " + "Set up and try again." wait .5 set count-steps 0 set count-no-order-successes 0 set #no-order-successes-per-sample-list [] stop ] ] ] ifelse display? [display] [no-display] if count-steps = sample-size [plot-sample] end ;; the model guesses by trying out a combination of random values from the dice or color lists to guess ;; patches-in-block procedure ifelse dice? [ ask dice-here [set shape item ( random length dice-rotation ) dice-rotation st] ] [set pcolor item ( random length colorotation ) colorotation] end ;; if a non-correspondence was found between the guessed and original key, this specific search trial is registered as failed to check ;; patches-in-block procedure ifelse dice? [ask dice-here [if shape != my-shape [set all-order-match? false] ] ] [if pcolor != my-color [set all-order-match? false]] end ;; For no order, we have earlier made a list of how many times each value appears in the key. ;; Now we create the guessed-key list, then compare this list to the original-key list. to check-no-order locals [rotation-counter] set rotation-counter 0 set no-order-choices-check [] repeat #choices [ ifelse dice? [set no-order-choices-check lput count dice with [shape = item rotation-counter dice-rotation] no-order-choices-check] [set no-order-choices-check lput count patches-in-block with [pcolor = item rotation-counter colorotation ] no-order-choices-check] set rotation-counter rotation-counter + 1 ] set rotation-counter 0 ifelse no-order-choices-check = no-order-choices [set all-no-order-match? true] [set all-no-order-match? false] end ;; This and the following procedure could have appeared in the search-key procedure but ;; we preferred this order for the coherency of the search-key rationale to call-off-order-search set count-order-successes count-order-successes + 1 end to call-off-no-order-search set count-no-order-successes count-no-order-successes + 1 end to reveal-key set abort-create-key? true wait 1 if not am-I-set-up? or not key-exists? [alert-setup stop] set wait-a-moment? true wait .5 display ifelse dice? [ask dice [set shape my-shape] ] [ask patches-in-block [set pcolor my-color] ] no-display set instructions "Here is the secret key. To start again, press 'setup.'" wait 5 set am-I-set-up? false set wait-a-moment? false end to alert-setup set instructions "Please work this way: press 'setup,' and then 'create-key'" end to plot-sample set samples-counter samples-counter + 1 set #order-successes-per-sample-list fput count-order-successes #order-successes-per-sample-list set #no-order-successes-per-sample-list fput count-no-order-successes #no-order-successes-per-sample-list ifelse order-matters? = "yes" [set-plot-x-range 0 ( max list (2 * ceiling ( mean #order-successes-per-sample-list ) ) .1 )] [set-plot-x-range 0 ( max list (2 * ceiling ( mean #no-order-successes-per-sample-list ) ) .1 )] ;; In order to collapse two procedures into one, we use (below) the do-plot procedure. ;; Here, we assign values for this procedure according to the two conditions of search (order and no-order). if order-matters? != "no" [ do-plot #order-successes-per-sample-list "order" ] if ( order-matters? = "no" ) or ( order-matters? = "both" ) [ do-plot #no-order-successes-per-sample-list "no-order" ] end ;; see 7 lines above in previous procedure to do-plot [ event-list current-plot-name ] set-current-plot-pen current-plot-name ifelse bars? [set-plot-pen-mode 1] [set-plot-pen-mode 0] histogram-list event-list set count-steps 0 set count-no-order-successes 0 set count-order-successes 0 end ;; procedure for running repeatedly between the #1 thru #6 monitors and updating their values. to-report # [index] ifelse ( #choices >= index ) [report item (index - 1) no-order-choices] [report "N/A"] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; ; Copyright 2002 by Uri Wilensky. Updated 2002. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (2002). NetLogo Stochastic Cryptology model. ; http://ccl.northwestern.edu/netlogo/models/StochasticCryptology. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/StochasticCryptology ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 390 60 760 291 4 2 40.0 1 10 1 1 1 CC-WINDOW 427 538 756 639 Command Center BUTTON 9 377 150 410 NIL reveal-key NIL 1 T OBSERVER SLIDER 147 161 389 194 how-many-choices? how-many-choices? 2 6 3 1 1 NIL MONITOR 608 416 729 465 # steps this sample count-steps 3 1 MONITOR 478 486 558 535 ORDER count-order-successes 3 1 MONITOR 328 562 422 611 max-order max #order-successes-per-sample-list 3 1 MONITOR 9 562 103 611 min-order min #order-successes-per-sample-list 3 1 SWITCH 9 343 150 376 single-success? single-success? 1 1 -1000 MONITOR 431 416 499 465 #samples samples-counter 0 1 SWITCH 319 377 422 410 display? display? 0 1 -1000 SWITCH 152 377 255 410 bars? bars? 0 1 -1000 MONITOR 430 364 480 413 NIL # 1 3 1 MONITOR 478 364 528 413 NIL # 2 3 1 MONITOR 529 364 579 413 NIL # 3 3 1 MONITOR 579 364 629 413 NIL # 4 3 1 MONITOR 629 364 679 413 NIL # 5 3 1 MONITOR 679 364 729 413 NIL # 6 3 1 MONITOR 9 614 103 663 min-no-order min #no-order-successes-per-sample-list 3 1 MONITOR 327 614 422 663 max-no-order max #no-order-successes-per-sample-list 3 1 MONITOR 559 486 639 535 NO-ORDER count-no-order-successes 3 1 TEXTBOX 494 467 650 485 Successes in this sample: TEXTBOX 485 334 748 358 How many objects of each choice: BUTTON 6 90 142 230 NIL setup NIL 1 T OBSERVER BUTTON 7 234 141 291 NIL create-key T 1 T OBSERVER BUTTON 260 254 389 291 NIL hide-key NIL 1 T OBSERVER BUTTON 147 235 253 291 NIL search-key T 1 T OBSERVER MONITOR 7 10 761 59 NIL instructions 0 1 SLIDER 146 91 388 124 width width 1 5 3 1 1 NIL SLIDER 147 126 389 159 height height 1 2 1 1 1 NIL MONITOR 105 562 326 611 mean order successes per sample mean #order-successes-per-sample-list 1 1 PLOT 9 412 422 560 frequency distribution successes-per-sample frequency 0.0 100.0 0.0 50.0 true true PENS "order" 1.0 1 -16777216 true "no-order" 1.0 1 -65536 true SLIDER 7 293 760 326 sample-size sample-size 1 100000 100 1 1 NIL SWITCH 147 197 254 230 dice? dice? 1 1 -1000 MONITOR 105 614 326 663 mean no order successes per sample mean #no-order-successes-per-sample-list 1 1 CHOICE 260 204 389 249 order-matters? order-matters? "no" "yes" "both" 0 @#$#@#$#@ WHAT IS IT? ----------- This model is a part of the ProbLab curriculum. The ProbLab Curriculum is currently under development at the CCL. For more information about the ProbLab Curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/. "Stochastic Cryptology," a mathematics microworld, uses the challenging and fun science of cryptology as a metaphor for introducing fundamental concepts of the domain of Probability & Statistics, through engaging activity. In this model, you will set, hide, and hack a secret "key." A key can be thought of as any code, such as a password (e.g., "jellyfish"), credit card number (e.g., 1234 5678 9012 3456), or lock combination (e.g., 25 11 65). You get to set a code, then simulate how many steps (or, how much time, if you will) it would take to blindly guess and try out one combination after another until you succeed in cracking the entire key. By running the model repeatedly, you will come to relate between variables, values, and the number of all possible outcomes. 'Variables' are like placeholders, for example "3-4-5-6" has 4 variables. Values are what each variable can possibly be, for example, a digit between 1 and 6. If there are 4 variables and each can take 6 different values, then how many different keys can you create under these conditions? I would have to tell you, though, if I am willing to accept "6-4-5-3" as just as good as "3-4-5-6": The model monitors two types of "locks." For one type of lock, "order matters," the combination 6-4-5-3 is not the same as combination 3-4-5-6, that is, these outcomes are mutually exclusive events. For instance, if you were opening a combination lock, it is crucial that you set the numbers in the correct order. But in the other type of lock, "order doesn't matter," these two combinations are considered the same. For instance, if your friend told you he has 3 siblings, and you guessed they were "2 sister, 1 brother," then it doesn't matter who was born first (sis-sis-bro; sis-bro-sis; bro-sis-sis). The model allows us to compare the random searches for the correct key under either or both lock systems. Probability is closely related to statistics. If all you are interested in is finding a simple key once, then you don't really need to carry out any search at all. But if you're searching for the code more than just once, you may be interested to know some things about what's going on in this search. When we conduct a search under conditions of uncertainty, we can keep track of the goodness of our search algorithm by taking repeated samples. One way of managing this is to take a sample of a fixed number of guesses, for instance 100 guesses. Some of these guesses will be correct. For instance, we may find that 7 guesses out of the 100 guesses were correct, or "successes." Does this mean that exactly 7 guesses will be correct next time? More? Less? If I take a larger sample, for instance 200 guesses, will I have a different number of successes? What if my friend ran the same simulation and got 21 successes out of 100? Is one of us "correct" and the other "wrong"? Once you have mastered all that can be done on the interface of this model, you may wish to tamper with the code itself. There is good reason to do so: If you had to search for a three-digit code, would you really keep on guessing blindly until you happened to get it right? Currently, the search algorithm is not too "intelligent" -- maybe you can do better (see 'Extending the Model' section for suggestions). Such work offers you opportunities to understand some basic notions in computer sciences, such as procedures, lists, and the limits of memory. HOW IT WORKS ------------ Follow the instructions in the "instructions" monitor window, which will lead you through the following process: You may wish to begin with the pre-set values of the sliders, but basically, once you have set up the block dimensions with the 'width' and 'height' values, press 'setup,' and then set the values of the 'how-many-choices?' slider and the 'order-matters?' choice and press the 'create-key' button. Set the 'dice?' switch either "on," to work with dice, or "off", to work with colors. Click on individual patches repeatedly until you are happy with your key, and then click the 'hide-key' button. Once you press the 'search-key' button, what happens is the following: At every "step," each place-holder randomly chooses a die face (or a color) from the exact same list of die faces (or of colors) you used to create your key. If and only if all the patches have simultaneously chosen their secret value, then this instance is registered as a "success." If you have set the 'single-success?' switch to "on" then the search is over, and you can reflect on it and start again. However, if you have set the 'single-success?' button to "off," then the program will begin a new search and will work on and on until you stop it manually. Various monitors (see below) help you track the statistics of this process as they evolve. HOW TO USE IT ------------- See previous section. Many people first come across probability problems involving the tossing of coins or the rolling of dice. If you feel comfortable with such tasks, you are welcome to enter this program by simulating these tasks. To toss a single coin, you need a 1-by-1 block -- that is, one coin -- and 2 colors. Setting up the color key, you could think of green as "heads" and blue as "tails." Now, if the "single-success" switch is set to "yes," you can press 'search-key.' Pretty immediately, the program will discover the "key," which here is simply either green or blue. How about tossing 2 coins? 3 coins?... 10 coins? What happens to the time it takes to find the key as a result of your increasing the number of coins? Also, if you were tossing 2 identical coins, you probably wouldn't know which is which, once they fell. So how many combinations do 2 coins have? That is a trick question. It all depends on whether or not order matters: Is "heads; tails" the same as "tails; heads"? How about dice? Roll 1, 2, 3, or more dice, with each bearing either 6 colors -- representing 6 different number sides -- or less. (Funky, huh? A die with five sides...) Because each of the dice have a specific location, getting a "3 ; 5" looks different from getting a " 5 ; 3". But, as you know, when rolling identical dice we cannot tell which is which. So perhaps "3 ; 5" is the same as "5 ; 3". Certainly, if all you care about is getting an 8. But then again, you may care to know if getting a 7 is easier than getting an 8 (see Extension). Buttons 'setup' - prepares the size of the patch population according to the block-size slider value. 'create-key' - allows you to use the mouse to click on patches in the block. Clicking rotates their die-face / color through an option cycle that has as many options as the value you set for the 'how-many-choices?' slider. 'hide-key' - once you have set your key this button causes patches to "remember" their key settings, and then hide them. 'search-key' - activates the random search: Patches in the block all flash randomly between the dice/colors options, stopping only when all patches are together showing the key. 'reveal-key' - if you've given up, you can always press this to peek at the secret key. Sliders: 'how-many-colors?' - set the number of colors you wish to include in your key and in the search. 'width' and 'height' - the width and height dimensions, respectively, of the block you are creating. 'sample-size' - set the number of guesses per sample Choices: 'order matters?' - "no" - That is, order does not matter, so the key '1 2 3' is technically the same as the key '3 2 1' "yes" - That is, order matters, so the key '1 2 3' is not accepted as the same as the key '3 2 1' "both" - That is, the experiments will monitor the events from both perspectives, and each will be represented in monitors, graphs. Switches: 'single-success?' - If "on," the program will stop running after it has hacked the key once. If "off," the program will continue running indefinitely. 'dice?' - toggles between two options: "on" means you will be creating and searching dice keys "off" means you will be creating and searching color keys bars? - "yes" gives you a histogram in the plot window; "no" gives you a graph. 'display?' - toggles between the display and no-display commands. This switch hides or reveals the graphics-window activity. The program continues to run as usual even if you cannot see the patches changing. Monitors: The following three explanations apply to both the ORDER and the NO ORDER monitors mean successes per sample - Shows the average number of successes to have occurred over all samples since this search began min - shows the minimum number of successes to have occurred in a single sample, over all samples max - shows the maximum number of successes to have occurred in a single sample, over all samples #samples - shows how many samples have run up to this moment #steps in this sample - counts guesses and resets back to 0 each time a sample has been completed. Steps in this sample - show how many guesses (or "attempts") the program has conducted in this sample, regardless of whether or not they were successful. Successes in this sample (applies both to ORDER and to NO ORDER)- shows how many successes (hit guesses) the program has performed this sample #1 thru #6 - These six monitors correspond, respectively, to the six options of the how-many-choices? When you have set up your key, these monitors will accumulate your setting according to type. For example, if you have set the dice? to "on," the how-many-choices? to 4 and have set up the dice faces: '4 2 1 1 2', then Monitor #1 will show "2" because there are two '1's in your key. Monitor #2 will show "2" because there are two '2's in your key. Monitor #3 will show "0" because there are no '3's in your key, even though there could have been. Monitor #4 will show "1" because there is just a single '3' in your code. Monitors #5 and #6 show "N/A" ("not available") -- telling us that there cannot be any number here, since the '5' and the '6' dice faces were not in your pool of choices. You would have to move your how-many-choices? slider up to 5 or even 6 in order to have those dice faces as choices for a new setting. If you press SETUP with how-many-choices set to, say, 4, the monitors show different values whether you are in dice? "yes" or "no" mode. This is because in the dice? "no" mode the monitors are following the color of the patches, whereas in dice? "yes" mode they are following the numbers themselves. Plot 'frequency distribution' - shows the distributed frequency of successes per sample for ORDER, NO ORDER, or both. THINGS TO TRY ------------- If you work with a friend, then they can try to set up "difficult" keys for you to hack. What is a "difficult key," anyway? Discuss this, and try out your hypotheses. Think about whether the computer has the same criteria as you do for determining what makes a key "difficult." Look at the shape of the graph(s) in the plot window as it develops. Run the program under different settings and see how, if at all, these setting combinations affect the shape of the graph(s). When you are working in the 'both' mode of the 'order-matters?' choice, you will get readings for both the "order matters" and the "order doesn't matter." Choose a key, say how-many-choices? set at 2 and the dice set at '1 1 2', and run the model. Look at the means of the ORDER and the NO ORDER and estimate the ratio between them. Is this ratio stable? What, if at all, could affect this ratio? For instance: - set the model again, changing only the how-many-colors? from 2 to 3 and run the model - set the model again. This time, change from the original by adding another die. Look at the two graphs, the red and the black. What else can you say about them? Is one of them always wider? taller? Do the graphs ever overlap so you see only the red graph? Where is the black graph? Keep doing this activity, and create a table in which you summarize your findings. Make sure to run the model long enough for it to stabilize. By the way, how come it takes time to stabilize? How do you know that it (the distribution) has stabilized -- according to the graph? -- according to the numbers? Here's another angle on the same question: Are some keys guessed quicker than others? Would you answer the same way for both the ORDER and the NO ORDER modes? If you can chart all possible keys, given a simple setting, try answering this methodically. THINGS TO NOTICE ---------------- Currently, when the program searches it does so only through as many colors as you have used to set the key. That is, if you have used only 2 colors to set your key, the program will search through 2 colors. Perhaps this is not how cryptology really works. For instance, some passwords are case sensitive and some are not. So even if we know how many variables there are, we don't always know what all the values could be. On the other hand, you may be searching too much: Perhaps there are fewer values than you think. For instance, in some university departments, all 5-digit internal-phone numbers begin with a "7." So even though there's a '7' up there, it's not really something you need to guess. It is very easy to get involved with huge numbers in this model. If you set the width, height, and the how-many-choices? sliders to their maximum, you will need a big sample-size in order to contain, on average, even a single success! Play with these sliders and try to get a sense of how different values of different variables affect the expected frequency. NETLOGO FEATURES ---------------- The model uses a "rotating" list containing choice of color or dice faces both for building and searching for the key. All in all, there are 6 optional colors or dice faces. These lists are created in the "initialize" procedure: | set color-list [55 105 125 85 135 0] | set dice-list ["one" "two" "three" "four" "five" "six"] Once the user has designated how-many-choices? they want, a part of this list is copied onto a new list -- either the colorotation or the dice-rotation -- in the "set-colorotation" and "set-dice-rotation" procedures, respectively. Later, in the search-key procedure (actually, in the 'guess' subprocedure') the program will guess an item from the rotation list. (You may decide to change this -- currently the program "knows" your choices.) For instance, if the user chooses to work with 3 colors, then the colors 55, 105, and 125 (the 3 first colors of the color-list) are copied to the colorotation list. This is done by using a local variable that counts up as many choices as the user has set -- for every count an additional item from the list is copied onto the new list: | repeat #choices | [ | set colorotation lput (item color-list-counter color-list) colorotation | set color-list-counter color-list-counter + 1 | ] These lists are "rotating" lists because in the assign-color-or-image we move along the list and when we get to its end we start from the beginning of the list again. This gives the user a sense of a loop. For instance, a line of code in the assign-color-or-image procedure is the following: | set pcolor item ((1 + position pcolor colorotation) mod #choices) colorotation The critical code word in the above line is "mod." If we have 3 colors in the colorotation list, then "1 + position etc." could exceed the limit of only 3 colors and be 4. But there is no 4th color in the list. "Mod" looks at the number in front of it, in this case 3, and takes this number away from the number behind it if it is greater, in this case 4, so it is left with 1, and so the first item in the list is chosen. (try typing "show 4 mod 3" in the command center, then try "show 7 mod 3" etc.). EXTENDING THE MODEL ------------------- As you will eventually discover, the current hacking procedures are very basic. What can one do about this? Here's one suggestion: Add code so that once a patch has "guessed" its correct dice-face / color, it will stay that d.f. / color, regardless of whether or not the other patches are still searching for their d.f. / color. How would such code affect, if at all, the number of steps necessary for cracking the key? Can you establish some sort of equation for predicting how many steps, on average, it should take the system to crack the code under these new conditions? Perhaps you could add a switch on the interface for toggling between the existing search procedure and this new and improved procedure that you have implemented. Compete or collaborate with your friends to create the fastest hacking procedures. You would have to agree on how to evaluate the procedure's effectiveness. Also, there is the question of what types of crypts the procedure is suitable for. For instance, if you're trying to guess someone's phone number by repeatedly dialing numbers, then you don't get any feedback on whether or not some if any of your digits are correct. (This may remind you of aspects of a popular patented and trademarked game called "Master Mind".) Also, when you are personally attempting to guess any value and are receiving feedback as to whether your guess is correct or incorrect, you would not repeat an incorrect guess, right? Add a monitor to show, during the search, how many of the patches happen to be showing their key dice-face/color. For the dice simulation, add code, monitors, and perhaps probability-distribution graphs to explore: -the probability of getting each of the six faces over many rolls -the probability of getting a certain sum of two dice. CREDITS AND REFERENCES ---------------------- Thanks to Dor Abrahamson for his work on the design of this model and the ProbLab curriculum. To refer to this model in academic publications, please use: Wilensky, U. (2002). NetLogo Stochastic Cryptology model. http://ccl.northwestern.edu/netlogo/models/StochasticCryptology. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2002 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/StochasticCryptology for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 ant true 0 Polygon -7566196 true true 136 61 129 46 144 30 119 45 124 60 114 82 97 37 132 10 93 36 111 84 127 105 172 105 189 84 208 35 171 11 202 35 204 37 186 82 177 60 180 44 159 32 170 44 165 60 Polygon -7566196 true true 150 95 135 103 139 117 125 149 137 180 135 196 150 204 166 195 161 180 174 150 158 116 164 102 Polygon -7566196 true true 149 186 128 197 114 232 134 270 149 282 166 270 185 232 171 195 149 186 149 186 Polygon -7566196 true true 225 66 230 107 159 122 161 127 234 111 236 106 Polygon -7566196 true true 78 58 99 116 139 123 137 128 95 119 Polygon -7566196 true true 48 103 90 147 129 147 130 151 86 151 Polygon -7566196 true true 65 224 92 171 134 160 135 164 95 175 Polygon -7566196 true true 235 222 210 170 163 162 161 166 208 174 Polygon -7566196 true true 249 107 211 147 168 147 168 150 213 150 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 bee true 0 Polygon -256 true false 152 149 77 163 67 195 67 211 74 234 85 252 100 264 116 276 134 286 151 300 167 285 182 278 206 260 220 242 226 218 226 195 222 166 Polygon -16777216 true false 150 149 128 151 114 151 98 145 80 122 80 103 81 83 95 67 117 58 141 54 151 53 177 55 195 66 207 82 211 94 211 116 204 139 189 149 171 152 Polygon -7566196 true true 151 54 119 59 96 60 81 50 78 39 87 25 103 18 115 23 121 13 150 1 180 14 189 23 197 17 210 19 222 30 222 44 212 57 192 58 Polygon -16777216 true false 70 185 74 171 223 172 224 186 Polygon -16777216 true false 67 211 71 226 224 226 225 211 67 211 Polygon -16777216 true false 91 257 106 269 195 269 211 255 Line -1 false 144 100 70 87 Line -1 false 70 87 45 87 Line -1 false 45 86 26 97 Line -1 false 26 96 22 115 Line -1 false 22 115 25 130 Line -1 false 26 131 37 141 Line -1 false 37 141 55 144 Line -1 false 55 143 143 101 Line -1 false 141 100 227 138 Line -1 false 227 138 241 137 Line -1 false 241 137 249 129 Line -1 false 249 129 254 110 Line -1 false 253 108 248 97 Line -1 false 249 95 235 82 Line -1 false 235 82 144 100 bird1 false 0 Polygon -7566196 true true 2 6 2 39 270 298 297 298 299 271 187 160 279 75 276 22 100 67 31 0 bird2 false 0 Polygon -7566196 true true 2 4 33 4 298 270 298 298 272 298 155 184 117 289 61 295 61 105 0 43 boat1 false 0 Polygon -1 true false 63 162 90 207 223 207 290 162 Rectangle -6524078 true false 150 32 157 162 Polygon -16776961 true false 150 34 131 49 145 47 147 48 149 49 Polygon -7566196 true true 158 33 230 157 182 150 169 151 157 156 Polygon -7566196 true true 149 55 88 143 103 139 111 136 117 139 126 145 130 147 139 147 146 146 149 55 boat2 false 0 Polygon -1 true false 63 162 90 207 223 207 290 162 Rectangle -6524078 true false 150 32 157 162 Polygon -16776961 true false 150 34 131 49 145 47 147 48 149 49 Polygon -7566196 true true 157 54 175 79 174 96 185 102 178 112 194 124 196 131 190 139 192 146 211 151 216 154 157 154 Polygon -7566196 true true 150 74 146 91 139 99 143 114 141 123 137 126 131 129 132 139 142 136 126 142 119 147 148 147 boat3 false 0 Polygon -1 true false 63 162 90 207 223 207 290 162 Rectangle -6524078 true false 150 32 157 162 Polygon -16776961 true false 150 34 131 49 145 47 147 48 149 49 Polygon -7566196 true true 158 37 172 45 188 59 202 79 217 109 220 130 218 147 204 156 158 156 161 142 170 123 170 102 169 88 165 62 Polygon -7566196 true true 149 66 142 78 139 96 141 111 146 139 148 147 110 147 113 131 118 106 126 71 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 butterfly1 true 0 Polygon -16777216 true false 151 76 138 91 138 284 150 296 162 286 162 91 Polygon -7566196 true true 164 106 184 79 205 61 236 48 259 53 279 86 287 119 289 158 278 177 256 182 164 181 Polygon -7566196 true true 136 110 119 82 110 71 85 61 59 48 36 56 17 88 6 115 2 147 15 178 134 178 Polygon -7566196 true true 46 181 28 227 50 255 77 273 112 283 135 274 135 180 Polygon -7566196 true true 165 185 254 184 272 224 255 251 236 267 191 283 164 276 Line -7566196 true 167 47 159 82 Line -7566196 true 136 47 145 81 Circle -7566196 true true 165 45 8 Circle -7566196 true true 134 45 6 Circle -7566196 true true 133 44 7 Circle -7566196 true true 133 43 8 circle false 0 Circle -7566196 true true 35 35 230 five false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Circle -1 true false 182 180 41 Rectangle -16777216 true false 120 120 180 178 Circle -1 true false 76 178 41 Circle -1 true false 180 77 40 Rectangle -1 true false 200 97 206 106 Circle -1 true false 131 130 39 four false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Circle -1 true false 182 180 41 Rectangle -16777216 true false 120 120 180 178 Circle -1 true false 76 178 41 Circle -1 true false 180 77 40 Rectangle -1 true false 200 97 206 106 Circle -1 true false 131 130 39 Rectangle -16777216 true false 121 114 178 179 frame false 14 Rectangle -16777216 true true -8 2 18 298 Rectangle -16777216 true true 1 0 300 16 Rectangle -16777216 true true 283 2 299 300 Rectangle -16777216 true true 1 285 300 299 one false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Rectangle -16777216 true false 67 62 119 123 Rectangle -16777216 true false 186 182 223 227 Rectangle -16777216 true false 177 194 198 211 Rectangle -16777216 true false 58 55 128 136 Rectangle -16777216 true false 181 191 247 239 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 sheep false 15 Rectangle -1 true true 90 75 270 225 Circle -1 true true 15 75 150 Rectangle -16777216 true false 81 225 134 286 Rectangle -16777216 true false 180 225 238 285 Circle -16777216 true false 1 88 92 six false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Circle -1 true false 182 180 41 Rectangle -16777216 true false 120 120 180 178 Circle -1 true false 76 178 41 Circle -1 true false 180 77 40 Rectangle -1 true false 200 97 206 106 Circle -1 true false 74 130 40 Circle -1 true false 181 129 40 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 three false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Circle -1 true false 182 180 41 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 turtle true 0 Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 two false 0 Rectangle -16777216 true false 46 45 255 255 Circle -1 true false 129 130 41 Circle -1 true false 75 76 41 Circle -1 true false 185 182 38 Circle -1 true false 182 180 41 Rectangle -16777216 true false 122 120 177 175 wolf false 0 Rectangle -7566196 true true 15 105 105 165 Rectangle -7566196 true true 45 90 105 105 Polygon -7566196 true true 60 90 83 44 104 90 Polygon -16777216 true false 67 90 82 59 97 89 Rectangle -1 true false 48 93 59 105 Rectangle -16777216 true false 51 96 55 101 Rectangle -16777216 true false 0 121 15 135 Rectangle -16777216 true false 15 136 60 151 Polygon -1 true false 15 136 23 149 31 136 Polygon -1 true false 30 151 37 136 43 151 Rectangle -7566196 true true 105 120 263 195 Rectangle -7566196 true true 108 195 259 201 Rectangle -7566196 true true 114 201 252 210 Rectangle -7566196 true true 120 210 243 214 Rectangle -7566196 true true 115 114 255 120 Rectangle -7566196 true true 128 108 248 114 Rectangle -7566196 true true 150 105 225 108 Rectangle -7566196 true true 132 214 155 270 Rectangle -7566196 true true 110 260 132 270 Rectangle -7566196 true true 210 214 232 270 Rectangle -7566196 true true 189 260 210 270 Line -7566196 true 263 127 281 155 Line -7566196 true 281 155 281 192 wolf-left false 3 Polygon -6524078 true true 117 97 91 74 66 74 60 85 36 85 38 92 44 97 62 97 81 117 84 134 92 147 109 152 136 144 174 144 174 103 143 103 134 97 Polygon -6524078 true true 87 80 79 55 76 79 Polygon -6524078 true true 81 75 70 58 73 82 Polygon -6524078 true true 99 131 76 152 76 163 96 182 104 182 109 173 102 167 99 173 87 159 104 140 Polygon -6524078 true true 107 138 107 186 98 190 99 196 112 196 115 190 Polygon -6524078 true true 116 140 114 189 105 137 Rectangle -6524078 true true 109 150 114 192 Rectangle -6524078 true true 111 143 116 191 Polygon -6524078 true true 168 106 184 98 205 98 218 115 218 137 186 164 196 176 195 194 178 195 178 183 188 183 169 164 173 144 Polygon -6524078 true true 207 140 200 163 206 175 207 192 193 189 192 177 198 176 185 150 Polygon -6524078 true true 214 134 203 168 192 148 Polygon -6524078 true true 204 151 203 176 193 148 Polygon -6524078 true true 207 103 221 98 236 101 243 115 243 128 256 142 239 143 233 133 225 115 214 114 wolf-right false 3 Polygon -6524078 true true 170 127 200 93 231 93 237 103 262 103 261 113 253 119 231 119 215 143 213 160 208 173 189 187 169 190 154 190 126 180 106 171 72 171 73 126 122 126 144 123 159 123 Polygon -6524078 true true 201 99 214 69 215 99 Polygon -6524078 true true 207 98 223 71 220 101 Polygon -6524078 true true 184 172 189 234 203 238 203 246 187 247 180 239 171 180 Polygon -6524078 true true 197 174 204 220 218 224 219 234 201 232 195 225 179 179 Polygon -6524078 true true 78 167 95 187 95 208 79 220 92 234 98 235 100 249 81 246 76 241 61 212 65 195 52 170 45 150 44 128 55 121 69 121 81 135 Polygon -6524078 true true 48 143 58 141 Polygon -6524078 true true 46 136 68 137 Polygon -6524078 true true 45 129 35 142 37 159 53 192 47 210 62 238 80 237 Line -16777216 false 74 237 59 213 Line -16777216 false 59 213 59 212 Line -16777216 false 58 211 67 192 Polygon -6524078 true true 38 138 66 149 Polygon -6524078 true true 46 128 33 120 21 118 11 123 3 138 5 160 13 178 9 192 0 199 20 196 25 179 24 161 25 148 45 140 Polygon -6524078 true true 67 122 96 126 63 144 @#$#@#$#@ NetLogo 2.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@