Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
More Jobs
Recent
Cheap ruby block templating
Bindings on caller
Initial script execution very slow and skewing results
suppress ERB newlines
Keeping the database clean
Arrays, loops, strings...
Similar virtual attributes and their getters/setter
Check type is XML Serializable
Serena Collage slideshow
Shortest regular expression for matching a subdomain.
Popular
Caching Methods
How to find max, min of three numbers?
Similar virtual attributes and their getters/setter
Shortest regular expression for matching a subdomain.
Arrays, loops, strings...
Cheap ruby block templating
Check type is XML Serializable
Bindings on caller
Apache log file sorting
Tab-Switching in jQuery
Pastable version of
Circular Cipher
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31</pre> <pre class="sunburst"><span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>Input string</span> msg <span style="color:#E28964;">=</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span>I wonder if this code can be better.<span style="color:#65B042;">"</span></span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>Randomly-generated key</span> key <span style="color:#E28964;">=</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span>s7eOhg2fqgPRWXtp303B67551G5zpEyHe78q5NR5eWKP9eq9fk54D23<span style="color:#65B042;">"</span></span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>This is the only way I can figure out how to store the result of the .each loops</span> ciphered <span style="color:#E28964;">=</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span><span style="color:#65B042;">"</span></span> deciphered <span style="color:#E28964;">=</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span><span style="color:#65B042;">"</span></span> beg <span style="color:#E28964;">=</span> <span style="color:#3387CC;">32</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>Equivalent to ASCII's {space} in decimal</span> fin <span style="color:#E28964;">=</span> <span style="color:#3387CC;">91</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>Equivalent to the distance between ASCII {space} and ASCII {z}</span> (<span style="color:#3387CC;">0</span>..msg.<span style="color:#89BDFF;">length</span><span style="color:#E28964;">-</span><span style="color:#3387CC;">1</span>).<span style="color:#89BDFF;">each</span> <span style="color:#E28964;">do </span>|<span style="color:#3E87E3;">i</span>| foo <span style="color:#E28964;">=</span> (msg[i] <span style="color:#E28964;">-</span> beg) <span style="color:#E28964;">+</span> (key[i] <span style="color:#E28964;">-</span> beg) foo <span style="color:#E28964;">%=</span> fin <span style="color:#E28964;">if</span> foo <span style="color:#E28964;">></span> fin foo <span style="color:#E28964;">+=</span> beg ciphered <span style="color:#E28964;"><<</span> foo <span style="color:#E28964;">end</span> (<span style="color:#3387CC;">0</span>..msg.<span style="color:#89BDFF;">length</span><span style="color:#E28964;">-</span><span style="color:#3387CC;">1</span>).<span style="color:#89BDFF;">each</span> <span style="color:#E28964;">do </span>|<span style="color:#3E87E3;">i</span>| foo <span style="color:#E28964;">=</span> (ciphered[i] <span style="color:#E28964;">-</span> beg) <span style="color:#E28964;">-</span> (key[i] <span style="color:#E28964;">-</span> beg) foo <span style="color:#E28964;">+=</span> fin <span style="color:#E28964;">if</span> foo <span style="color:#E28964;"><</span> <span style="color:#3387CC;">0</span> foo <span style="color:#E28964;">+=</span> beg deciphered <span style="color:#E28964;"><<</span> foo <span style="color:#E28964;">end</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">#</span>msg should now be the same as deciphered</span> puts msg puts ciphered puts deciphered </pre> </div> </div> <a href="http://refactormycode.com/codes/138-circular-cipher" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://refactormycode.com/images/small_logo.gif" style="border:0" /></a>