Solvershttp://www.cryptoden.com/index.php/solvers2015-07-03T08:41:13+00:00Joomla! - Open Source Content ManagementUsing Javascript2013-02-07T13:38:31+00:002013-02-07T13:38:31+00:00http://www.cryptoden.com/index.php/solvers/using-javascriptSuper Usermikejcowan@me.com<div class="feed-description"><p><span style="font-family: verdana, geneva; font-size: small;">Javascript is a free programming language that already exists in your browser. You can use it right away! For solving cryptograms it is considerably faster than Python, some 20 times in my experience. On the downside it is a bit more complicated language to program.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Javascript runs inside your browser. The program code must be written in a web page, and then when the browser loads the page it sees the program lines and executes them. So we have two parts to the program: the webpage itself which is programmed in HTML and then the javascript code within the page.</span></p>
<h3><span style="font-family: verdana, geneva; font-size: small;">The HTML program.</span></h3>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">Let’s look at a simple example of the HTML program that makes the webpage. We want a green page that reads “Hello World” when we load it. First of all, type the code below into a Text Editor (I use TextWrangler):</span></p>
<p><span style="font-family: 'courier new', courier;"><html></span><br /><span style="font-family: 'courier new', courier;"><head></span><br /><span style="font-family: 'courier new', courier;"><script type="text/javascript"> </span><br /><span style="font-family: 'courier new', courier;"></script></span><br /><span style="font-family: 'courier new', courier;"></head></span></p>
<p><span style="font-family: 'courier new', courier;"><body bgcolor="green" ></span><br /><span style="font-family: 'courier new', courier;"><FONT FACE= "Verdana"></span><br /><span style="font-family: 'courier new', courier;"><h1>Hello World!</h1> </span><br /><span style="font-family: 'courier new', courier;"></body></span><br /><span style="font-family: 'courier new', courier;"></html></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Now </span><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">save it as Test.html and double-click it. A web page will open in your browser like this:</span></p>
<p style="text-align: center;"><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"><img src="images/Screen Shot 2013-02-07 at 15.53.08.png" border="0" alt="" /></span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"> </span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">For cryptogram solving the HTML program needs to ask for the ciphertext and display the solved plaintext and the key. Here is the HTML program:</span><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"> </span></p>
<p><span style="font-family: 'courier new', courier;"><html></span><br /><span style="font-family: 'courier new', courier;"><head></span><br /><span style="font-family: 'courier new', courier;"><script type="text/javascript"> </span><br /><span style="font-family: 'courier new', courier;"></script></span><br /><span style="font-family: 'courier new', courier;"></head></span><br /><span style="font-family: 'courier new', courier;"><body bgcolor="green" ></span><br /><span style="font-family: 'courier new', courier;"><h3>Cryptogram Solver</h3> (paste ciphertext into Input Area. Press button to solve and display plaintext & key in Output Area)<br><br></span><br /><span style="font-family: 'courier new', courier;">Input Area:<br></span><br /><span style="font-family: 'courier new', courier;"><textarea id="input_area" cols=80 rows = 5></span><br /><span style="font-family: 'courier new', courier;"></textarea><br></span><br /><span style="font-family: 'courier new', courier;">Output Area:<br></span><br /><span style="font-family: 'courier new', courier;"><textarea id="output_area" cols=80 rows = 8></span><br /><span style="font-family: 'courier new', courier;"></textarea><br></span><br /><span style="font-family: 'courier new', courier;">Button:<br></span><br /><span style="font-family: 'courier new', courier;"><input type="button" value="Solve" onclick=do_solve();></span><br /><span style="font-family: 'courier new', courier;"></body></span><br /><span style="font-family: 'courier new', courier;"></html></span></p>
<p> </p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">Save this as Test1, double-click it to get:</span></p>
<p style="text-align: center;"><img src="images/Screen Shot 2013-02-08 at 08.15.55.png" border="0" alt="" /></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">You will see there is an Input area for the ciphertext and an Output area where the solution will be displayed. Also a button to click to get things going.</span></p>
<h3><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript program. </span></h3>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript code which solves the cryptogram can be included in the HTML program but I prefer to make a separate program called a Web Worker. The HTML program contains enough javascript to send the ciphertext to the Web Worker and tell it to get started. The Worker carries out its programmed duties, reporting back results to the HTML program which then displays on your browser in the Output area.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript code that communicates with the Worker is put in the 'head' of the HTML program between the <script> and </script>. Here is the code:</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">var hclimber;</span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">function do_solve()</span></p>
<p><span style="font-family: 'courier new', courier;"> { </span><br /><span style="font-family: 'courier new', courier;"> var str;</span><br /><span style="font-family: 'courier new', courier;"> hclimber = new Worker('AP_worker.js');</span><br /><span style="font-family: 'courier new', courier;"> str = document.getElementById('input_area').value; </span><br /><span style="font-family: 'courier new', courier;"> hclimber.postMessage(str); </span><br /><span style="font-family: 'courier new', courier;"> hclimber.onmessage = function (event) </span><br /><span style="font-family: 'courier new', courier;"> {</span><br /><span style="font-family: 'courier new', courier;"> str = event.data;</span><br /><span style="font-family: 'courier new', courier;"> document.getElementById('output_area').value = str; </span><br /><span style="font-family: 'courier new', courier;"> }</span><br /><span style="font-family: 'courier new', courier;"> }</span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">On clicking the button, the function do_solve() is called. This makes the Worker 'hclimber', sends it the ciphertext and displays any data that comes back in the Output area.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">The main javascript program is in the <a href="programs/AP_worker.js">Worker -- click here to view it.</a> It solves monoalphabetic substitution ciphers. Because this is not a tutorial I am not going to go through it in detail. If you have read my Python tutorial you will have been through <a href="index.php/python/47-python-hillclimber">what this program is doing</a>. </span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">You can <a href="programs/Ari_Pat_WW.html">run the program here</a>. Paste the ciphertext below into the Input Area, press the button and the prtogram will put the plaintext in the Output area:</span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">OJNPZ FDWXJ UHDNI JGKFD QDPDQ JODHI XIFJK DSBZW NBQZH HBIZD VIDFF DHQIJ HSBQB JHHJF JHMDN NDLRB NDSUB ODEHJ UPDTD NXQAB HM.</span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">Many of the commands are different in the two languages and to help those who are interested I have summarised these below. </span></span></p>
<p><span style="font-family: 'courier new', courier;"> <span style="text-decoration: underline;"><strong>python</strong> </span> | <span style="text-decoration: underline;"><strong>javascript</strong></span></span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">x=randrange(26) | x=Math.floor(Math.random()*26);</span></p>
<p><span style="font-family: 'courier new', courier;"> alpha = "OJNPZ" | var alpha = "OJNPZ";</span><br /><span style="font-family: 'courier new', courier;"> value = [0,1,2,3,4] | var value = {0,1,2,3,4 }; </span><br /><span style="font-family: 'courier new', courier;"> len = len(alpha) | len = alpha.length;</span><br /><span style="font-family: 'courier new', courier;"> t=0 | var t=0;</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">index = [0]*26 | var index=new Array(26);</span></p>
<p><span style="font-family: 'courier new', courier;"> cipher=['A']*200 | var cipher=new Array(200);</span><br /> <br /><span style="font-family: 'courier new', courier;"> x = ord(alpha[j])-65 | x = alpha.charCodeAt(j)-65; </span><br /><span style="font-family: 'courier new', courier;"> pt =chr(x+97) | pt = String.fromCharCode(x+97);</span><br /> <br /><span style="font-family: 'courier new', courier;"> ch = alpha[j] | ch = alpha.charAt(x);</span><br /><span style="font-family: 'courier new', courier;"><span>alpha = alpha + ch;</span> | alpha = alpha + ch; </span><br /> <br /><span style="font-family: 'courier new', courier;">for j in range(10): | for(j=0;j<10;j++)</span><br /><span style="font-family: 'courier new', courier;"> do this | { do this; } </span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">if(score>10): | if(score>10) </span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;"> do this | { do this; }</span></p>
<p><span style="font-family: 'courier new', courier;">else: | else </span><br /><span style="font-family: 'courier new', courier;"> do that | {do that }</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">print ("K2=", display) | postMessage("K2=" + display);</span></p>
<p><span style="font-family: 'courier new', courier;">InFile = open("Tetras.bin","rb") | importScripts('Tettable.js'); </span><br /><span style="font-family: 'courier new', courier;">temp_string = InFile.read()</span><br /><span style="font-family: 'courier new', courier;">InFile.close()</span></p>
<p> </p></div><div class="feed-description"><p><span style="font-family: verdana, geneva; font-size: small;">Javascript is a free programming language that already exists in your browser. You can use it right away! For solving cryptograms it is considerably faster than Python, some 20 times in my experience. On the downside it is a bit more complicated language to program.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Javascript runs inside your browser. The program code must be written in a web page, and then when the browser loads the page it sees the program lines and executes them. So we have two parts to the program: the webpage itself which is programmed in HTML and then the javascript code within the page.</span></p>
<h3><span style="font-family: verdana, geneva; font-size: small;">The HTML program.</span></h3>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">Let’s look at a simple example of the HTML program that makes the webpage. We want a green page that reads “Hello World” when we load it. First of all, type the code below into a Text Editor (I use TextWrangler):</span></p>
<p><span style="font-family: 'courier new', courier;"><html></span><br /><span style="font-family: 'courier new', courier;"><head></span><br /><span style="font-family: 'courier new', courier;"><script type="text/javascript"> </span><br /><span style="font-family: 'courier new', courier;"></script></span><br /><span style="font-family: 'courier new', courier;"></head></span></p>
<p><span style="font-family: 'courier new', courier;"><body bgcolor="green" ></span><br /><span style="font-family: 'courier new', courier;"><FONT FACE= "Verdana"></span><br /><span style="font-family: 'courier new', courier;"><h1>Hello World!</h1> </span><br /><span style="font-family: 'courier new', courier;"></body></span><br /><span style="font-family: 'courier new', courier;"></html></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Now </span><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">save it as Test.html and double-click it. A web page will open in your browser like this:</span></p>
<p style="text-align: center;"><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"><img src="images/Screen Shot 2013-02-07 at 15.53.08.png" border="0" alt="" /></span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"> </span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">For cryptogram solving the HTML program needs to ask for the ciphertext and display the solved plaintext and the key. Here is the HTML program:</span><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;"> </span></p>
<p><span style="font-family: 'courier new', courier;"><html></span><br /><span style="font-family: 'courier new', courier;"><head></span><br /><span style="font-family: 'courier new', courier;"><script type="text/javascript"> </span><br /><span style="font-family: 'courier new', courier;"></script></span><br /><span style="font-family: 'courier new', courier;"></head></span><br /><span style="font-family: 'courier new', courier;"><body bgcolor="green" ></span><br /><span style="font-family: 'courier new', courier;"><h3>Cryptogram Solver</h3> (paste ciphertext into Input Area. Press button to solve and display plaintext & key in Output Area)<br><br></span><br /><span style="font-family: 'courier new', courier;">Input Area:<br></span><br /><span style="font-family: 'courier new', courier;"><textarea id="input_area" cols=80 rows = 5></span><br /><span style="font-family: 'courier new', courier;"></textarea><br></span><br /><span style="font-family: 'courier new', courier;">Output Area:<br></span><br /><span style="font-family: 'courier new', courier;"><textarea id="output_area" cols=80 rows = 8></span><br /><span style="font-family: 'courier new', courier;"></textarea><br></span><br /><span style="font-family: 'courier new', courier;">Button:<br></span><br /><span style="font-family: 'courier new', courier;"><input type="button" value="Solve" onclick=do_solve();></span><br /><span style="font-family: 'courier new', courier;"></body></span><br /><span style="font-family: 'courier new', courier;"></html></span></p>
<p> </p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">Save this as Test1, double-click it to get:</span></p>
<p style="text-align: center;"><img src="images/Screen Shot 2013-02-08 at 08.15.55.png" border="0" alt="" /></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">You will see there is an Input area for the ciphertext and an Output area where the solution will be displayed. Also a button to click to get things going.</span></p>
<h3><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript program. </span></h3>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript code which solves the cryptogram can be included in the HTML program but I prefer to make a separate program called a Web Worker. The HTML program contains enough javascript to send the ciphertext to the Web Worker and tell it to get started. The Worker carries out its programmed duties, reporting back results to the HTML program which then displays on your browser in the Output area.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">The javascript code that communicates with the Worker is put in the 'head' of the HTML program between the <script> and </script>. Here is the code:</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">var hclimber;</span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">function do_solve()</span></p>
<p><span style="font-family: 'courier new', courier;"> { </span><br /><span style="font-family: 'courier new', courier;"> var str;</span><br /><span style="font-family: 'courier new', courier;"> hclimber = new Worker('AP_worker.js');</span><br /><span style="font-family: 'courier new', courier;"> str = document.getElementById('input_area').value; </span><br /><span style="font-family: 'courier new', courier;"> hclimber.postMessage(str); </span><br /><span style="font-family: 'courier new', courier;"> hclimber.onmessage = function (event) </span><br /><span style="font-family: 'courier new', courier;"> {</span><br /><span style="font-family: 'courier new', courier;"> str = event.data;</span><br /><span style="font-family: 'courier new', courier;"> document.getElementById('output_area').value = str; </span><br /><span style="font-family: 'courier new', courier;"> }</span><br /><span style="font-family: 'courier new', courier;"> }</span></p>
<p><span style="font-family: verdana, geneva; font-size: small; line-height: 1.3em;">On clicking the button, the function do_solve() is called. This makes the Worker 'hclimber', sends it the ciphertext and displays any data that comes back in the Output area.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">The main javascript program is in the <a href="programs/AP_worker.js">Worker -- click here to view it.</a> It solves monoalphabetic substitution ciphers. Because this is not a tutorial I am not going to go through it in detail. If you have read my Python tutorial you will have been through <a href="index.php/python/47-python-hillclimber">what this program is doing</a>. </span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">You can <a href="programs/Ari_Pat_WW.html">run the program here</a>. Paste the ciphertext below into the Input Area, press the button and the prtogram will put the plaintext in the Output area:</span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">OJNPZ FDWXJ UHDNI JGKFD QDPDQ JODHI XIFJK DSBZW NBQZH HBIZD VIDFF DHQIJ HSBQB JHHJF JHMDN NDLRB NDSUB ODEHJ UPDTD NXQAB HM.</span></span></p>
<p><span style="font-family: verdana, geneva; font-size: small;"><span style="line-height: 16.890625px;">Many of the commands are different in the two languages and to help those who are interested I have summarised these below. </span></span></p>
<p><span style="font-family: 'courier new', courier;"> <span style="text-decoration: underline;"><strong>python</strong> </span> | <span style="text-decoration: underline;"><strong>javascript</strong></span></span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">x=randrange(26) | x=Math.floor(Math.random()*26);</span></p>
<p><span style="font-family: 'courier new', courier;"> alpha = "OJNPZ" | var alpha = "OJNPZ";</span><br /><span style="font-family: 'courier new', courier;"> value = [0,1,2,3,4] | var value = {0,1,2,3,4 }; </span><br /><span style="font-family: 'courier new', courier;"> len = len(alpha) | len = alpha.length;</span><br /><span style="font-family: 'courier new', courier;"> t=0 | var t=0;</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">index = [0]*26 | var index=new Array(26);</span></p>
<p><span style="font-family: 'courier new', courier;"> cipher=['A']*200 | var cipher=new Array(200);</span><br /> <br /><span style="font-family: 'courier new', courier;"> x = ord(alpha[j])-65 | x = alpha.charCodeAt(j)-65; </span><br /><span style="font-family: 'courier new', courier;"> pt =chr(x+97) | pt = String.fromCharCode(x+97);</span><br /> <br /><span style="font-family: 'courier new', courier;"> ch = alpha[j] | ch = alpha.charAt(x);</span><br /><span style="font-family: 'courier new', courier;"><span>alpha = alpha + ch;</span> | alpha = alpha + ch; </span><br /> <br /><span style="font-family: 'courier new', courier;">for j in range(10): | for(j=0;j<10;j++)</span><br /><span style="font-family: 'courier new', courier;"> do this | { do this; } </span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;">if(score>10): | if(score>10) </span></p>
<p><span style="font-family: 'courier new', courier; line-height: 1.3em;"> do this | { do this; }</span></p>
<p><span style="font-family: 'courier new', courier;">else: | else </span><br /><span style="font-family: 'courier new', courier;"> do that | {do that }</span></p>
<p> <span style="font-family: 'courier new', courier; line-height: 1.3em;">print ("K2=", display) | postMessage("K2=" + display);</span></p>
<p><span style="font-family: 'courier new', courier;">InFile = open("Tetras.bin","rb") | importScripts('Tettable.js'); </span><br /><span style="font-family: 'courier new', courier;">temp_string = InFile.read()</span><br /><span style="font-family: 'courier new', courier;">InFile.close()</span></p>
<p> </p></div>Solving programs2012-07-23T10:00:52+00:002012-07-23T10:00:52+00:00http://www.cryptoden.com/index.php/solvers/programsSuper Usermikejcowan@me.com<div class="feed-description"><p><span style="font-family: verdana, geneva; font-size: small;">Click <a href="equations/WW.html">here</a> to run a solver for Cryptarithm Equations.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Here is quite a difficult, duodecimal equation to solve (thanks to the <a href="http://cryptogram.org/">ACA</a>). The key is comprised of two words that run backwards from B to zero:</span></p>
<p><strong><span style="font-family: 'courier new', courier;">TIGER + SCOUT = IYMIDO. TRUE + GRIT = CYSU</span></strong></p>
<p><strong><span style="font-family: 'courier new', courier;"> </span></strong></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/HeadlineMatrixSymmetry.html">Headlines Matrix & Chain solver</a> -- paste in solved headlines</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/get%20mixed%20alpha.html">Headlines Mixed Alphabet Solver</a> -- paste in chained alphabet</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/NSub_WW.html">Nihilist Substitution Solver</a> -- paste in ciphertext</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/Ari_Pat_WW.html">Monoalphabetic substitution solver</a> -- paste in ciphertext</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/K3%20Key%20Find.html">K3 Keyword Finder </a> -- paste in partial mixed alphabet</span></p>
<p><strong><span style="font-family: 'courier new', courier;"> </span></strong></p></div><div class="feed-description"><p><span style="font-family: verdana, geneva; font-size: small;">Click <a href="equations/WW.html">here</a> to run a solver for Cryptarithm Equations.</span></p>
<p><span style="font-family: verdana, geneva; font-size: small;">Here is quite a difficult, duodecimal equation to solve (thanks to the <a href="http://cryptogram.org/">ACA</a>). The key is comprised of two words that run backwards from B to zero:</span></p>
<p><strong><span style="font-family: 'courier new', courier;">TIGER + SCOUT = IYMIDO. TRUE + GRIT = CYSU</span></strong></p>
<p><strong><span style="font-family: 'courier new', courier;"> </span></strong></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/HeadlineMatrixSymmetry.html">Headlines Matrix & Chain solver</a> -- paste in solved headlines</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/get%20mixed%20alpha.html">Headlines Mixed Alphabet Solver</a> -- paste in chained alphabet</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/NSub_WW.html">Nihilist Substitution Solver</a> -- paste in ciphertext</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/Ari_Pat_WW.html">Monoalphabetic substitution solver</a> -- paste in ciphertext</span></p>
<p><span style="font-family: verdana, geneva;"><a href="programs/K3%20Key%20Find.html">K3 Keyword Finder </a> -- paste in partial mixed alphabet</span></p>
<p><strong><span style="font-family: 'courier new', courier;"> </span></strong></p></div>