add hack-a-round for language specified markdown code blocks
When language is specified in a markdown code block such as:
````
```c
printf("Hello, world!\n");
```
````
is used, the resulting HTML as produced by `pandoc(1)` combined
with our revised `ioccc.css` is not intent the code block well.
A temporary "_hack-a-round_" is to turn the "markdown code language
specifier" into an HTML comment. For example:
````
```<!---c-->
printf("Hello, world!\n");
```
````
This commits turns off existing markdown code language specifiers
for now, while preserving our ability to restore them in the future
when a better "_hack-a-round_" to the "markdown code language
specifier" problem is found.
The HTML impact if this "_hack-a-round_" is to produce HTML that
looks like this:
```
<pre class="<!---c-->"><code> .. </code></pre>
```
We might be able to create a complex set of classes for each markdown
code language (there won't be very many) in `ioccc.css`, or we might
find a more general CSS (or maybe `pandoc(1)`?) solution.
For now, this hack-a-round will have to do.
This commit is contained in:
1 parent
3919df50fb
commit
b66c79254a
700 files changed
+7052
-7056
No files matched your search
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,14 +18,14 @@ For more detailed information see [2020 burton bugs](../../bugs.html#2020_burton
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog arg ...
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ result?
|
||||
|
||||
This code may be tested by:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make test
|
||||
```
|
||||
|
||||
@@ -107,19 +107,19 @@ Compiles cleanly under `clang -Wall -Weverything -pedantic`, but you need to add
|
||||
|
||||
On a little-endian machine:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
clang -include stdio.h -include stdlib.h -Wall -Weverything -pedantic -DB=6945503773712347754LL -DI=5859838231191962459LL -DT=0 -DS=7 -o prog prog.c
|
||||
```
|
||||
|
||||
On a big-endian machine:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
clang -include stdio.h -include stdlib.h -Wall -Weverything -pedantic -DB=7091606191627001958LL -DI=6006468689561538903LL -DT=1 -DS=0 -o prog_be prog.c
|
||||
```
|
||||
|
||||
You might be interested to compile it both ways on the same host, and try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog 1; ./prog_be 1
|
||||
```
|
||||
|
||||
|
||||
@@ -141,15 +141,15 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_burton">2020 burton bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> arg ...</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog arg ...</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>By default, the program works for Little Endian machines. This alternate build
|
||||
is for Big Endian machines (that works whether you have LE or BE).</p>
|
||||
@@ -170,7 +170,7 @@ value that results when the two magic constants are <code>XOR</code>ed.</p>
|
||||
choosing new constants, but using the same computation generate a reversed
|
||||
result?</p>
|
||||
<p>This code may be tested by:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> test</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make test</code></pre>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<p>Invoke this with a single non-negative integer less than 256, and a useful
|
||||
transformation occurs.</p>
|
||||
@@ -189,11 +189,11 @@ display strange results with more than one argument.</p>
|
||||
<p>Compiles cleanly under <code>clang -Wall -Weverything -pedantic</code>, but you need to add
|
||||
<code>--include stdio.h --include stdlib.h</code> for the <code>printf(3)</code> and <code>atoi(3)</code>.</p>
|
||||
<p>On a little-endian machine:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> <span class="at">-include</span> stdio.h <span class="at">-include</span> stdlib.h <span class="at">-Wall</span> <span class="at">-Weverything</span> <span class="at">-pedantic</span> <span class="at">-DB</span><span class="op">=</span>6945503773712347754LL <span class="at">-DI</span><span class="op">=</span>5859838231191962459LL <span class="at">-DT</span><span class="op">=</span>0 <span class="at">-DS</span><span class="op">=</span>7 <span class="at">-o</span> prog prog.c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> clang -include stdio.h -include stdlib.h -Wall -Weverything -pedantic -DB=6945503773712347754LL -DI=5859838231191962459LL -DT=0 -DS=7 -o prog prog.c</code></pre>
|
||||
<p>On a big-endian machine:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> <span class="at">-include</span> stdio.h <span class="at">-include</span> stdlib.h <span class="at">-Wall</span> <span class="at">-Weverything</span> <span class="at">-pedantic</span> <span class="at">-DB</span><span class="op">=</span>7091606191627001958LL <span class="at">-DI</span><span class="op">=</span>6006468689561538903LL <span class="at">-DT</span><span class="op">=</span>1 <span class="at">-DS</span><span class="op">=</span>0 <span class="at">-o</span> prog_be prog.c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> clang -include stdio.h -include stdlib.h -Wall -Weverything -pedantic -DB=7091606191627001958LL -DI=6006468689561538903LL -DT=1 -DS=0 -o prog_be prog.c</code></pre>
|
||||
<p>You might be interested to compile it both ways on the same host, and try:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> 1<span class="kw">;</span> <span class="ex">./prog_be</span> 1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog 1; ./prog_be 1</code></pre>
|
||||
<!--
|
||||
|
||||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||||
|
||||
+23
-23
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,20 +18,20 @@ For more detailed information see [2020 carlini bugs](../../bugs.html#2020_carli
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
Or if you actually want to play:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# Play with a friend, real or imagined, P1 and P2, squares are numbered 1..9
|
||||
./prog
|
||||
```
|
||||
@@ -51,7 +51,7 @@ HOW ABOUT A NICE GAME OF <strike>CHESS</strike>TIC-TAC-TOE?
|
||||
|
||||
### USAGE
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
cc -o prog prog.c
|
||||
./prog
|
||||
```
|
||||
@@ -92,7 +92,7 @@ compilers unhappy, and others slow. (For example, passing GCC the flags `-Wall
|
||||
|
||||
Under some terminals the program may exit early. The following should always work:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
echo "1 2 3 4 5 6 7" | ./prog
|
||||
```
|
||||
|
||||
@@ -100,7 +100,7 @@ Under some terminals the program may exit early. The following should always wor
|
||||
|
||||
The entirety of the program consists of a single iterated call to `printf(3)`.
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
int main() {
|
||||
while(*d) printf(fmt, arg);
|
||||
}
|
||||
@@ -144,13 +144,13 @@ Format specifiers can take extra "arguments".
|
||||
|
||||
For example, the following expression
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
printf("%1$.*2$d%3$hhn", 5, 10, &x)
|
||||
```
|
||||
|
||||
will have the same effect as if we had written
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
x = 10;
|
||||
```
|
||||
|
||||
@@ -174,37 +174,37 @@ We can use format strings to compute the OR/NOT of arbitrary "bits".
|
||||
|
||||
We'll start with the simplest, OR:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
printf("%1$s%2$s%3$hhn", a, b, c)
|
||||
```
|
||||
|
||||
will compute
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*c = strlen(a) + strlen(b)
|
||||
```
|
||||
|
||||
but given that `strlen(x)` is `1` for a 1-bit and `0` for a 0-bit, we have
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*c = a | b
|
||||
```
|
||||
|
||||
Computing the NOT of a single value is also easy:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
printf("%1$255d%1$s%hhn", a, b)
|
||||
```
|
||||
|
||||
will compute
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*b = (strlen(a)+255)%256 = strlen(a)-1
|
||||
```
|
||||
|
||||
and again, because `strlen(x)` is either `1` or `0` we have
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*c = !b
|
||||
```
|
||||
|
||||
@@ -221,7 +221,7 @@ To detect who has won, we implement the following logic. Let `A`, `B`, and `C` b
|
||||
pointers to three squares in a row to test, and `D` be where to save if there is a
|
||||
win or not.
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
"%A$s%B$s%C$s%1$253d%11$hhn" // r11 = !(*A & *B & *C)
|
||||
ZERO
|
||||
"%11$s%1$255d%11hhn" // r11 = !r11
|
||||
@@ -235,7 +235,7 @@ possible three-in-a-row configurations, for both players.
|
||||
The ZERO macro ensures that the number of bytes written out is 0 mod 256 with
|
||||
the following expression
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
"%1$hhn%1$s" (repeated 256 times)
|
||||
```
|
||||
|
||||
@@ -254,13 +254,13 @@ bits to Xs and Os to print out. This is actually rather straightforward. Given
|
||||
in `1$` the pointer to player 1's square, and `2$` the pointer to player 2's, and
|
||||
in `3$` the pointer to the board string, we can compute
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
"%1$s" (repeated 47 times) "%2$s" (repeated 56 times) %1$32d%3$hhn"
|
||||
```
|
||||
|
||||
which will, in effect, compute
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*r3 = (*r1) * 47 + (*r2) * 56 + 32
|
||||
```
|
||||
|
||||
@@ -273,7 +273,7 @@ which will output `' '` if neither are true, `'X'` if `r1` is true, or `'O'` if
|
||||
In order to be able to finally display the board, while still only using one
|
||||
`printf(3)` statement, we finish the statement with
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
"\n\033[2J\n%26$s"
|
||||
```
|
||||
|
||||
@@ -299,7 +299,7 @@ won, or the game is over and it is a draw.
|
||||
This turns out not to be as hard as it might look. Using the same trick as
|
||||
before, we set byte four to be
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
*byte4 = is_win * 'W' + is_tie * 'T'
|
||||
```
|
||||
|
||||
@@ -313,7 +313,7 @@ ends. It should just exit.
|
||||
|
||||
One option would be to implement the logic as
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
printf()
|
||||
while (*ok) {
|
||||
scanf();
|
||||
@@ -324,7 +324,7 @@ One option would be to implement the logic as
|
||||
but this would DOUBLE the number of calls to `printf(3)` we require. So instead we
|
||||
implement it like this
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
while (*ok) {
|
||||
scanf();
|
||||
printf();
|
||||
|
||||
+38
-38
@@ -141,18 +141,18 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_carlini">2020 carlini bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<p>Or if you actually want to play:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Play with a friend, real or imagined, P1 and P2, squares are numbered 1..9</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # Play with a friend, real or imagined, P1 and P2, squares are numbered 1..9
|
||||
./prog</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>This program consists of a single <code>printf(3)</code> statement wrapped in a <code>while</code>
|
||||
loop. You would not think that this would amount to much, but you would be very,
|
||||
@@ -161,8 +161,8 @@ ASCII art of the program source.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<p>HOW ABOUT A NICE GAME OF <strike>CHESS</strike>TIC-TAC-TOE?</p>
|
||||
<h3 id="usage">USAGE</h3>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-o</span> prog prog.c</span>
|
||||
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> cc -o prog prog.c
|
||||
./prog</code></pre>
|
||||
<p>Alternates between P1 and P2. Enter a digit [1-9] to move:</p>
|
||||
<pre><code> 1 | 2 | 3
|
||||
---------
|
||||
@@ -187,12 +187,12 @@ patient.</p>
|
||||
<p>After macro expansion the format string is roughly 100K. This makes some
|
||||
compilers unhappy, and others slow. (For example, passing GCC the flags <code>-Wall -Wextra -pedantic</code> will result in a warning about oversized strings.)</p>
|
||||
<p>Under some terminals the program may exit early. The following should always work:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="st">"1 2 3 4 5 6 7"</span> <span class="kw">|</span> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> echo "1 2 3 4 5 6 7" | ./prog</code></pre>
|
||||
<h3 id="obfuscation">OBFUSCATION</h3>
|
||||
<p>The entirety of the program consists of a single iterated call to <code>printf(3)</code>.</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main<span class="op">()</span> <span class="op">{</span></span>
|
||||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span><span class="op">(*</span>d<span class="op">)</span> printf<span class="op">(</span>fmt<span class="op">,</span> arg<span class="op">);</span></span>
|
||||
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> int main() {
|
||||
while(*d) printf(fmt, arg);
|
||||
}</code></pre>
|
||||
<p>Here, <code>fmt</code> is a single string, and <code>arg</code> is a series of arguments to
|
||||
<code>printf(3)</code>.</p>
|
||||
<p>While its primary purpose is to serve as The One True Debugger, <code>printf(3)</code> also happens
|
||||
@@ -218,9 +218,9 @@ this one <code>printf(3)</code> call (and a call to <code>scanf(3)</code> to rea
|
||||
<li><p><code>"%3$.*4$d"</code>: print argument 3 to <code>printf(3)</code> with as many zeros as in argument 4.</p></li>
|
||||
</ul>
|
||||
<p>For example, the following expression</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> printf<span class="op">(</span><span class="st">"%1$.*2$d%3$hhn"</span><span class="op">,</span> <span class="dv">5</span><span class="op">,</span> <span class="dv">10</span><span class="op">,</span> <span class="op">&</span>x<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> printf("%1$.*2$d%3$hhn", 5, 10, &x)</code></pre>
|
||||
<p>will have the same effect as if we had written</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> x <span class="op">=</span> <span class="dv">10</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> x = 10;</code></pre>
|
||||
<p>because it will print out <code>0000000005</code> (5 padded to size 10) and then write the
|
||||
number of bytes written to <code>x</code>.</p>
|
||||
<h4 id="printf3-oriented-programming"><code>printf(3)</code> Oriented Programming</h4>
|
||||
@@ -233,17 +233,17 @@ array–one bit per pair of bytes:</p>
|
||||
</ul>
|
||||
<p>We can use format strings to compute the OR/NOT of arbitrary “bits”.</p>
|
||||
<p>We’ll start with the simplest, OR:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> printf<span class="op">(</span><span class="st">"%1$s%2$s%3$hhn"</span><span class="op">,</span> a<span class="op">,</span> b<span class="op">,</span> c<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> printf("%1$s%2$s%3$hhn", a, b, c)</code></pre>
|
||||
<p>will compute</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>c <span class="op">=</span> strlen<span class="op">(</span>a<span class="op">)</span> <span class="op">+</span> strlen<span class="op">(</span>b<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *c = strlen(a) + strlen(b)</code></pre>
|
||||
<p>but given that <code>strlen(x)</code> is <code>1</code> for a 1-bit and <code>0</code> for a 0-bit, we have</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>c <span class="op">=</span> a <span class="op">|</span> b</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *c = a | b</code></pre>
|
||||
<p>Computing the NOT of a single value is also easy:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> printf<span class="op">(</span><span class="st">"%1$255d%1$s</span><span class="sc">%hhn</span><span class="st">"</span><span class="op">,</span> a<span class="op">,</span> b<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> printf("%1$255d%1$s%hhn", a, b)</code></pre>
|
||||
<p>will compute</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>b <span class="op">=</span> <span class="op">(</span>strlen<span class="op">(</span>a<span class="op">)+</span><span class="dv">255</span><span class="op">)%</span><span class="dv">256</span> <span class="op">=</span> strlen<span class="op">(</span>a<span class="op">)-</span><span class="dv">1</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *b = (strlen(a)+255)%256 = strlen(a)-1</code></pre>
|
||||
<p>and again, because <code>strlen(x)</code> is either <code>1</code> or <code>0</code> we have</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>c <span class="op">=</span> <span class="op">!</span>b</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *c = !b</code></pre>
|
||||
<p>From here we can compute any binary circuit. Doing something efficient,
|
||||
though, still takes work.</p>
|
||||
<h4 id="tic-tac-toe">Tic-Tac-Toe</h4>
|
||||
@@ -252,16 +252,16 @@ with a turn counter that alternates between player 1 and player 2.</p>
|
||||
<p>To detect who has won, we implement the following logic. Let <code>A</code>, <code>B</code>, and <code>C</code> be
|
||||
pointers to three squares in a row to test, and <code>D</code> be where to save if there is a
|
||||
win or not.</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="st">"</span><span class="sc">%A</span><span class="st">$s%B$s%C$s%1$253d%11$hhn"</span> <span class="co">// r11 = !(*A & *B & *C)</span></span>
|
||||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> ZERO</span>
|
||||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"%11$s%1$255d</span><span class="sc">%11hhn</span><span class="st">"</span> <span class="co">// r11 = !r11</span></span>
|
||||
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> ZERO</span>
|
||||
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"%11$s%D$s%D$hhn"</span> <span class="co">// *D = *D | r11</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> "%A$s%B$s%C$s%1$253d%11$hhn" // r11 = !(*A & *B & *C)
|
||||
ZERO
|
||||
"%11$s%1$255d%11hhn" // r11 = !r11
|
||||
ZERO
|
||||
"%11$s%D$s%D$hhn" // *D = *D | r11</code></pre>
|
||||
<p>That is, we set <code>*D</code> to <code>1</code> if there is a three-in-a-row. We repeat this for all
|
||||
possible three-in-a-row configurations, for both players.</p>
|
||||
<p>The ZERO macro ensures that the number of bytes written out is 0 mod 256 with
|
||||
the following expression</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="st">"%1$hhn%1$s"</span> <span class="op">(</span>repeated <span class="dv">256</span> times<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> "%1$hhn%1$s" (repeated 256 times)</code></pre>
|
||||
<p>where argument 1 is a pointer to a temporary variable followed by a NUL byte.</p>
|
||||
<p>This works because if the current count is 0 mod 256, then <code>"%1$hhn"</code> will write
|
||||
zero to argument 1 and then <code>"%1$s"</code> will never emit any text. If, on the other
|
||||
@@ -273,15 +273,15 @@ times we’re eventually going to reach 0 mod 256.</p>
|
||||
bits to Xs and Os to print out. This is actually rather straightforward. Given
|
||||
in <code>1$</code> the pointer to player 1’s square, and <code>2$</code> the pointer to player 2’s, and
|
||||
in <code>3$</code> the pointer to the board string, we can compute</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="st">"%1$s"</span> <span class="op">(</span>repeated <span class="dv">47</span> times<span class="op">)</span> <span class="st">"%2$s"</span> <span class="op">(</span>repeated <span class="dv">56</span> times<span class="op">)</span> <span class="op">%</span><span class="dv">1</span>$<span class="dv">32</span><span class="er">d</span><span class="op">%</span><span class="dv">3</span>$hhn<span class="st">"</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> "%1$s" (repeated 47 times) "%2$s" (repeated 56 times) %1$32d%3$hhn"</code></pre>
|
||||
<p>which will, in effect, compute</p>
|
||||
<div class="sourceCode" id="cb21"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>r3 <span class="op">=</span> <span class="op">(*</span>r1<span class="op">)</span> <span class="op">*</span> <span class="dv">47</span> <span class="op">+</span> <span class="op">(*</span>r2<span class="op">)</span> <span class="op">*</span> <span class="dv">56</span> <span class="op">+</span> <span class="dv">32</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *r3 = (*r1) * 47 + (*r2) * 56 + 32</code></pre>
|
||||
<p>which will output <code>' '</code> if neither are true, <code>'X'</code> if <code>r1</code> is true, or <code>'O'</code> if
|
||||
<code>r2</code> is true.</p>
|
||||
<h4 id="further-obfuscations">Further Obfuscations</h4>
|
||||
<p>In order to be able to finally display the board, while still only using one
|
||||
<code>printf(3)</code> statement, we finish the statement with</p>
|
||||
<div class="sourceCode" id="cb22"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="st">"</span><span class="sc">\n\033</span><span class="st">[2J</span><span class="sc">\n</span><span class="st">%26$s"</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> "\n\033[2J\n%26$s"</code></pre>
|
||||
<p>which is the escape sequence to clear the screen, and then prints argument 26.
|
||||
Argument 26 is a pointer to a <code>char*</code> in memory, that initially is undefined,
|
||||
but within the <code>printf(3)</code> statement we will construct this string to look like a
|
||||
@@ -297,7 +297,7 @@ tic-tac-toe board.</p>
|
||||
won, or the game is over and it is a draw.</p>
|
||||
<p>This turns out not to be as hard as it might look. Using the same trick as
|
||||
before, we set byte four to be</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>byte4 <span class="op">=</span> is_win <span class="op">*</span> <span class="ch">'W'</span> <span class="op">+</span> is_tie <span class="op">*</span> <span class="ch">'T'</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> *byte4 = is_win * 'W' + is_tie * 'T'</code></pre>
|
||||
<p>The byte <code>'I'</code> and <code>'S'</code> can always be the same, and we do the same for <code>'E'</code>/<code>'N'</code>.</p>
|
||||
<p>We do this same on-the-fly creation of the <code>scanf(3)</code> format string, but for a
|
||||
different reason. We first want to run <code>printf(3)</code> to show the first board, and
|
||||
@@ -305,17 +305,17 @@ then alternate between runs to <code>scanf(3)</code> and <code>printf(3)</code>
|
||||
displaying moves. Importantly, we <em>do not</em> want a final <code>scanf(3)</code> when the game
|
||||
ends. It should just exit.</p>
|
||||
<p>One option would be to implement the logic as</p>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a> printf<span class="op">()</span></span>
|
||||
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span> <span class="op">(*</span>ok<span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> scanf<span class="op">();</span></span>
|
||||
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> printf<span class="op">();</span></span>
|
||||
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> printf()
|
||||
while (*ok) {
|
||||
scanf();
|
||||
printf();
|
||||
}</code></pre>
|
||||
<p>but this would DOUBLE the number of calls to <code>printf(3)</code> we require. So instead we
|
||||
implement it like this</p>
|
||||
<div class="sourceCode" id="cb26"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span> <span class="op">(*</span>ok<span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> scanf<span class="op">();</span></span>
|
||||
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> printf<span class="op">();</span></span>
|
||||
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> while (*ok) {
|
||||
scanf();
|
||||
printf();
|
||||
}</code></pre>
|
||||
<p>(In reality we actually pass <code>scanf(3)</code> as an argument to avoid the extra
|
||||
statement, but it has the same effect.)</p>
|
||||
<p>Notice there is now no initial <code>printf(3)</code>. In order make sure the program doesn’t
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -10,7 +10,7 @@ code](#alternate-code) below.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# IMPORTANT for macOS: run under Terminal.app
|
||||
|
||||
./prog
|
||||
@@ -19,7 +19,7 @@ code](#alternate-code) below.
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# IMPORTANT for macOS: run under Terminal.app
|
||||
|
||||
# Try resizing the terminal window before the first click.
|
||||
@@ -41,7 +41,7 @@ Author's remarks for more details.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
@@ -94,7 +94,7 @@ All you have to do is (0). You can test if you are lucky or not.
|
||||
|
||||
It uses ncurses:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
gcc -o prog prog.c -lncurses
|
||||
./prog
|
||||
```
|
||||
@@ -200,7 +200,7 @@ Analyze the code.
|
||||
|
||||
You can also play with a prepared map.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog ioccc.txt
|
||||
```
|
||||
|
||||
|
||||
+17
-17
@@ -141,29 +141,29 @@ Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>There is an alternate version provided by the author. See <a href="#alternate-code">Alternate
|
||||
code</a> below.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># IMPORTANT for macOS: run under Terminal.app</span></span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # IMPORTANT for macOS: run under Terminal.app
|
||||
|
||||
./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># IMPORTANT for macOS: run under Terminal.app</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># Try resizing the terminal window before the first click.</span></span>
|
||||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># Try resizing the terminal window after the first click.</span></span>
|
||||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> ioccc.txt</span>
|
||||
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> unwinnable.txt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # IMPORTANT for macOS: run under Terminal.app
|
||||
|
||||
# Try resizing the terminal window before the first click.
|
||||
|
||||
# Try resizing the terminal window after the first click.
|
||||
|
||||
./prog ioccc.txt
|
||||
|
||||
./prog unwinnable.txt</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>An alternate version of this entry, <a href="prog.alt.c">prog.alt.c</a>, is provided. This
|
||||
alternate code lacks the additional rule to flag all unprobed cells. See the
|
||||
Author’s remarks for more details.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
@@ -194,8 +194,8 @@ such a boring task!</p>
|
||||
All you have to do is (0). You can test if you are lucky or not.</p>
|
||||
<h3 id="how-to-use">How to use:</h3>
|
||||
<p>It uses ncurses:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="at">-o</span> prog prog.c <span class="at">-lncurses</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> gcc -o prog prog.c -lncurses
|
||||
./prog</code></pre>
|
||||
<p>You will see a terminal-wide field of a minesweeper. Probe a cell by mouse
|
||||
click.</p>
|
||||
<p>If a cell turns out to have a mine (or not), the program determines whether its
|
||||
@@ -255,7 +255,7 @@ are flagged.</p>
|
||||
Analyze the code.</p>
|
||||
<h3 id="one-more-thing">One more thing</h3>
|
||||
<p>You can also play with a prepared map.</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> ioccc.txt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog ioccc.txt</code></pre>
|
||||
<p>The format of the text is:</p>
|
||||
<pre><code> width height number-of-mines priorities-of-each-cell...</code></pre>
|
||||
<p>There are mines in a cell whose “priorities-of-each-cell” is less than
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
What happens if you do
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog prog.c
|
||||
```
|
||||
|
||||
@@ -41,7 +41,7 @@ render for a larger terminal window? How about adding more glyphs?
|
||||
|
||||
No! Try not. Do, or do not. There is no try.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
cc -std=c99 prog.c
|
||||
./a.out
|
||||
./a.out hello.txt
|
||||
|
||||
@@ -141,13 +141,13 @@ Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<p>What happens if you do</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> prog.c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog prog.c</code></pre>
|
||||
<p>?</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>Clever use of the C99 complex data type. The <a href="spoiler/">spoiler</a> directory
|
||||
@@ -157,11 +157,11 @@ shapes.</p>
|
||||
render for a larger terminal window? How about adding more glyphs?</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<p>No! Try not. Do, or do not. There is no try.</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-std</span><span class="op">=</span>c99 prog.c</span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./a.out</span></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./a.out</span> hello.txt</span>
|
||||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">./a.out</span> yoda.txt</span>
|
||||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./a.out</span> bear.txt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> cc -std=c99 prog.c
|
||||
./a.out
|
||||
./a.out hello.txt
|
||||
./a.out yoda.txt
|
||||
./a.out bear.txt</code></pre>
|
||||
<p>See spoiler.zip for the source code.
|
||||
<a href="https://en.wikipedia.org/wiki/List_of_the_most_common_passwords">The 16th most common password on the Internet in 2017 (according to Splash Data)</a> the password is.</p>
|
||||
<!--
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -10,14 +10,14 @@ code](#alternate-code) below.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./run_clock
|
||||
# And watch closely for 15-20 seconds
|
||||
```
|
||||
@@ -31,7 +31,7 @@ alternate code uses Unicode letters.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
@@ -43,7 +43,7 @@ Use `prog.alt` as you would `prog` above.
|
||||
|
||||
### Alternate try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./run_clock.alt
|
||||
# And watch closely for 15-20 seconds
|
||||
```
|
||||
@@ -63,7 +63,7 @@ time might depend on what time it is.
|
||||
|
||||
Prepare a mirror!
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make clock
|
||||
```
|
||||
|
||||
|
||||
@@ -141,24 +141,24 @@ Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>An alternate version of this program exists. See <a href="#alternate-code">Alternate
|
||||
code</a> below.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./run_clock</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># And watch closely for 15-20 seconds</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./run_clock
|
||||
# And watch closely for 15-20 seconds</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>An alternate version of this entry, <a href="prog.alt.c">prog.alt.c</a>, is provided. This
|
||||
alternate code uses Unicode letters.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
|
||||
<h3 id="alternate-try">Alternate try:</h3>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./run_clock.alt</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># And watch closely for 15-20 seconds</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./run_clock.alt
|
||||
# And watch closely for 15-20 seconds</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>You may be tempted to use a mirror. Resist the temptation! Try figuring out how
|
||||
the clock hands are drawn. Can you change the program to make it draw a
|
||||
@@ -167,7 +167,7 @@ familiar (non-mirrored) clock face? Can you add the second hand?</p>
|
||||
time might depend on what time it is.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<p>Prepare a mirror!</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clock</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make clock</code></pre>
|
||||
<p>Note: You need to recompile it each run.</p>
|
||||
<!--
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ matters; I only have Intel CPUs and arm64 (MacBook Pro M1).</p>
|
||||
<p>I imagine that it works for 32-bit systems but I do not know for sure.</p>
|
||||
<h1 id="portability-macos">Portability: macOS</h1>
|
||||
<p>You should be able to get the compiler with:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo xcode-select --install</code></pre>
|
||||
<p>You don’t need Xcode itself and it appears that the command line tools (as above
|
||||
should install) already has ncurses so there shouldn’t be anything else that
|
||||
needs to be done. But I’m not actually sure of this - I’m seeing conflicting
|
||||
@@ -159,20 +159,20 @@ so that you don’t need sudo because … Well never mind.</p>
|
||||
you want to use the Makefile) to compile and link this entry. With Fedora more
|
||||
recent versions there’s the <code>dnf</code> package manager but I cannot help with any of
|
||||
the GUI installers since I don’t use them. Something like:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> dnf install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># dnf install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<h1 id="portability-centos">Portability: CentOS</h1>
|
||||
<p>Just like Fedora you will need <code>gcc</code>, <code>ncurses</code>, <code>ncurses-devel</code> (and if you
|
||||
want to use the Makefile <code>make</code>). CentOS uses <code>yum</code> and CentOS 8 uses <code>dnf</code>.
|
||||
So:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> yum install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo yum install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># yum install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # yum install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> dnf install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># dnf install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>You can also use clang to compile (which is what gcc actually is under macOS).</p>
|
||||
<h1 id="compilation-notes">Compilation notes</h1>
|
||||
<p>As long as you have the dependencies above the only thing that comes to mind is
|
||||
|
||||
@@ -33,7 +33,7 @@ I imagine that it works for 32-bit systems but I do not know for sure.
|
||||
|
||||
You should be able to get the compiler with:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo xcode-select --install
|
||||
```
|
||||
|
||||
@@ -53,13 +53,13 @@ you want to use the Makefile) to compile and link this entry. With Fedora more
|
||||
recent versions there's the `dnf` package manager but I cannot help with any of
|
||||
the GUI installers since I don't use them. Something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
@@ -69,25 +69,25 @@ Just like Fedora you will need `gcc`, `ncurses`, `ncurses-devel` (and if you
|
||||
want to use the Makefile `make`). CentOS uses `yum` and CentOS 8 uses `dnf`.
|
||||
So:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo yum install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# yum install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
|
||||
+33
-33
@@ -192,19 +192,19 @@ defaults if you don’t want to change the colour.</p>
|
||||
initialise a pair (make it 5 so as to not interfere with the script
|
||||
customisability) and then you use the bkgd() function with the colour pair.
|
||||
Something like this:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span><span class="dv">5</span><span class="op">,</span> COLOR_BLACK<span class="op">,</span> COLOR_WHITE<span class="op">);</span></span>
|
||||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> bkgd<span class="op">(</span>COLOR_PAIR<span class="op">(</span><span class="dv">5</span><span class="op">));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> init_pair(5, COLOR_BLACK, COLOR_WHITE);
|
||||
bkgd(COLOR_PAIR(5));</code></pre>
|
||||
<p>I played with this after winning and I came across some problems with colours
|
||||
but that changes the background of the program anyway.</p>
|
||||
<p>The standard colour identifiers are:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> COLOR_BLACK</span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> COLOR_RED</span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> COLOR_GREEN</span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> COLOR_YELLOW</span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> COLOR_BLUE</span>
|
||||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> COLOR_MAGENTA</span>
|
||||
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> COLOR_CYAN</span>
|
||||
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> COLOR_WHITE</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> COLOR_BLACK
|
||||
COLOR_RED
|
||||
COLOR_GREEN
|
||||
COLOR_YELLOW
|
||||
COLOR_BLUE
|
||||
COLOR_MAGENTA
|
||||
COLOR_CYAN
|
||||
COLOR_WHITE</code></pre>
|
||||
<p>See Linux Journal for more information article
|
||||
<a href="https://www.linuxjournal.com/content/programming-color-ncurses" class="uri">https://www.linuxjournal.com/content/programming-color-ncurses</a> for more
|
||||
details.</p>
|
||||
@@ -220,16 +220,16 @@ source code (<strong>include the single quotes!</strong>) respectively:</p>
|
||||
<p>Let’s say you don’t want to use arrow keys or you don’t have arrow keys. Instead
|
||||
you might want the keys <code>l</code>, <code>r</code>, <code>u</code> and <code>d</code> for the directions. Find the case
|
||||
statements:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_LEFT<span class="op">:</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_RIGHT<span class="op">:</span></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_UP<span class="op">:</span></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_DOWN<span class="op">:</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> case KEY_LEFT:
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
case KEY_DOWN:</code></pre>
|
||||
<p>Replace <code>KEY_LEFT</code> with:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ch">'l'</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> 'l'</code></pre>
|
||||
<p>and do the same thing for the other directions too. If you want more than one
|
||||
key e.g. the arrow keys and the letters just add another case statement e.g. for
|
||||
left it might be:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_LEFT<span class="op">:</span> <span class="cf">case</span> <span class="ch">'l'</span><span class="op">:</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> case KEY_LEFT: case 'l':</code></pre>
|
||||
<p>Yes the single quotes matter. You can do similar for the other input keys.
|
||||
Please note that modifier keys like ctrl aren’t detectable or at least I’m
|
||||
unaware of how to do so.</p>
|
||||
@@ -245,9 +245,9 @@ end of the game; I leave that as an exercise to the reader to implement two
|
||||
different sets. Please also be aware that if you don’t want any information you
|
||||
must set it to the below at the very least; defining it without a value is not
|
||||
enough (it amounts to the parameters to a printf call):</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J </span><span class="st">" "</span><span class="pp"> </span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J " " );</code></pre>
|
||||
<p>If you don’t care about brief displays of ‘o’ at 0,0 you can just have:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J </span><span class="st">""</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J "");</code></pre>
|
||||
<p>That’s the bare minimum. Notice also that it’s been a long while since I’ve
|
||||
tested this part but I think this is right.</p>
|
||||
<p>Anyway as I said the score line has basic statistics that’s relatively easy to
|
||||
@@ -262,7 +262,7 @@ bug. This however was something I didn’t quite like: I like having the
|
||||
coordinates of where the snake is plus the other things that are there (a number
|
||||
of which were added over time). Obviously this would take many bug sized bytes
|
||||
(bites) even once let alone twice! Thus I made it into a define:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J Z</span><span class="op">(</span><span class="pp">X</span><span class="op">:%</span><span class="pp">d</span><span class="op">/%</span><span class="pp">d Y</span><span class="op">:%</span><span class="pp">d</span><span class="op">/%</span><span class="pp">d S</span><span class="op">:%</span><span class="pp">zu</span><span class="op">/%</span><span class="pp">zu B</span><span class="op">:%</span><span class="pp">zu\n</span><span class="op">),</span><span class="pp"> Y</span><span class="op">,</span><span class="pp"> y</span><span class="op">[-</span><span class="dv">2</span><span class="op">],</span><span class="pp"> X</span><span class="op">,*</span><span class="pp">y</span><span class="op">,</span><span class="pp">A</span><span class="op">,</span><span class="pp">g</span><span class="op">,</span><span class="pp"> c</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J Z(X:%d/%d Y:%d/%d S:%zu/%zu B:%zu\n), Y, y[-2], X,*y,A,g, c);</code></pre>
|
||||
<p>With the table below you can show a variety of other variables/statistics.</p>
|
||||
<p>There’s another reason for changing this line though: depending on the terminal
|
||||
width the line could cover the top wall; this can even happen only part of the
|
||||
@@ -280,7 +280,7 @@ so if this line wasn’t there it would require changes to make it work right.</
|
||||
<p>For an example this would only include the size of the snake and the number of
|
||||
bugs eaten (I think I have this correct; I’ve made many changes to the point of
|
||||
not wanting to mess with anything that’s unnecessary):</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J Z</span><span class="op">(</span><span class="pp">SIZE</span><span class="op">:</span><span class="pp"> </span><span class="op">%</span><span class="pp">zu BUGS</span><span class="op">:</span><span class="pp"> </span><span class="op">%</span><span class="pp">zu\n</span><span class="op">),</span><span class="pp"> A</span><span class="op">,</span><span class="pp"> c</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J Z(SIZE: %zu BUGS: %zu\n), A, c);</code></pre>
|
||||
<p>More generally the following expressions and data types (with format specifiers)
|
||||
come to mind as information that might be of interest.</p>
|
||||
<pre><code> DESCRIPTION EXPRESSION TYPE FORMAT SPECIFIER
|
||||
@@ -307,10 +307,10 @@ come to mind as information that might be of interest.</p>
|
||||
bug)</code></pre>
|
||||
<h2 id="make-it-so-the-snake-starts-at-a-random-location">Make it so the snake starts at a random location</h2>
|
||||
<p>Quite simply change:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> H <span class="op">/</span> <span class="dv">2</span><span class="op">;</span> Y <span class="op">=</span> <span class="op">*</span>x <span class="op">/</span> <span class="dv">2</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X = H / 2; Y = *x / 2;</code></pre>
|
||||
<p>To be something like:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> R<span class="op">(</span><span class="dv">1</span><span class="op">,</span>H<span class="op">-</span><span class="dv">1</span><span class="op">);</span></span>
|
||||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> Y <span class="op">=</span> R<span class="op">(</span><span class="dv">2</span><span class="op">,*</span>x<span class="op">-</span><span class="dv">1</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X = R(1,H-1);
|
||||
Y = R(2,*x-1);</code></pre>
|
||||
<p>Or whatever you might want it to be… (question to answer: will this work at
|
||||
all? You decide!)</p>
|
||||
<h1 id="additions">Additions (+)</h1>
|
||||
@@ -407,22 +407,22 @@ their ruddy phone instead of where they’re walking (even when crossing a busy
|
||||
street!).</p>
|
||||
<p>If you look at the walls code you will see a ternary operator for both <code>X</code> and <code>Y</code>
|
||||
coordinates. This of course is very different now but the idea remains the same:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>p <span class="op">&&</span> <span class="op">!(*</span>O<span class="op">>=</span>O<span class="op">[</span><span class="dv">1</span><span class="op">]||</span>H<span class="op">>=</span>M<span class="op">(</span><span class="dv">1</span><span class="op">)))</span></span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>X<span class="op"><</span><span class="dv">1</span><span class="op">||</span>X<span class="op">>=</span>H<span class="op">)</span></span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> X<span class="op"><</span><span class="dv">1</span><span class="op">?</span>H<span class="op">-</span><span class="dv">1</span><span class="op">:</span><span class="dv">1</span><span class="op">;</span></span>
|
||||
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>Y<span class="op"><</span><span class="dv">2</span><span class="op">||</span>Y<span class="op">>=*</span>O<span class="op">)</span></span>
|
||||
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> Y <span class="op">=</span> Y<span class="op"><</span><span class="dv">2</span><span class="op">?*</span>O<span class="op">-</span><span class="dv">1</span><span class="op">:</span><span class="dv">2</span><span class="op">;</span></span>
|
||||
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (p && !(*O>=O[1]||H>=M(1)))
|
||||
{
|
||||
if (X<1||X>=H)
|
||||
X = X<1?H-1:1;
|
||||
if (Y<2||Y>=*O)
|
||||
Y = Y<2?*O-1:2;
|
||||
}</code></pre>
|
||||
<p>You can ignore the first if if you like; I’m not going to explain that part. The
|
||||
inner if statements however are testing if the new snake coordinates are beyond
|
||||
the walls (off screen). Depending on where the snake is it will set the
|
||||
coordinates to the correct new location.</p>
|
||||
<p>If however you wanted the walls to act as a barrier you could do something like
|
||||
this instead (omitting the inner if statements here):</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> X<span class="op">=</span>X<span class="op"><</span><span class="dv">1</span><span class="op">?</span><span class="dv">1</span><span class="op">:*</span>H<span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> Y<span class="op">=</span>Y<span class="op"><</span><span class="dv">2</span><span class="op">?</span><span class="dv">2</span><span class="op">:*</span>O<span class="op">-</span><span class="dv">1</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X=X<1?1:*H-1;
|
||||
|
||||
Y=Y<2?2:*O-1;</code></pre>
|
||||
<p>Again though that’s just the idea; the code is dramatically different. The above
|
||||
incidentally is not even complete.</p>
|
||||
<p>You could also have it so depending on the WALLS value have it go through
|
||||
|
||||
+13
-13
@@ -78,7 +78,7 @@ initialise a pair (make it 5 so as to not interfere with the script
|
||||
customisability) and then you use the bkgd() function with the colour pair.
|
||||
Something like this:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
init_pair(5, COLOR_BLACK, COLOR_WHITE);
|
||||
bkgd(COLOR_PAIR(5));
|
||||
```
|
||||
@@ -88,7 +88,7 @@ but that changes the background of the program anyway.
|
||||
|
||||
The standard colour identifiers are:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
COLOR_BLACK
|
||||
COLOR_RED
|
||||
COLOR_GREEN
|
||||
@@ -124,7 +124,7 @@ Let's say you don't want to use arrow keys or you don't have arrow keys. Instead
|
||||
you might want the keys `l`, `r`, `u` and `d` for the directions. Find the case
|
||||
statements:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
case KEY_LEFT:
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
@@ -133,7 +133,7 @@ statements:
|
||||
|
||||
Replace `KEY_LEFT` with:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
'l'
|
||||
```
|
||||
|
||||
@@ -141,7 +141,7 @@ and do the same thing for the other directions too. If you want more than one
|
||||
key e.g. the arrow keys and the letters just add another case statement e.g. for
|
||||
left it might be:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
case KEY_LEFT: case 'l':
|
||||
```
|
||||
|
||||
@@ -166,13 +166,13 @@ different sets. Please also be aware that if you don't want any information you
|
||||
must set it to the below at the very least; defining it without a value is not
|
||||
enough (it amounts to the parameters to a printf call):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J " " );
|
||||
```
|
||||
|
||||
If you don't care about brief displays of 'o' at 0,0 you can just have:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J "");
|
||||
```
|
||||
|
||||
@@ -194,7 +194,7 @@ coordinates of where the snake is plus the other things that are there (a number
|
||||
of which were added over time). Obviously this would take many bug sized bytes
|
||||
(bites) even once let alone twice! Thus I made it into a define:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J Z(X:%d/%d Y:%d/%d S:%zu/%zu B:%zu\n), Y, y[-2], X,*y,A,g, c);
|
||||
```
|
||||
|
||||
@@ -220,7 +220,7 @@ For an example this would only include the size of the snake and the number of
|
||||
bugs eaten (I think I have this correct; I've made many changes to the point of
|
||||
not wanting to mess with anything that's unnecessary):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J Z(SIZE: %zu BUGS: %zu\n), A, c);
|
||||
```
|
||||
|
||||
@@ -257,13 +257,13 @@ come to mind as information that might be of interest.
|
||||
|
||||
Quite simply change:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X = H / 2; Y = *x / 2;
|
||||
```
|
||||
|
||||
To be something like:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X = R(1,H-1);
|
||||
Y = R(2,*x-1);
|
||||
```
|
||||
@@ -395,7 +395,7 @@ street!).
|
||||
If you look at the walls code you will see a ternary operator for both `X` and `Y`
|
||||
coordinates. This of course is very different now but the idea remains the same:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (p && !(*O>=O[1]||H>=M(1)))
|
||||
{
|
||||
if (X<1||X>=H)
|
||||
@@ -414,7 +414,7 @@ coordinates to the correct new location.
|
||||
If however you wanted the walls to act as a barrier you could do something like
|
||||
this instead (omitting the inner if statements here):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X=X<1?1:*H-1;
|
||||
|
||||
Y=Y<2?2:*O-1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@ For more detailed information see [2020 ferguson1 bugs](../../bugs.html#2020_fer
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=N WALLS=[01] EVADE=N SIZE=N MAXSIZE=N GROW=N SHEDS=N SHED=N CANNIBAL=[01] ./prog
|
||||
# start pressing some arrow keys
|
||||
```
|
||||
@@ -87,7 +87,7 @@ and non-zero).
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make test
|
||||
|
||||
WAIT=75 WALLS=1 CANNIBAL=1 ./prog
|
||||
@@ -211,7 +211,7 @@ features.
|
||||
Because all IOCCC entries should have a man page I have included one (even
|
||||
though much of it is what's also above). To render try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
man ./snake.1
|
||||
```
|
||||
|
||||
|
||||
+24
-24
@@ -141,7 +141,7 @@ like some of the other features this was not intentionally designed but is
|
||||
simply a fun consequence of the features I did implement.</p>
|
||||
<p>Let’s say you want to verify that the evade mode is at the right count. How
|
||||
can you verify it without modifying the code? Try:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>0 <span class="va">SHED</span><span class="op">=</span>1 <span class="va">SHEDS</span><span class="op">=</span>1 <span class="va">EVADE</span><span class="op">=</span>10 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=0 SHED=1 SHEDS=1 EVADE=10 ./prog</code></pre>
|
||||
<p>Since you start out at size 0 and you shed every movement then when you’re
|
||||
size 10 (as long as you don’t eat a bug of course!) the bug should evade.</p>
|
||||
<p>If you set it to <code>SIZE=10</code> there would be a difference of 10. Now every
|
||||
@@ -154,7 +154,7 @@ don’t at this time remember any I might have done.</p>
|
||||
<h1 id="the-snake-doesnt-seem-to-be-moving"><a name="stillsnake" href="#toc">The snake doesn’t seem to be moving</a></h1>
|
||||
<p>One way to show this is in full is to set the initial size and growth size to a
|
||||
high value; then try each one individually. For example:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 ./prog</code></pre>
|
||||
<p>In this case after you make the first move the snake will keep growing and
|
||||
so the snake tail stays in the same spot until after it’s the ‘full size’.
|
||||
When it has reached the full size then the entire body of the snake will
|
||||
@@ -201,24 +201,24 @@ way negative size will force a win.</p>
|
||||
<p>Here’s a fun output:</p>
|
||||
<pre><code> < <<<+</code></pre>
|
||||
<p>That’s from:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SHED</span><span class="op">=</span>1 <span class="va">SHEDS</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SHED=1 SHEDS=-1 ./prog</code></pre>
|
||||
<p>And right after that you would see:</p>
|
||||
<pre><code> YOU WIN!
|
||||
X:72/156 Y:20/41 S:997/997 B:0</code></pre>
|
||||
<p>Try this though:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SHEDS</span><span class="op">=</span>-1 <span class="va">SHED</span><span class="op">=</span>25 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SHEDS=-1 SHED=25 ./prog</code></pre>
|
||||
<p>And you’ll see that you start to be the normal size but then you leave your
|
||||
head several places until you end up getting to the max size (by way of it
|
||||
being unsigned). This isn’t a bug even if it might seem like one. In fact
|
||||
this is the basis of the grow/shrink mode of play that I talk about in the
|
||||
<a href="gameplay.html">gameplay.html</a> (<a href="gameplay.md">gameplay.md</a> on GitHub) file.</p>
|
||||
<p>Here’s another thing to be aware of. Let’s say you do:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>1 <span class="va">GROW</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=1 GROW=-1 ./prog</code></pre>
|
||||
<p>How many bugs will it take before you win? In fact it’s two: you would see the
|
||||
head twice: the second time once you ‘shrink’ down to size 0; it would then be
|
||||
that if you get another bug you will be at the ‘max size’:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:81/156</span> Y:35/41 S:997/997 B:2</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> YOU WIN!
|
||||
X:81/156 Y:35/41 S:997/997 B:2</code></pre>
|
||||
<h1 id="i-was-a-few-places-behind-my-tail-and-i-ran-into-it"><a name="bitetail" href="#toc">‘I was a few places behind my tail and I ran into it!’</a></h1>
|
||||
<p>I.e. what happens if you’re growing - for example after just eating a bug - and
|
||||
you’re racing towards your tail? If you’re behind it should be fine since you’re
|
||||
@@ -271,23 +271,23 @@ how it’s done in Snake and works well). The minimum terminal size I require in
|
||||
the game is 10 x 10. This includes the walls and score line.</p>
|
||||
<p>Now the default max snake size is 997 but when the terminal is too small it
|
||||
adjusts the max snake size. For 10 lines and 10 columns you would see:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> make test</span>
|
||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports cursor movement</span>
|
||||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports making cursor invisible</span>
|
||||
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports bold</span>
|
||||
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports colours</span>
|
||||
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> rows 10 <span class="er">(</span><span class="ex">7</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> cols 10 <span class="er">(</span><span class="ex">8</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">snake</span> size: 49 <span class="er">(</span><span class="ex">max</span> size: 49<span class="kw">)</span></span>
|
||||
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">bugs:</span> 9 <span class="er">(</span><span class="ex">max</span> size: 9<span class="kw">)</span></span>
|
||||
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 28 columns recommended for snake size 49 <span class="er">(</span><span class="ex">is</span> 10<span class="kw">)</span></span>
|
||||
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 28 columns recommended for snake size 49 <span class="er">(</span><span class="ex">is</span> 10<span class="kw">)</span></span>
|
||||
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">1</span> problem detected <span class="er">(</span><span class="ex">0</span> fatal<span class="kw">)</span><span class="bu">.</span></span>
|
||||
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">make:</span> <span class="pp">***</span> <span class="pp">[</span><span class="ss">test</span><span class="pp">]</span> Error 1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ make test
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
terminal supports colours
|
||||
|
||||
terminal rows 10 (7 playable)
|
||||
terminal cols 10 (8 playable)
|
||||
|
||||
snake size: 49 (max size: 49)
|
||||
bugs: 9 (max size: 9)
|
||||
|
||||
at least 28 columns recommended for snake size 49 (is 10)
|
||||
at least 28 columns recommended for snake size 49 (is 10)
|
||||
|
||||
1 problem detected (0 fatal).
|
||||
make: *** [test] Error 1</code></pre>
|
||||
<p>First: what’s the problem? It’s just a warning that for the snake size of 49 the
|
||||
recommended size of columns is 28. However this is just for the score text; with
|
||||
only 10 columns it will overflow and wrap to the next line(s). But if you observe
|
||||
|
||||
@@ -22,7 +22,7 @@ simply a fun consequence of the features I did implement.
|
||||
Let's say you want to verify that the evade mode is at the right count. How
|
||||
can you verify it without modifying the code? Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=0 SHED=1 SHEDS=1 EVADE=10 ./prog
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ don't at this time remember any I might have done.
|
||||
One way to show this is in full is to set the initial size and growth size to a
|
||||
high value; then try each one individually. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 ./prog
|
||||
```
|
||||
|
||||
@@ -113,7 +113,7 @@ Here's a fun output:
|
||||
|
||||
That's from:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SHED=1 SHEDS=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -126,7 +126,7 @@ And right after that you would see:
|
||||
|
||||
Try this though:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SHEDS=-1 SHED=25 ./prog
|
||||
```
|
||||
|
||||
@@ -138,7 +138,7 @@ this is the basis of the grow/shrink mode of play that I talk about in the
|
||||
|
||||
Here's another thing to be aware of. Let's say you do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=1 GROW=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -146,7 +146,7 @@ How many bugs will it take before you win? In fact it's two: you would see the
|
||||
head twice: the second time once you 'shrink' down to size 0; it would then be
|
||||
that if you get another bug you will be at the 'max size':
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
YOU WIN!
|
||||
X:81/156 Y:35/41 S:997/997 B:2
|
||||
```
|
||||
@@ -228,7 +228,7 @@ the game is 10 x 10. This includes the walls and score line.
|
||||
Now the default max snake size is 997 but when the terminal is too small it
|
||||
adjusts the max snake size. For 10 lines and 10 columns you would see:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ make test
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
|
||||
@@ -274,7 +274,7 @@ most of them.</p>
|
||||
<h2 id="example-5-snake-moving-left-with-snake-inside-itsself">Example 5: snake moving left with snake inside itsself</h2>
|
||||
<p>Another example invocation where the snake head is in the snake and where the snake
|
||||
hadn’t yet moved (that is it was still growing):</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">SIZE</span><span class="op">=</span>1500 <span class="va">GROW</span><span class="op">=</span>2 <span class="va">MAXSIZE</span><span class="op">=</span>1600 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 SIZE=1500 GROW=2 MAXSIZE=1600 ./prog</code></pre>
|
||||
<p>It looked like:</p>
|
||||
<pre><code> X:55/89 Y:11/25 S:1564/1600 B:32
|
||||
##########################################################################################
|
||||
|
||||
@@ -184,7 +184,7 @@ most of them.
|
||||
Another example invocation where the snake head is in the snake and where the snake
|
||||
hadn't yet moved (that is it was still growing):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 SIZE=1500 GROW=2 MAXSIZE=1600 ./prog
|
||||
```
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<p>The following are a few screen dumps of:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">SHEDS</span><span class="op">=</span>5 <span class="va">GROW</span><span class="op">=</span>-10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>As you will see it took 17 bugs to get down to below 0. Notice how I had to get
|
||||
down to 0 more than once: because I moved enough times before I got the last
|
||||
bug that I grew by 5 in size. I then however moved a bit more and ate a bug
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The following are a few screen dumps of:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
|
||||
@@ -451,9 +451,9 @@ setting the max size to a smaller value than the size you specify (or the
|
||||
default) or setting the size to higher than the default (or < 0 which will end
|
||||
up being > the max size though I suppose there might be some value that makes it
|
||||
less than again - I’m not going to try and figure that out however). Anyway:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>-1 <span class="ex">./prog</span></span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:24/49</span> Y:8/16 S:658/658 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=-1 ./prog
|
||||
YOU WIN!
|
||||
X:24/49 Y:8/16 S:658/658 B:0</code></pre>
|
||||
<p>Observe that the size isn’t the default 997: because the screen size is too
|
||||
small for that value (see <a href="terminals.md">terminals.md</a>).</p>
|
||||
<p>The reason I chose 997 is that it leaves a bit of a challenge for some (maybe
|
||||
@@ -499,22 +499,22 @@ you have any form of epilepsy. Thank you.</strong></p>
|
||||
<p>If you want to draw the snake wherever you like on the screen you can do this by
|
||||
modifying the wait time (for input) to -1 (or any value < 0): then the snake
|
||||
does not move until you press a movement key. For example:</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=-1 ./prog</code></pre>
|
||||
<p>When you eat a bug the snake will grow and you can draw more. If you want to
|
||||
make it so you can go through yourself:</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>-1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=-1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>If you don’t want to start out so small (i.e. you want to be able to draw more
|
||||
quickly) you can just set the size to a bigger number (and you could do the same
|
||||
with growth and moult/shed):</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>50 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=50 CANNIBAL=1 WAIT=-1 ./prog</code></pre>
|
||||
<p>Do note that although you’re a bigger size you still grow one movement at a
|
||||
time.</p>
|
||||
<p>Okay but then if you get too many bugs the drawing will be over. If this proves
|
||||
to be a problem simply do:</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>-1 <span class="va">GROW</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 CANNIBAL=1 WAIT=-1 GROW=0 ./prog</code></pre>
|
||||
<p>Or something like that (maybe make the size bigger but that’s up to you). You
|
||||
could also set the max size to be the highest possible by saying</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="va">MAXSIZE</span><span class="op">=</span>-1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> MAXSIZE=-1</code></pre>
|
||||
<p>Which I’ve done in the <a href="play.sh">play.sh</a> script.</p>
|
||||
<p>I discuss how this mode works in [spoilers.markdown][].</p>
|
||||
<p>Here’s an example run where I spelt ‘SNAKE’. As you can see it’s far from
|
||||
@@ -536,7 +536,7 @@ different colours and depending on the exact parameters you specify it could
|
||||
easily be in the trigger range for epilepsy but potentially stimulation overload
|
||||
too.</p>
|
||||
<p>If you’re still here you can create this effect like:</p>
|
||||
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 WALLS=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>As long as the bug evades you’ll find that the snake is growing because it’s
|
||||
actually eating bugs; the computer is actually playing the game by itself! You
|
||||
can still move the snake though it won’t seem like you have much control over
|
||||
@@ -553,14 +553,14 @@ happen because the bug has to find a X and Y coordinate that’s not occupied an
|
||||
so with fewer available it has a harder time finding a place in that one line.</p>
|
||||
<h3 id="computer-player-variations"><a name="auto-variations" href="#toc">Computer player variations</a></h3>
|
||||
<p>Here’s how to make the bug move every time the snake moves:</p>
|
||||
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 ./prog</code></pre>
|
||||
<h4 id="help-the-computer-win-fairly-quickly">Help the computer win fairly quickly</h4>
|
||||
<p>If you want to see the game ‘win’ try something like:</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog</code></pre>
|
||||
<h4 id="negative-growth-shrink-automatic-mode">Negative growth (Shrink) Automatic mode</h4>
|
||||
<p>Here’s a fun one I just thought of (a long time after these other modes were
|
||||
thought of):</p>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">GROW</span><span class="op">=</span>-1 <span class="va">SIZE</span><span class="op">=</span>9 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 EVADE=1 GROW=-1 SIZE=9 MAXSIZE=10 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>What you’ll see is that first the snake will get to the size of 9 - whether it
|
||||
shows to be 10 characters depends on whether or not it gets a bug before it can
|
||||
get to that length - and then it’ll start shrinking until it’s just the head
|
||||
@@ -568,7 +568,7 @@ then the head again (i.e. 1 then 0 in size) and then win! This is also in the
|
||||
<a href="play.sh">play.sh</a> script.</p>
|
||||
<h4 id="adjusting-the-timespeed">Adjusting the time/speed</h4>
|
||||
<p>Of course you can also do something like:</p>
|
||||
<div class="sourceCode" id="cb26"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>5 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=5 WALLS=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>Which although might not seem like it is significantly slower.</p>
|
||||
<h4 id="moving-the-snake-about-to-create-patterns">Moving the snake about to create patterns</h4>
|
||||
<p>If you press different direction keys in some pattern you will see a pattern
|
||||
@@ -578,7 +578,7 @@ suppose also how much the bug moves and the chance of being eaten also).</p>
|
||||
<p>Here’s an idea: how many moves is needed to make it possible to have some sort
|
||||
of success in catching bugs? Obviously the dimensions will affect this value.</p>
|
||||
<p>How long will it take for the snake to run into itself? For instance by doing:</p>
|
||||
<div class="sourceCode" id="cb27"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 ./prog</code></pre>
|
||||
<p>On my 13” MacBook Pro (replaced later by a 16”) at the default settings going
|
||||
horizontally the snake ran into itself at:</p>
|
||||
<pre><code> OW!
|
||||
@@ -592,7 +592,7 @@ or growing to the full size directly. This is how it works:</p>
|
||||
<p>You have a negative shedding growth and a positive growth size: negative and
|
||||
positive winning. Depending on the parameters specified it might go one way over
|
||||
the other. Try:</p>
|
||||
<div class="sourceCode" id="cb29"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>150 <span class="va">SHEDS</span><span class="op">=</span>-5 <span class="va">GROW</span><span class="op">=</span>10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=150 SHEDS=-5 GROW=10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>What this does is set the size to 150 (to make it not go down so quickly) and
|
||||
then for each bug you eat it adds 5 to the size; for every 50 moves (that you
|
||||
don’t get the bug) you shrink by 5. You will find that at times you might only
|
||||
@@ -608,7 +608,7 @@ dumps with this idea.</p>
|
||||
<p>You could also have it so that eating a bug makes you shrink and moving so many
|
||||
moves you grow. I tried this and for me it was far more fun. The <a href="play.sh">play.sh</a>
|
||||
also has this mode:</p>
|
||||
<div class="sourceCode" id="cb30"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">SHEDS</span><span class="op">=</span>5 <span class="va">GROW</span><span class="op">=</span>-10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>Obviously there are many other variations. The <a href="play.sh">play.sh</a> script has some
|
||||
of them (the above is option 5; others are 4, 15 and 16 but only options 4 and 5
|
||||
are called Grow / Shrink).</p>
|
||||
@@ -622,7 +622,7 @@ typical range of seizures is 3 to 30 flashes per seconds (but can be higher) and
|
||||
that means that at <strong>EVADE=1</strong> every 231ms there will be a flash in addition to the
|
||||
snake moving too.</p>
|
||||
<p>Anyway this might sound absurd but it can be somewhat hypnotic by doing:</p>
|
||||
<div class="sourceCode" id="cb31"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a> <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> EVADE=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>And just moving the snake about not trying to catch any bugs - just let whatever
|
||||
happens happen.</p>
|
||||
<h2 id="gameplay-mode-stimulation-calming-mode"><a name="stim" href="#toc">Gameplay mode: Stimulation / Calming mode</a></h2>
|
||||
@@ -631,7 +631,7 @@ want to play a game without having to worry about winning or losing you can set
|
||||
the growth size to 0 and then just move the snake round and round eating bugs
|
||||
until you want to quit. You can enable cannibalism so that you don’t have to
|
||||
worry about even running into yourself and losing:</p>
|
||||
<div class="sourceCode" id="cb32"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a> <span class="va">GROW</span><span class="op">=</span>0 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> GROW=0 CANNIBAL=1 ./prog</code></pre>
|
||||
<h2 id="gameplay-mode-expansibility"><a name="expansibility" href="#toc">Gameplay mode: Expansibility</a></h2>
|
||||
<p>As I was writing this document and the game modes I have thought of other game
|
||||
modes (they were added) and I have come back to this document to add more modes.
|
||||
@@ -650,9 +650,9 @@ reason as well as I simply enjoy it and thinking up new modes.</p>
|
||||
this file discusses as well as allowing to easily change the colours.</p>
|
||||
<h2 id="colours-selection-snake-colours"><a name="colours" href="#toc">Colours selection: snake-colours</a></h2>
|
||||
<p>To do this use the <a href="snake-colours">snake-colours</a> script like so:</p>
|
||||
<div class="sourceCode" id="cb33"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./snake-colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./snake-colours</code></pre>
|
||||
<p>If you want to pass in specific variables you can do that too e.g.:</p>
|
||||
<div class="sourceCode" id="cb34"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./snake-colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 ./snake-colours</code></pre>
|
||||
<p>The script will prompt you for the colour of the walls, snake head, body and the
|
||||
bug.</p>
|
||||
<h2 id="automate-the-above-gameplay-modes"><a name="preset" href="#toc">Automate the above gameplay modes</a></h2>
|
||||
@@ -664,9 +664,9 @@ snake-colours above) and then gives you a list of game modes to play. You can
|
||||
pass in the game variables but note that if you pass in a variable that the mode
|
||||
you choose uses then the script will override what you pass in.</p>
|
||||
<p>To use you can do something like:</p>
|
||||
<div class="sourceCode" id="cb35"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./play.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./play.sh</code></pre>
|
||||
<p>Or to make it so walls are an obstacle:</p>
|
||||
<div class="sourceCode" id="cb36"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>0 <span class="ex">./play.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=0 ./play.sh</code></pre>
|
||||
<h1 id="notes-about-some-of-the-game-variables">6. <a name="variables" href="#toc">Notes about some of the game variables</a></h1>
|
||||
<p>The game variables can be used for a variety of things including different
|
||||
gameplay modes (as shown above) but here are some general notes about a few of them.</p>
|
||||
|
||||
+20
-20
@@ -415,7 +415,7 @@ default) or setting the size to higher than the default (or < 0 which will end
|
||||
up being > the max size though I suppose there might be some value that makes it
|
||||
less than again - I'm not going to try and figure that out however). Anyway:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=-1 ./prog
|
||||
YOU WIN!
|
||||
X:24/49 Y:8/16 S:658/658 B:0
|
||||
@@ -487,7 +487,7 @@ If you want to draw the snake wherever you like on the screen you can do this by
|
||||
modifying the wait time (for input) to -1 (or any value < 0): then the snake
|
||||
does not move until you press a movement key. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -495,7 +495,7 @@ does not move until you press a movement key. For example:
|
||||
When you eat a bug the snake will grow and you can draw more. If you want to
|
||||
make it so you can go through yourself:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=-1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -503,7 +503,7 @@ If you don't want to start out so small (i.e. you want to be able to draw more
|
||||
quickly) you can just set the size to a bigger number (and you could do the same
|
||||
with growth and moult/shed):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=50 CANNIBAL=1 WAIT=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -513,14 +513,14 @@ time.
|
||||
Okay but then if you get too many bugs the drawing will be over. If this proves
|
||||
to be a problem simply do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 CANNIBAL=1 WAIT=-1 GROW=0 ./prog
|
||||
```
|
||||
|
||||
Or something like that (maybe make the size bigger but that's up to you). You
|
||||
could also set the max size to be the highest possible by saying
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
MAXSIZE=-1
|
||||
```
|
||||
|
||||
@@ -556,7 +556,7 @@ too.
|
||||
|
||||
If you're still here you can create this effect like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 WALLS=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -582,7 +582,7 @@ so with fewer available it has a harder time finding a place in that one line.
|
||||
|
||||
Here's how to make the bug move every time the snake moves:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 ./prog
|
||||
```
|
||||
|
||||
@@ -591,7 +591,7 @@ Here's how to make the bug move every time the snake moves:
|
||||
|
||||
If you want to see the game 'win' try something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog
|
||||
```
|
||||
|
||||
@@ -601,7 +601,7 @@ If you want to see the game 'win' try something like:
|
||||
Here's a fun one I just thought of (a long time after these other modes were
|
||||
thought of):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 EVADE=1 GROW=-1 SIZE=9 MAXSIZE=10 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -616,7 +616,7 @@ then the head again (i.e. 1 then 0 in size) and then win! This is also in the
|
||||
|
||||
Of course you can also do something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=5 WALLS=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -635,7 +635,7 @@ of success in catching bugs? Obviously the dimensions will affect this value.
|
||||
|
||||
How long will it take for the snake to run into itself? For instance by doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 ./prog
|
||||
```
|
||||
|
||||
@@ -660,7 +660,7 @@ You have a negative shedding growth and a positive growth size: negative and
|
||||
positive winning. Depending on the parameters specified it might go one way over
|
||||
the other. Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=150 SHEDS=-5 GROW=10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
@@ -683,7 +683,7 @@ You could also have it so that eating a bug makes you shrink and moving so many
|
||||
moves you grow. I tried this and for me it was far more fun. The [play.sh][]
|
||||
also has this mode:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
@@ -705,7 +705,7 @@ snake moving too.
|
||||
|
||||
Anyway this might sound absurd but it can be somewhat hypnotic by doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
EVADE=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -721,7 +721,7 @@ the growth size to 0 and then just move the snake round and round eating bugs
|
||||
until you want to quit. You can enable cannibalism so that you don't have to
|
||||
worry about even running into yourself and losing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
GROW=0 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -752,13 +752,13 @@ this file discusses as well as allowing to easily change the colours.
|
||||
|
||||
To do this use the [snake-colours][] script like so:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./snake-colours
|
||||
```
|
||||
|
||||
If you want to pass in specific variables you can do that too e.g.:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 ./snake-colours
|
||||
```
|
||||
|
||||
@@ -777,13 +777,13 @@ you choose uses then the script will override what you pass in.
|
||||
|
||||
To use you can do something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./play.sh
|
||||
```
|
||||
|
||||
Or to make it so walls are an obstacle:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=0 ./play.sh
|
||||
```
|
||||
|
||||
|
||||
+23
-23
@@ -141,14 +141,14 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_ferguson1">2020 ferguson1 bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>N <span class="va">WALLS</span><span class="op">=</span><span class="pp">[</span><span class="ss">01</span><span class="pp">]</span> <span class="va">EVADE</span><span class="op">=</span>N <span class="va">SIZE</span><span class="op">=</span>N <span class="va">MAXSIZE</span><span class="op">=</span>N <span class="va">GROW</span><span class="op">=</span>N <span class="va">SHEDS</span><span class="op">=</span>N <span class="va">SHED</span><span class="op">=</span>N <span class="va">CANNIBAL</span><span class="op">=</span><span class="pp">[</span><span class="ss">01</span><span class="pp">]</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># start pressing some arrow keys</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=N WALLS=[01] EVADE=N SIZE=N MAXSIZE=N GROW=N SHEDS=N SHED=N CANNIBAL=[01] ./prog
|
||||
# start pressing some arrow keys</code></pre>
|
||||
<p>where <code>N</code> is a number and <code>[01]</code> is either <code>1</code> or <code>0</code> (or more correctly zero
|
||||
and non-zero).</p>
|
||||
<h3 id="variables">Variables:</h3>
|
||||
@@ -202,25 +202,25 @@ whether you can go through the Snake or not. Default is 0
|
||||
(cannot - die if you try).</p></li>
|
||||
</ul>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> test</span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>75 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span>
|
||||
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>-1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>50 <span class="va">EVADE</span><span class="op">=</span>200 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>75 <span class="va">GROW</span><span class="op">=</span>-1 <span class="va">SIZE</span><span class="op">=</span>5 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">./play</span></span>
|
||||
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a> <span class="co"># allows you to configure colours and has various pre-configured gameplay modes</span></span>
|
||||
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">./snake-colours</span></span>
|
||||
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a> <span class="co"># allows for configuring colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make test
|
||||
|
||||
WAIT=75 WALLS=1 CANNIBAL=1 ./prog
|
||||
|
||||
./prog
|
||||
|
||||
SIZE=-1 ./prog
|
||||
|
||||
CANNIBAL=1 WALLS=1 WAIT=50 EVADE=200 ./prog
|
||||
|
||||
WAIT=75 GROW=-1 SIZE=5 CANNIBAL=1 ./prog
|
||||
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog
|
||||
|
||||
./play
|
||||
# allows you to configure colours and has various pre-configured gameplay modes
|
||||
|
||||
./snake-colours
|
||||
# allows for configuring colours</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>As the <a href="https://en.wikipedia.org/wiki/Gadsden_flag">Gadsden flag</a> warns, beware of the snake!
|
||||
This game has a number of configurable pitfalls including walls and snakes.</p>
|
||||
@@ -306,7 +306,7 @@ look like bugs but aren’t as well as documenting a built-in test unit for some
|
||||
features.</p>
|
||||
<p>Because all IOCCC entries should have a man page I have included one (even
|
||||
though much of it is what’s also above). To render try:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./snake.1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> man ./snake.1</code></pre>
|
||||
<p>The <a href="COMPILING.html">COMPILING.html</a> file has a few portability
|
||||
notes and the <a href="HACKING.html">HACKING.html</a> file has some
|
||||
information on how one might modify things, things that could be implemented
|
||||
|
||||
@@ -762,9 +762,9 @@ returning <code>E()</code> I am returning 1 but if the end of main() is reached
|
||||
returned. In either case curses is ended.</p>
|
||||
<p>One of these optimisations saved four bytes simply by taking advantage of the
|
||||
value of a loop iterator after the loop. The loop is:</p>
|
||||
<div class="sourceCode" id="cb27"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> <span class="op">(</span>I <span class="op">=</span> <span class="dv">0</span><span class="op">;</span> A <span class="op">&&</span> I <span class="op"><</span> A <span class="op">-</span> <span class="dv">1</span><span class="op">;</span> <span class="op">++</span>I<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> for (I = 0; A && I < A - 1; ++I)</code></pre>
|
||||
<p>However after the loop I had this:</p>
|
||||
<div class="sourceCode" id="cb28"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a> A <span class="op">></span> <span class="dv">1</span> <span class="op">&&</span> q<span class="op">(</span>n<span class="op">[</span>A <span class="op">-</span> <span class="dv">1</span><span class="op">],</span>e<span class="op">[</span>A <span class="op">-</span> <span class="dv">1</span><span class="op">],</span> <span class="ch">'o'</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> A > 1 && q(n[A - 1],e[A - 1], 'o');</code></pre>
|
||||
<p>When I was considering moving that line to before the loop it occurred to me
|
||||
that as long as <code>A > 0</code> then <code>A - 1 == I</code> after the loop. I still had to check
|
||||
for <code>A > 1</code> but I could refer to just <code>I</code> instead of <code>A - 1</code>!</p>
|
||||
@@ -779,31 +779,31 @@ place at this point) I was looking at the code to see if I could figure out how
|
||||
to save even more bytes. Here are some that I found interesting ways to go about
|
||||
the problem.</p>
|
||||
<p>First, the function that turns on colours looked like:</p>
|
||||
<div class="sourceCode" id="cb29"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>h<span class="op">)</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (h) attron(m(PAIR(L)));
|
||||
else attroff(m(PAIR(L)));</code></pre>
|
||||
<p>But I thought is that else actually needed? If I were to switch the order so
|
||||
that the <code>attroff()</code> is called first then I could just do an <code>if (h)</code> -
|
||||
therefore getting rid of the <code>else</code>! But then I thought why not do what I’ve
|
||||
done elsewhere? I had:</p>
|
||||
<div class="sourceCode" id="cb30"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>h<span class="op">)</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> attroff(m(PAIR(L)));
|
||||
if (h) attron(m(PAIR(L)));</code></pre>
|
||||
<p>But I then saved an extra byte by making it:</p>
|
||||
<div class="sourceCode" id="cb31"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> h <span class="op">&&</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> attroff(m(PAIR(L)));
|
||||
h && attron(m(PAIR(L)));</code></pre>
|
||||
<p>That saved two bytes.</p>
|
||||
<p>Second let’s look at the <code>B()</code> function: there were two things I thought of that
|
||||
would save some bytes (I no longer know how many but a few at least possibly six
|
||||
or even more). I had the following code:</p>
|
||||
<div class="sourceCode" id="cb32"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>V <span class="op">&&</span> U <span class="op">&&</span> o<span class="op">)</span> <span class="op">{</span> S<span class="op">(</span>N<span class="op">);</span> b<span class="op">(</span><span class="dv">1</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (V && U && o) { S(N); b(1); }</code></pre>
|
||||
<p>This made sure that only if the snake has caught a bug should it grow by the
|
||||
growth size and increase the bug count. But was checking for the <code>V</code> or <code>U</code>
|
||||
necessary? I gave it a look over and it occurred to me: the only time <code>B()</code> is
|
||||
called with <code>1</code> (thus <code>o</code> is 1 so the if is true) was if the bug actually is
|
||||
caught. That means I could remove the <code>V && U &&</code> part of the if! Thus it became
|
||||
instead:</p>
|
||||
<div class="sourceCode" id="cb33"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>o<span class="op">)</span> <span class="op">{</span> S<span class="op">(</span>N<span class="op">);</span> b<span class="op">(</span><span class="dv">1</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (o) { S(N); b(1); }</code></pre>
|
||||
<p>Then this</p>
|
||||
<div class="sourceCode" id="cb34"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> V <span class="op">&&</span> U <span class="op">&&</span> q U<span class="op">,</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && V && U && q U,V,' ');</code></pre>
|
||||
<p>…is to make sure to only clear the spot the bug is (or was) at if
|
||||
the bug was NOT eaten. Why not eaten? Because if it was eaten it means the
|
||||
snake’s head will be there!</p>
|
||||
@@ -818,7 +818,7 @@ unfortunately the snake has to be placed first since the bug cannot be placed
|
||||
where the snake already is. So if I had to make sure the game had started (the
|
||||
snake has moved at least once) what could I check? In fact that means the
|
||||
direction is not 0! So I could just replace it with:</p>
|
||||
<div class="sourceCode" id="cb35"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> D <span class="op">&&</span> q <span class="op">*</span>U<span class="op">,*</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && D && q *U,*V,' ');</code></pre>
|
||||
<p>That reduced the count further. But then I wondered if even that much is needed.
|
||||
The condition is that the bug has evaded which means the snake has moved already
|
||||
(so game started). What calls to this function happen before the game starts
|
||||
@@ -831,7 +831,7 @@ to check for is that <code>!o</code>: because after this call before the game ev
|
||||
the score line is updated: so the empty space will be overwritten anyway. And if
|
||||
the score line is made an empty string it doesn’t matter because it’ll appear as
|
||||
all spaces anyway. Thus I could save another three bytes by changing it to:</p>
|
||||
<div class="sourceCode" id="cb36"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> q <span class="op">*</span>U<span class="op">,*</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && q *U,*V,' ');</code></pre>
|
||||
<p>Technically it would be a <code>" "</code> (see <a href="HACKING.html">HACKING.html</a> or on GitHub
|
||||
<a href="HACKING.md">HACKING.md</a>) else for N (not referring to the variable though it might very
|
||||
well matter here too) movements (i.e. due to sizes) you will at times (e.g.
|
||||
|
||||
+10
-10
@@ -818,13 +818,13 @@ returned. In either case curses is ended.
|
||||
One of these optimisations saved four bytes simply by taking advantage of the
|
||||
value of a loop iterator after the loop. The loop is:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
for (I = 0; A && I < A - 1; ++I)
|
||||
```
|
||||
|
||||
However after the loop I had this:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
A > 1 && q(n[A - 1],e[A - 1], 'o');
|
||||
```
|
||||
|
||||
@@ -847,7 +847,7 @@ the problem.
|
||||
|
||||
First, the function that turns on colours looked like:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (h) attron(m(PAIR(L)));
|
||||
else attroff(m(PAIR(L)));
|
||||
```
|
||||
@@ -857,14 +857,14 @@ that the `attroff()` is called first then I could just do an `if (h)` -
|
||||
therefore getting rid of the `else`! But then I thought why not do what I've
|
||||
done elsewhere? I had:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
attroff(m(PAIR(L)));
|
||||
if (h) attron(m(PAIR(L)));
|
||||
```
|
||||
|
||||
But I then saved an extra byte by making it:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
attroff(m(PAIR(L)));
|
||||
h && attron(m(PAIR(L)));
|
||||
```
|
||||
@@ -875,7 +875,7 @@ Second let's look at the `B()` function: there were two things I thought of that
|
||||
would save some bytes (I no longer know how many but a few at least possibly six
|
||||
or even more). I had the following code:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (V && U && o) { S(N); b(1); }
|
||||
```
|
||||
|
||||
@@ -886,13 +886,13 @@ called with `1` (thus `o` is 1 so the if is true) was if the bug actually is
|
||||
caught. That means I could remove the `V && U &&` part of the if! Thus it became
|
||||
instead:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (o) { S(N); b(1); }
|
||||
```
|
||||
|
||||
Then this
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && V && U && q U,V,' ');
|
||||
```
|
||||
|
||||
@@ -913,7 +913,7 @@ where the snake already is. So if I had to make sure the game had started (the
|
||||
snake has moved at least once) what could I check? In fact that means the
|
||||
direction is not 0! So I could just replace it with:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && D && q *U,*V,' ');
|
||||
```
|
||||
|
||||
@@ -930,7 +930,7 @@ the score line is updated: so the empty space will be overwritten anyway. And if
|
||||
the score line is made an empty string it doesn't matter because it'll appear as
|
||||
all spaces anyway. Thus I could save another three bytes by changing it to:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && q *U,*V,' ');
|
||||
```
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ movement is required) I have provided a source file that can test your terminal
|
||||
for the capabilities I use in the entry.</p>
|
||||
<p>It also tries to determine the minimum number of columns to play without the
|
||||
status line overflowing - even with the dynamic length. Try:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> make test</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ make test</code></pre>
|
||||
<p>This compiles the program <a href="termcaps.c">termcaps.c</a> and runs it; you should see something like:</p>
|
||||
<pre><code> terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
@@ -178,21 +178,21 @@ maximum (capped) snake size.</p>
|
||||
<p>If I pass in any of the variables <strong>GROW</strong>, <strong>MAXSIZE</strong>, <strong>SIZE</strong> and/or
|
||||
<strong>LINES</strong> or <strong>COLUMNS</strong> it bases its calculations on those variables. For
|
||||
example:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports cursor movement</span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports making cursor invisible</span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports bold</span>
|
||||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports colours</span>
|
||||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> rows 41 <span class="er">(</span><span class="ex">38</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> cols 155 <span class="er">(</span><span class="ex">153</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">snake</span> size: 5776 <span class="er">(</span><span class="ex">max</span> size: 5776<span class="kw">)</span></span>
|
||||
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">bugs:</span> 5771 <span class="er">(</span><span class="ex">max</span> size: 5771<span class="kw">)</span></span>
|
||||
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 37 columns <span class="er">(</span><span class="ex">currently</span> 155<span class="kw">)</span> <span class="ex">recommended</span> for snake size 5776</span>
|
||||
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 37 columns <span class="er">(</span><span class="ex">currently</span> 155<span class="kw">)</span> <span class="ex">recommended</span> for capped snake size 5776</span>
|
||||
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">No</span> problems detected.</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
terminal supports colours
|
||||
|
||||
terminal rows 41 (38 playable)
|
||||
terminal cols 155 (153 playable)
|
||||
|
||||
snake size: 5776 (max size: 5776)
|
||||
bugs: 5771 (max size: 5771)
|
||||
|
||||
at least 37 columns (currently 155) recommended for snake size 5776
|
||||
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||||
|
||||
No problems detected.</code></pre>
|
||||
<p>As you can see it tells you the max size (the ‘capsized’ snake) as well as the
|
||||
requested max size (if the requested size is bigger than the capped size then it
|
||||
will be set to that value instead) of the snake. The capped size is like in the
|
||||
@@ -224,12 +224,12 @@ resize the window with first. But what if you want exacts?</p>
|
||||
<p>To specify the lines/columns of curses program per instance use the <code>LINES</code> and
|
||||
<code>COLUMNS</code> environmental variables.</p>
|
||||
<p>For demonstration consider the following:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo <span class="va">$LINES</span> <span class="va">$COLUMNS</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">42</span> 157</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo $LINES $COLUMNS
|
||||
42 157</code></pre>
|
||||
<p>Note: I subtract 1 from the max y/x and the max coords in the game output
|
||||
include the walls and score line but these values are for the terminal itself.</p>
|
||||
<p>Say you want 55 columns:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> COLUMNS=55 ./prog</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ COLUMNS=55 ./prog</code></pre>
|
||||
<p>This will force curses to detect the max columns (X) of your terminal (for the
|
||||
game dimensions) - to be 55; it might look like this instead:</p>
|
||||
<pre><code> X:27/54 Y:20/41 S:5/997 B:0</code></pre>
|
||||
@@ -245,8 +245,8 @@ etc. For the game you might not see the final score.</p>
|
||||
<p>In my tests there is one thing that at least allows you to see the final score
|
||||
and that is by running <code>clear</code> before running the program. That’s what the
|
||||
prog.alt version does. You might run it as one of:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>20 <span class="ex">./prog.alt</span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>20 <span class="ex">./snake.alt</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> LINES=20 ./prog.alt
|
||||
LINES=20 ./snake.alt</code></pre>
|
||||
<p>Even if the final score is visible though the terminal may very well still be
|
||||
messed up. There are numerous things you might try but probably the easiest is
|
||||
to run the game again without modifying the dimensions (and then just quit) or
|
||||
@@ -259,7 +259,7 @@ even just the <code>reset</code> command.</p>
|
||||
(the line-feed character is normally control-J) to get the terminal
|
||||
to work, as carriage-return may no longer work in the abnormal state.</code></pre>
|
||||
<p>If you don’t have the reset utility you can try:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="at">-e</span> <span class="dt">\\</span>033c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> echo -e \\033c</code></pre>
|
||||
<p>Otherwise try <code>clear; stty sane</code> (that will turn on echo also) or if all else
|
||||
fails log out and back in.</p>
|
||||
<p>For more information on this subject generally see the <a href="https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO.html">Linux keyboard and
|
||||
@@ -271,10 +271,10 @@ outside what’s actually possible with their screen. But then player 4 comes
|
||||
along and thinks he/she will be clever and mess with the dimensions a bit. Let’s
|
||||
say they have a 13” monitor and they think it’d be funny to see how 997 lines
|
||||
would work; they might try something like:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>997 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> LINES=997 ./prog</code></pre>
|
||||
<p>What then? Well expect trouble; curses will not know any better and the max
|
||||
number of lines will be 997. If they were to do:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="va">COLUMNS</span><span class="op">=</span>997 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> COLUMNS=997 ./prog</code></pre>
|
||||
<p>Then they will see a different effect. Again the same reason: the player trying
|
||||
to be funny.</p>
|
||||
<p>The game will try and be funny in return and you can expect it to not function
|
||||
@@ -306,7 +306,7 @@ GitHub) file).</p>
|
||||
<p>According to my tests for monochrome terminals the screen has the white and
|
||||
black background; if terminal is configured to be black background white
|
||||
foreground that is the order it is too. You can try that like:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./prog</code></pre>
|
||||
<p>But I do not specifically check if the terminal has colours. Is there a curses
|
||||
implementation that has a problem here? Below I explain what to comment out
|
||||
should you need colours to be disabled but I personally have not run into any
|
||||
@@ -328,19 +328,19 @@ support in the source code itself.</p>
|
||||
<p>Based on the two as well as the fact that monochrome terminals (I’ve tried under
|
||||
both Linux and macOS) seem to work fine I believe I am fine here too. And to
|
||||
confirm this I wrote the following code with the output below:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include </span><span class="im"><curses.h></span></span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main<span class="op">()</span></span>
|
||||
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> initscr<span class="op">();</span></span>
|
||||
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> start_color<span class="op">();</span></span>
|
||||
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> printw<span class="op">(</span><span class="st">"COLORS: </span><span class="sc">%d\n</span><span class="st">COLOR_PAIRS: </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> COLORS<span class="op">,</span> COLOR_PAIRS<span class="op">);</span></span>
|
||||
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> getch<span class="op">();</span></span>
|
||||
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> endwin<span class="op">();</span></span>
|
||||
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./colour_pairs</span></span>
|
||||
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">COLORS:</span> 0</span>
|
||||
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">COLOR_PAIRS:</span> 0</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #include <curses.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
initscr();
|
||||
start_color();
|
||||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||||
getch();
|
||||
endwin();
|
||||
}</code></pre>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./colour_pairs
|
||||
COLORS: 0
|
||||
COLOR_PAIRS: 0</code></pre>
|
||||
<p>Without specifying the TERM I get:</p>
|
||||
<pre><code> COLORS: 256
|
||||
COLOR_PAIRS: 32767</code></pre>
|
||||
@@ -348,22 +348,22 @@ confirm this I wrote the following code with the output below:</p>
|
||||
possible colour pairs than I have used so that’s not a problem either. Perhaps
|
||||
even it would only be a runtime error if the colours are supported and the
|
||||
number is out of the range? To try and figure this out I did another test:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main<span class="op">()</span></span>
|
||||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> initscr<span class="op">();</span></span>
|
||||
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> start_color<span class="op">();</span></span>
|
||||
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span>COLOR_PAIRS<span class="op">+</span><span class="dv">1</span><span class="op">,</span> COLOR_WHITE<span class="op">,</span> COLOR_GREEN<span class="op">);</span></span>
|
||||
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a> bkgd<span class="op">(</span>COLOR_PAIR<span class="op">(</span>COLOR_PAIRS<span class="op">+</span><span class="dv">1</span><span class="op">));</span></span>
|
||||
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span><span class="dv">1</span><span class="op">,</span> COLOR_WHITE<span class="op">,</span> COLOR_BLACK<span class="op">);</span></span>
|
||||
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a> attron<span class="op">(</span>COLOR_PAIR<span class="op">(</span><span class="dv">1</span><span class="op">));</span></span>
|
||||
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a> printw<span class="op">(</span><span class="st">"COLORS: </span><span class="sc">%d\n</span><span class="st">COLOR_PAIRS: </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> COLORS<span class="op">,</span> COLOR_PAIRS<span class="op">);</span></span>
|
||||
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a> getch<span class="op">();</span></span>
|
||||
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a> endwin<span class="op">();</span></span>
|
||||
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> int main()
|
||||
{
|
||||
initscr();
|
||||
start_color();
|
||||
|
||||
init_pair(COLOR_PAIRS+1, COLOR_WHITE, COLOR_GREEN);
|
||||
bkgd(COLOR_PAIR(COLOR_PAIRS+1));
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLACK);
|
||||
attron(COLOR_PAIR(1));
|
||||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
}</code></pre>
|
||||
<p>Running it like</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./colour_pairs</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./colour_pairs</code></pre>
|
||||
<p>I got the output as if colours weren’t used: 0 and 0. With coloured terminals
|
||||
however it was not visible. If I however comment out the call to <code>bkgd()</code> I get
|
||||
instead:</p>
|
||||
|
||||
+13
-13
@@ -30,7 +30,7 @@ for the capabilities I use in the entry.
|
||||
It also tries to determine the minimum number of columns to play without the
|
||||
status line overflowing - even with the dynamic length. Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ make test
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ If I pass in any of the variables **GROW**, **MAXSIZE**, **SIZE** and/or
|
||||
**LINES** or **COLUMNS** it bases its calculations on those variables. For
|
||||
example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
@@ -129,7 +129,7 @@ To specify the lines/columns of curses program per instance use the `LINES` and
|
||||
|
||||
For demonstration consider the following:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo $LINES $COLUMNS
|
||||
42 157
|
||||
```
|
||||
@@ -139,7 +139,7 @@ include the walls and score line but these values are for the terminal itself.
|
||||
|
||||
Say you want 55 columns:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ COLUMNS=55 ./prog
|
||||
```
|
||||
|
||||
@@ -166,7 +166,7 @@ In my tests there is one thing that at least allows you to see the final score
|
||||
and that is by running `clear` before running the program. That's what the
|
||||
prog.alt version does. You might run it as one of:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
LINES=20 ./prog.alt
|
||||
LINES=20 ./snake.alt
|
||||
```
|
||||
@@ -190,7 +190,7 @@ The Linux man page says:
|
||||
|
||||
If you don't have the reset utility you can try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
echo -e \\033c
|
||||
```
|
||||
|
||||
@@ -209,14 +209,14 @@ along and thinks he/she will be clever and mess with the dimensions a bit. Let's
|
||||
say they have a 13" monitor and they think it'd be funny to see how 997 lines
|
||||
would work; they might try something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
LINES=997 ./prog
|
||||
```
|
||||
|
||||
What then? Well expect trouble; curses will not know any better and the max
|
||||
number of lines will be 997. If they were to do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
COLUMNS=997 ./prog
|
||||
```
|
||||
|
||||
@@ -265,7 +265,7 @@ According to my tests for monochrome terminals the screen has the white and
|
||||
black background; if terminal is configured to be black background white
|
||||
foreground that is the order it is too. You can try that like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./prog
|
||||
```
|
||||
|
||||
@@ -301,7 +301,7 @@ Based on the two as well as the fact that monochrome terminals (I've tried under
|
||||
both Linux and macOS) seem to work fine I believe I am fine here too. And to
|
||||
confirm this I wrote the following code with the output below:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#include <curses.h>
|
||||
|
||||
int main()
|
||||
@@ -314,7 +314,7 @@ confirm this I wrote the following code with the output below:
|
||||
}
|
||||
```
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./colour_pairs
|
||||
COLORS: 0
|
||||
COLOR_PAIRS: 0
|
||||
@@ -332,7 +332,7 @@ possible colour pairs than I have used so that's not a problem either. Perhaps
|
||||
even it would only be a runtime error if the colours are supported and the
|
||||
number is out of the range? To try and figure this out I did another test:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
int main()
|
||||
{
|
||||
initscr();
|
||||
@@ -351,7 +351,7 @@ number is out of the range? To try and figure this out I did another test:
|
||||
|
||||
Running it like
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./colour_pairs
|
||||
```
|
||||
|
||||
|
||||
@@ -372,7 +372,7 @@ hit a key every time to move because it is blocking.</p></li>
|
||||
</ul>
|
||||
<h2 id="on-environmental-variables-more-generally-and-string-to-int-conversions"><a name="envvars" href="#toc">On environmental variables more generally and string to int conversions</a></h2>
|
||||
<p>What happens if you do:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS= ./prog</code></pre>
|
||||
<p>Can you run into the wall since you didn’t specify a value and the default is 1?
|
||||
No. That’s not the way it works. By saying WALLS= you have told the system that
|
||||
there is that environmental variable. However the way the <code>strtoul()</code> functions
|
||||
@@ -381,12 +381,12 @@ it’s wasteful (iocccsize wise) and I have never felt that having invalid input
|
||||
for a number could have a better value than 0.</p>
|
||||
<p>If however you were to give valid input followed by invalid input the valid
|
||||
input would be parsed. For example:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>1test <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=1test ./prog</code></pre>
|
||||
<p>would let you go through the walls. On the other hand</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>test1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=test1 ./prog</code></pre>
|
||||
<p>would not. Furthermore if you specify the same variable more than once it’s the
|
||||
last one that counts. For example:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>0 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=0 WALLS=1 CANNIBAL=1 CANNIBAL=0 ./prog</code></pre>
|
||||
<p>would allow you to go through walls but you could not cannibalise.</p>
|
||||
<p>Also note that I specify base 0 which means that you can also have it in hex and
|
||||
octal. These are all the same:</p>
|
||||
@@ -421,17 +421,17 @@ will end (yes things that haven’t begun can be ended).</p>
|
||||
<p>If <code>calloc()</code> fails to obtain the needed memory you’ll see something like (here it
|
||||
was before I added proper - to make the perfect and obvious pun - capsizing
|
||||
so that by setting the size to -1 it went to the max unsigned value):</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> MAXSIZE=-1 ./prog</span>
|
||||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">memory</span> error</span>
|
||||
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:0/157</span> Y:0/42 S:3/18446744073709551614 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ MAXSIZE=-1 ./prog
|
||||
memory error
|
||||
X:0/157 Y:0/42 S:3/18446744073709551614 B:0</code></pre>
|
||||
<p>BTW: There are two arrays that have to be <strong>MAXSIZE</strong> (technically + 1).</p>
|
||||
<p>Is it possible that some value specified by the user could mess this up? I do
|
||||
not know but what I do know is that because it’s unsigned it can’t be negative;
|
||||
if the max size is 0 then the array size will be 1 but it won’t matter because
|
||||
the snake size will be >= that max anyway. But here’s a curious output:</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>0 <span class="ex">./prog</span></span>
|
||||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:78/156</span> Y:20/41 S:0/0 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=1 MAXSIZE=0 ./prog
|
||||
YOU WIN!
|
||||
X:78/156 Y:20/41 S:0/0 B:0</code></pre>
|
||||
<p>Why does it show snake size as 0 when I specified 1? It’s because the max size
|
||||
is 0 and I limit the size to be no bigger than the max size.</p>
|
||||
<!--
|
||||
|
||||
@@ -328,7 +328,7 @@ hit a key every time to move because it is blocking.
|
||||
|
||||
What happens if you do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS= ./prog
|
||||
```
|
||||
|
||||
@@ -342,20 +342,20 @@ for a number could have a better value than 0.
|
||||
If however you were to give valid input followed by invalid input the valid
|
||||
input would be parsed. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=1test ./prog
|
||||
```
|
||||
|
||||
would let you go through the walls. On the other hand
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=test1 ./prog
|
||||
```
|
||||
|
||||
would not. Furthermore if you specify the same variable more than once it's the
|
||||
last one that counts. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=0 WALLS=1 CANNIBAL=1 CANNIBAL=0 ./prog
|
||||
```
|
||||
|
||||
@@ -414,7 +414,7 @@ If `calloc()` fails to obtain the needed memory you'll see something like (here
|
||||
was before I added proper - to make the perfect and obvious pun - capsizing
|
||||
so that by setting the size to -1 it went to the max unsigned value):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ MAXSIZE=-1 ./prog
|
||||
memory error
|
||||
X:0/157 Y:0/42 S:3/18446744073709551614 B:0
|
||||
@@ -428,7 +428,7 @@ not know but what I do know is that because it's unsigned it can't be negative;
|
||||
if the max size is 0 then the array size will be 1 but it won't matter because
|
||||
the snake size will be >= that max anyway. But here's a curious output:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=1 MAXSIZE=0 ./prog
|
||||
YOU WIN!
|
||||
X:78/156 Y:20/41 S:0/0 B:0
|
||||
|
||||
+24
-24
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -11,7 +11,7 @@ at once. See [Alternate code](#alternate-code) below.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
|
||||
# get recode help:
|
||||
@@ -49,13 +49,13 @@ are allowed.
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
What does:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
echo | ./recode
|
||||
echo | ./recode -v
|
||||
```
|
||||
@@ -72,14 +72,14 @@ and to make it a bit more like the real thing.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
The default time to sleep is 400000 microseconds but you can change this by
|
||||
doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make clobber SLEEP=600000 alt
|
||||
```
|
||||
|
||||
@@ -93,7 +93,7 @@ Use `prog.alt` as you would `prog` above.
|
||||
|
||||
### Alternate try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.alt.sh
|
||||
```
|
||||
|
||||
@@ -110,7 +110,7 @@ There is a good deal of useful documentation that is provided with this entry:
|
||||
* [enigma.1](enigma.1) - A useful man page for this entry. To render, try:
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
man ./enigma.1
|
||||
```
|
||||
|
||||
@@ -251,7 +251,7 @@ the result (after finishing the enciphering).
|
||||
|
||||
If you run it like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog -
|
||||
```
|
||||
|
||||
@@ -283,7 +283,7 @@ program as well as how to use the two winning entries of the [Morse
|
||||
code](https://en.wikipedia.org/wiki/Morse_code) that I referred to earlier:
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog -
|
||||
Ring 1: 3
|
||||
Setting 1: I
|
||||
@@ -317,7 +317,7 @@ default settings; as the judges suggest this invocation I will not show it here.
|
||||
|
||||
But you can also type it out like this:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog
|
||||
IOCCC
|
||||
UUMMX
|
||||
@@ -328,7 +328,7 @@ The IOCCC comes from stdin; the `UUMMX` is written to stdout.
|
||||
If I compile the 2014 entry and copy it to my local directory as
|
||||
`vik` I might do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo TEST|./prog |./vik | mplayer -demuxer rawaudio -
|
||||
```
|
||||
|
||||
@@ -340,7 +340,7 @@ a bug in that entry (Fedora, CentOS and macOS all affected).
|
||||
For example I can use the syntax provided in the winning remarks along with my
|
||||
entry to write it to a file. Say:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo TEST|./prog |./vik > test.raw
|
||||
$ ./vik e < test.raw | ./prog
|
||||
LEST
|
||||
@@ -348,21 +348,21 @@ entry to write it to a file. Say:
|
||||
|
||||
Why did that happen? This shows more details:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./vik e < test.raw
|
||||
SCWV
|
||||
```
|
||||
|
||||
However as can be seen the first char is wrong:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo TEST|./prog
|
||||
KCWV
|
||||
```
|
||||
|
||||
And piping the original output to my entry itself you get the original input:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo TEST | ./prog | ./prog
|
||||
TEST
|
||||
```
|
||||
@@ -372,7 +372,7 @@ idea anyway. Neither do I know if the original transcoding is correct.
|
||||
|
||||
What if I use the input string `LEST` instead? In that case it worked fine:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo LEST | ./prog | ./vik > lest.raw
|
||||
$ ./vik e < lest.raw | ./prog
|
||||
LEST
|
||||
@@ -380,7 +380,7 @@ What if I use the input string `LEST` instead? In that case it worked fine:
|
||||
|
||||
But there's one obvious question, right? Let's try the most important one:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo IOCCC | ./prog | ./vik > ioccc.raw
|
||||
$ ./vik e < ioccc.raw
|
||||
UUMMX
|
||||
@@ -396,7 +396,7 @@ too. Notice also how it showed the same output that my program gave it - `UUMMX`
|
||||
|
||||
What about the other [Morse code entry](../../1998/dorssel/dorssel.c)?
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo IOCCC | ./prog | ./dorssel
|
||||
..- ..- -- -- -..-
|
||||
```
|
||||
@@ -441,7 +441,7 @@ The parser is in a sense rather rudimentary but allows for both interactive and
|
||||
automatic (e.g. via the [recode](recode.c) program) input. This does mean that
|
||||
something like the following can happen:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog -
|
||||
Ring 1: 1AB
|
||||
Setting 1: Position 1: Ring 2: 2CD
|
||||
@@ -504,7 +504,7 @@ should help you remember (though not at this time in our world it might help you
|
||||
later on?). This might become even more useful after the challenge is accepted,
|
||||
accomplished and made use of! :)
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo ABC | ./prog
|
||||
GYM
|
||||
$ echo ABC | ./prog | ./prog
|
||||
@@ -536,7 +536,7 @@ ended his life. (I later made a bug fix but I consider this inconsequential).
|
||||
|
||||
As for [recode.c][] though I really love this:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
/\
|
||||
/ This is *not* what you think:
|
||||
```
|
||||
@@ -552,13 +552,13 @@ It's an [Enigma machine](https://en.wikipedia.org/wiki/Enigma_machine) simulator
|
||||
that proof that it's obfuscated itself?! :) Silliness aside [obfuscation.txt][]
|
||||
has some of the ways I think this entry is obfuscated. To decipher try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./recode -Robfuscation.key -fobfuscation.txt | ./prog - 2>/dev/null > obfuscation.md
|
||||
```
|
||||
|
||||
To encipher:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./recode -Robfuscation.key -fobfuscation.md | ./prog - 2>/dev/null > obfuscation.txt
|
||||
```
|
||||
|
||||
|
||||
+113
-113
@@ -141,62 +141,62 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>The author provided alternate code that prints the output one character at a
|
||||
time to make it a bit more like the real thing in that it isn’t dumped out all
|
||||
at once. See <a href="#alternate-code">Alternate code</a> below.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># get recode help:</span></span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-h</span></span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># general syntax for recode passing to Enigma machine:</span></span>
|
||||
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="pp">[</span><span class="ss">options</span><span class="pp">]</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># general syntax for recode without passing to Enigma machine:</span></span>
|
||||
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="pp">[</span><span class="ss">options</span><span class="pp">]</span></span>
|
||||
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="co"># recode prompts for settings; pass to Enigma machine:</span></span>
|
||||
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="co"># recode reads from input file, prompts for settings; passed to Enigma machine:</span></span>
|
||||
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-finput</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="co"># recode reads config from string or file; passed to Enigma machine after</span></span>
|
||||
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> <span class="co"># prompting for input:</span></span>
|
||||
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-R</span><span class="op"><</span>string<span class="kw">|</span><span class="fu">file</span><span class="op">></span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="co"># write config to output file; passed to Enigma machine after prompting for</span></span>
|
||||
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> <span class="co"># input:</span></span>
|
||||
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-o</span><span class="op"><</span>config<span class="op">></span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a> <span class="co"># pseudo-randomly select settings</span></span>
|
||||
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-r</span></span>
|
||||
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a> <span class="co"># show Enigma machine settings after selection / generation:</span></span>
|
||||
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-v</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog
|
||||
|
||||
# get recode help:
|
||||
./recode -h
|
||||
|
||||
# general syntax for recode passing to Enigma machine:
|
||||
./recode [options] | ./prog - 2>/dev/null
|
||||
# general syntax for recode without passing to Enigma machine:
|
||||
./recode [options]
|
||||
|
||||
# recode prompts for settings; pass to Enigma machine:
|
||||
./recode | ./prog - 2>/dev/null
|
||||
|
||||
# recode reads from input file, prompts for settings; passed to Enigma machine:
|
||||
./recode -finput | ./prog - 2>/dev/null
|
||||
|
||||
# recode reads config from string or file; passed to Enigma machine after
|
||||
# prompting for input:
|
||||
./recode -R<string|file> | ./prog - 2>/dev/null
|
||||
|
||||
# write config to output file; passed to Enigma machine after prompting for
|
||||
# input:
|
||||
./recode -o<config> | ./prog - 2>/dev/null
|
||||
|
||||
# pseudo-randomly select settings
|
||||
./recode -r
|
||||
|
||||
# show Enigma machine settings after selection / generation:
|
||||
./recode -v</code></pre>
|
||||
<p><strong>NOTE</strong>: in <a href="recode.c">recode</a> no spaces between options and option arguments
|
||||
are allowed.</p>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<p>What does:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="kw">|</span> <span class="ex">./recode</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-v</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> echo | ./recode
|
||||
echo | ./recode -v</code></pre>
|
||||
<p>do?</p>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>This version, <a href="prog.alt.c">prog.alt.c</a>, writes a character at a time, sleeping
|
||||
after each character, so that one can read it more easily (for longer output)
|
||||
and to make it a bit more like the real thing.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<p>The default time to sleep is 400000 microseconds but you can change this by
|
||||
doing:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber SLEEP=600000 alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make clobber SLEEP=600000 alt</code></pre>
|
||||
<p>to change it to 600000 microseconds. It guards against negative numbers.</p>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
|
||||
<h3 id="alternate-try">Alternate try:</h3>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.alt.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.alt.sh</code></pre>
|
||||
<p>Notice how only the last part should use the <code>prog.alt</code>. Why? Try it and find
|
||||
out! Can you figure out why this works this way?</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
@@ -205,7 +205,7 @@ out! Can you figure out why this works this way?</p>
|
||||
<ul>
|
||||
<li><a href="enigma.1">enigma.1</a> - A useful man page for this entry. To render, try:</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./enigma.1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> man ./enigma.1</code></pre>
|
||||
<ul>
|
||||
<li><a href="recode.html">recode.html</a> (or <a href="recode.html">recode.html</a> if reading on GitHub)
|
||||
<ul>
|
||||
@@ -317,7 +317,7 @@ leave this in for historical purposes.</p>
|
||||
for input (end with EOF). At that point it’ll process the input string and print
|
||||
the result (after finishing the enciphering).</p>
|
||||
<p>If you run it like:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="at">-</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog -</code></pre>
|
||||
<p>It will prompt you for the settings of the machine (example below).</p>
|
||||
<p>The first group is in the order of
|
||||
<a href="https://www.ciphermachinesandcryptology.com/en/enigmatech.htm">rotor</a> (number),
|
||||
@@ -338,78 +338,78 @@ on GitHub see <a href="chocolate-cake.html">here</a>) though one might need a di
|
||||
of exercise after taking up the challenge! :-) These however show the general
|
||||
program as well as how to use the two winning entries of the <a href="https://en.wikipedia.org/wiki/Morse_code">Morse
|
||||
code</a> that I referred to earlier:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog <span class="at">-</span></span>
|
||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 1: 3</span>
|
||||
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 1: I</span>
|
||||
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">Position</span> 1: O</span>
|
||||
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 2: 1</span>
|
||||
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 2: C</span>
|
||||
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">Position</span> 2: C</span>
|
||||
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 3: 5</span>
|
||||
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 3: C</span>
|
||||
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">Position</span> 3: Z</span>
|
||||
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span> 2</span>
|
||||
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 1: CO</span>
|
||||
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 2: DE</span>
|
||||
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 3: SN</span>
|
||||
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 4: XY</span>
|
||||
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 5: MS</span>
|
||||
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 6: AT</span>
|
||||
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 7: VF</span>
|
||||
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 8: UR</span>
|
||||
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 9: KL</span>
|
||||
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 10: BJ</span>
|
||||
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a> <span class="ex">^D</span></span>
|
||||
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true" tabindex="-1"></a> <span class="ex">CFDRG</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog -
|
||||
Ring 1: 3
|
||||
Setting 1: I
|
||||
Position 1: O
|
||||
Ring 2: 1
|
||||
Setting 2: C
|
||||
Position 2: C
|
||||
Ring 3: 5
|
||||
Setting 3: C
|
||||
Position 3: Z
|
||||
Reflector: 2
|
||||
Plugboard pair 1: CO
|
||||
Plugboard pair 2: DE
|
||||
Plugboard pair 3: SN
|
||||
Plugboard pair 4: XY
|
||||
Plugboard pair 5: MS
|
||||
Plugboard pair 6: AT
|
||||
Plugboard pair 7: VF
|
||||
Plugboard pair 8: UR
|
||||
Plugboard pair 9: KL
|
||||
Plugboard pair 10: BJ
|
||||
IOCCC
|
||||
^D
|
||||
CFDRG</code></pre>
|
||||
<p>Notice that all output except the deciphered/enciphered text is sent to stdout.</p>
|
||||
<p>If I didn’t specify the <code>-</code> by e.g. <code>echo IOCCC | ./prog</code> then it will use the
|
||||
default settings; as the judges suggest this invocation I will not show it here.</p>
|
||||
<p>But you can also type it out like this:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog</span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">UUMMX</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog
|
||||
IOCCC
|
||||
UUMMX</code></pre>
|
||||
<p>The IOCCC comes from stdin; the <code>UUMMX</code> is written to stdout.</p>
|
||||
<p>If I compile the 2014 entry and copy it to my local directory as
|
||||
<code>vik</code> I might do:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo TEST<span class="kw">|</span><span class="ex">./prog</span> <span class="kw">|</span><span class="ex">./vik</span> <span class="kw">|</span> <span class="ex">mplayer</span> <span class="at">-demuxer</span> rawaudio <span class="at">-</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo TEST|./prog |./vik | mplayer -demuxer rawaudio -</code></pre>
|
||||
<p>And you would hear <a href="https://en.wikipedia.org/wiki/Morse_code">Morse code</a> of the
|
||||
<a href="https://www.ciphermachinesandcryptology.com/en/enigmatech.htm">Enigma</a> output
|
||||
of ‘TEST’ (i.e. <code>KCWV</code>)! Or perhaps not in this case. I’m not sure: I discovered
|
||||
a bug in that entry (Fedora, CentOS and macOS all affected).</p>
|
||||
<p>For example I can use the syntax provided in the winning remarks along with my
|
||||
entry to write it to a file. Say:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo TEST<span class="kw">|</span><span class="ex">./prog</span> <span class="kw">|</span><span class="ex">./vik</span> <span class="op">></span> test.raw</span>
|
||||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./vik e <span class="op"><</span> test.raw <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">LEST</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo TEST|./prog |./vik > test.raw
|
||||
$ ./vik e < test.raw | ./prog
|
||||
LEST</code></pre>
|
||||
<p>Why did that happen? This shows more details:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./vik e <span class="op"><</span> test.raw</span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">SCWV</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./vik e < test.raw
|
||||
SCWV</code></pre>
|
||||
<p>However as can be seen the first char is wrong:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo TEST<span class="kw">|</span><span class="ex">./prog</span></span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">KCWV</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo TEST|./prog
|
||||
KCWV</code></pre>
|
||||
<p>And piping the original output to my entry itself you get the original input:</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo TEST <span class="kw">|</span> <span class="ex">./prog</span> <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">TEST</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo TEST | ./prog | ./prog
|
||||
TEST</code></pre>
|
||||
<p>I’m not sure what causes that or if there’s a way to fix it but that’s the
|
||||
idea anyway. Neither do I know if the original transcoding is correct.</p>
|
||||
<p>What if I use the input string <code>LEST</code> instead? In that case it worked fine:</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo LEST <span class="kw">|</span> <span class="ex">./prog</span> <span class="kw">|</span> <span class="ex">./vik</span> <span class="op">></span> lest.raw</span>
|
||||
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./vik e <span class="op"><</span> lest.raw <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">LEST</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo LEST | ./prog | ./vik > lest.raw
|
||||
$ ./vik e < lest.raw | ./prog
|
||||
LEST</code></pre>
|
||||
<p>But there’s one obvious question, right? Let’s try the most important one:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo IOCCC <span class="kw">|</span> <span class="ex">./prog</span> <span class="kw">|</span> <span class="ex">./vik</span> <span class="op">></span> ioccc.raw</span>
|
||||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./vik e <span class="op"><</span> ioccc.raw</span>
|
||||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">UUMMX</span></span>
|
||||
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./vik e <span class="op"><</span> ioccc.raw <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo IOCCC | ./prog | ./vik > ioccc.raw
|
||||
$ ./vik e < ioccc.raw
|
||||
UUMMX
|
||||
$ ./vik e < ioccc.raw | ./prog
|
||||
IOCCC</code></pre>
|
||||
<p>Phew! The program redeemed itself after the test failure! :)</p>
|
||||
<p>(Technically above it didn’t print a newline after the output and this is how it
|
||||
is with some of the things I pasted in the other file and maybe others here
|
||||
too. Notice also how it showed the same output that my program gave it - <code>UUMMX</code>.)</p>
|
||||
<p>What about the other <a href="../../1998/dorssel/dorssel.c">Morse code entry</a>?</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo IOCCC <span class="kw">|</span> <span class="ex">./prog</span> <span class="kw">|</span> <span class="ex">./dorssel</span></span>
|
||||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">..-</span> ..- <span class="at">--</span> <span class="at">--</span> <span class="at">-..-</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo IOCCC | ./prog | ./dorssel
|
||||
..- ..- -- -- -..-</code></pre>
|
||||
<h3 id="the-recode.c-configurator"><a name="recode" href="#toc">The recode.c configurator</a></h3>
|
||||
<p>I have included a supplementary program <a href="recode.c">recode.c</a> that can do a number of
|
||||
things which acts as a kind of wrapper and configurator to my entry. By default
|
||||
@@ -440,26 +440,26 @@ make it more flexible by a wrapper program.</p>
|
||||
<p>The parser is in a sense rather rudimentary but allows for both interactive and
|
||||
automatic (e.g. via the <a href="recode.c">recode</a> program) input. This does mean that
|
||||
something like the following can happen:</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog <span class="at">-</span></span>
|
||||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 1: 1AB</span>
|
||||
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 1: Position 1: Ring 2: 2CD</span>
|
||||
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 2: Position 2: Ring 3: 3</span>
|
||||
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 3: A</span>
|
||||
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Position</span> 3: B</span>
|
||||
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span> 1A</span>
|
||||
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 1: BC</span>
|
||||
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 2: ..</span>
|
||||
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 3: ..</span>
|
||||
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 4: DE</span>
|
||||
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 5: FG</span>
|
||||
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 6: HI</span>
|
||||
<span id="cb20-14"><a href="#cb20-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 7: JK</span>
|
||||
<span id="cb20-15"><a href="#cb20-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 8: LM</span>
|
||||
<span id="cb20-16"><a href="#cb20-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 9: NO</span>
|
||||
<span id="cb20-17"><a href="#cb20-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair 10: PQ</span>
|
||||
<span id="cb20-18"><a href="#cb20-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb20-19"><a href="#cb20-19" aria-hidden="true" tabindex="-1"></a> <span class="ex">WD</span></span>
|
||||
<span id="cb20-20"><a href="#cb20-20" aria-hidden="true" tabindex="-1"></a> <span class="ex">SIRDK</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog -
|
||||
Ring 1: 1AB
|
||||
Setting 1: Position 1: Ring 2: 2CD
|
||||
Setting 2: Position 2: Ring 3: 3
|
||||
Setting 3: A
|
||||
Position 3: B
|
||||
Reflector: 1A
|
||||
Plugboard pair 1: BC
|
||||
Plugboard pair 2: ..
|
||||
Plugboard pair 3: ..
|
||||
Plugboard pair 4: DE
|
||||
Plugboard pair 5: FG
|
||||
Plugboard pair 6: HI
|
||||
Plugboard pair 7: JK
|
||||
Plugboard pair 8: LM
|
||||
Plugboard pair 9: NO
|
||||
Plugboard pair 10: PQ
|
||||
IOCCC
|
||||
WD
|
||||
SIRDK</code></pre>
|
||||
<p>First of all: what is that <code>WD</code>? I didn’t type that but it showed up hitting
|
||||
<code>ctrl-d</code> to end input.</p>
|
||||
<p>If everything is input correctly it would show nothing except the actual
|
||||
@@ -493,10 +493,10 @@ GitHub).</p>
|
||||
should help you remember (though not at this time in our world it might help you
|
||||
later on?). This might become even more useful after the challenge is accepted,
|
||||
accomplished and made use of! :)</p>
|
||||
<div class="sourceCode" id="cb21"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo ABC <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">GYM</span></span>
|
||||
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo ABC <span class="kw">|</span> <span class="ex">./prog</span> <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">ABC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo ABC | ./prog
|
||||
GYM
|
||||
$ echo ABC | ./prog | ./prog
|
||||
ABC</code></pre>
|
||||
<h3 id="on-the-source-code-layout"><a name="layout" href="#toc">On the source code layout</a></h3>
|
||||
<p>The layout of <a href="recode.c">recode.c</a> isn’t too significant (but see below) but I want to
|
||||
mention <a href="prog.c">prog.c</a> especially:</p>
|
||||
@@ -516,17 +516,17 @@ which was exactly 75 years from the day that the person responsible for the
|
||||
<a href="https://en.wikipedia.org/wiki/World_War_II">Second World War</a>, Adolf Hitler,
|
||||
ended his life. (I later made a bug fix but I consider this inconsequential).</p>
|
||||
<p>As for <a href="recode.c">recode.c</a> though I really love this:</p>
|
||||
<div class="sourceCode" id="cb22"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="op">/</span>\</span>
|
||||
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="op">/</span> This is <span class="op">*</span>not<span class="op">*</span> what you think<span class="op">:</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> /\
|
||||
/ This is *not* what you think:</code></pre>
|
||||
<p>…because it seems so wrong in C code at first glance. Also what does the
|
||||
‘this’ refer to?</p>
|
||||
<h3 id="obfuscation"><a name="obfuscation" href="#toc">Obfuscation</a></h3>
|
||||
<p>It’s an <a href="https://en.wikipedia.org/wiki/Enigma_machine">Enigma machine</a> simulator! Isn’t
|
||||
that proof that it’s obfuscated itself?! :) Silliness aside <a href="obfuscation.txt">obfuscation.txt</a>
|
||||
has some of the ways I think this entry is obfuscated. To decipher try:</p>
|
||||
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-Robfuscation.key</span> <span class="at">-fobfuscation.txt</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> obfuscation.md</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./recode -Robfuscation.key -fobfuscation.txt | ./prog - 2>/dev/null > obfuscation.md</code></pre>
|
||||
<p>To encipher:</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-Robfuscation.key</span> <span class="at">-fobfuscation.md</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> obfuscation.txt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./recode -Robfuscation.key -fobfuscation.md | ./prog - 2>/dev/null > obfuscation.txt</code></pre>
|
||||
<p>The file <a href="obfuscation.key">obfuscation.key</a> is the key to decipher/encipher
|
||||
<a href="obfuscation.txt">obfuscation.txt</a>.</p>
|
||||
<p>For the lazy <a href="obfuscation.html">obfuscation.html</a> has the deciphered version. I am afraid I’m not
|
||||
|
||||
@@ -140,41 +140,41 @@ there is an aesthetic appeal to my eyes too).</p></li>
|
||||
Y<:19:><:27:> but it’s not the only example. Here the compound literal of 13
|
||||
ints:</p></li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> <span class="op">*</span>z<span class="op">=(</span><span class="dt">int</span><span class="op">[</span><span class="dv">13</span><span class="op">])</span> <span class="op">{</span> <span class="dv">0</span> <span class="op">}</span> <span class="op">,</span> <span class="op">*</span>e<span class="op">,</span> <span class="op">*</span>g<span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> int *z=(int[13]) { 0 } , *e, *g;</code></pre>
|
||||
<p>Then in main:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> e <span class="op">=</span> z <span class="op">+</span> <span class="dv">10</span><span class="op">;</span></span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> g <span class="op">=</span> e <span class="op">+</span> <span class="dv">1</span><span class="op">;</span></span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> <span class="op">(</span>j<span class="op">=-</span><span class="dv">3</span><span class="op">;</span> j <span class="op"><</span> <span class="dv">0</span><span class="op">;</span> <span class="op">++</span>j<span class="op">)</span></span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> e<span class="op"><:</span>j<span class="op">:></span> <span class="op">=</span> j<span class="op">+</span><span class="dv">3</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> e = z + 10;
|
||||
g = e + 1;
|
||||
|
||||
for (j=-3; j < 0; ++j)
|
||||
e<:j:> = j+3;</code></pre>
|
||||
<p>Which I think is more confusing: when one is iterating an array you don’t
|
||||
expect to start out with index < 0 but to then compare that that index < 0
|
||||
and increment until 0 along with setting the value of the array to j + 3 is
|
||||
more confusing still. There are at least two other ways that are much easier
|
||||
to read that could accomplish the same thing. It continues on:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co">/* ... */</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> e<span class="op"><:</span>i<span class="op">-</span><span class="dv">3</span><span class="op">:></span> <span class="op">=</span> <span class="op">(</span>j <span class="op"><</span> <span class="dv">1</span> <span class="op">?</span> <span class="dv">1</span> <span class="op">:</span> <span class="op">(</span>j <span class="op">></span> <span class="dv">5</span> <span class="op">?</span> <span class="dv">5</span> <span class="op">:</span> j<span class="op">))-</span><span class="dv">1</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> /* ... */
|
||||
e<:i-3:> = (j < 1 ? 1 : (j > 5 ? 5 : j))-1;</code></pre>
|
||||
<ul>
|
||||
<li>Observe these two functions:</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">void</span> w<span class="op">(</span><span class="dt">char</span> <span class="op">*</span>s<span class="op">,</span> <span class="dt">int</span> k<span class="op">,</span> <span class="dt">int</span> v<span class="op">)</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span><span class="op">(</span>e<span class="op"><:</span><span class="dv">2</span><span class="op">:></span> <span class="op">=</span> <span class="dv">0</span><span class="op">;</span> s<span class="op"><:*</span>P<span class="op">:>;</span> <span class="op">++</span>e<span class="op"><:</span><span class="dv">2</span><span class="op">:>)</span></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> v <span class="op">=</span> s<span class="op"><:</span>e<span class="op"><:</span><span class="dv">2</span><span class="op">:>:>;</span></span>
|
||||
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span><span class="op">(</span>v <span class="op">></span> <span class="dv">64</span> <span class="op">&&</span> v <span class="op"><</span> <span class="dv">91</span><span class="op">)</span></span>
|
||||
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> s<span class="op"><:</span>e<span class="op"><:</span><span class="dv">2</span><span class="op">:>:></span> <span class="op">=</span> <span class="op">(((</span>v <span class="op">-</span> <span class="dv">65</span> <span class="op">+</span> k<span class="op">)</span> <span class="op">%</span> <span class="dv">26</span><span class="op">)</span> <span class="op">+</span> <span class="dv">65</span><span class="op">);</span></span>
|
||||
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> <span class="dt">void</span> Q<span class="op">(</span><span class="dt">void</span><span class="op">)</span></span>
|
||||
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span><span class="op">(*</span>g <span class="op">=</span> <span class="dv">0</span><span class="op">;</span> <span class="op">*</span>g <span class="op"><</span> <span class="dv">3</span><span class="op">;</span> <span class="op">++*</span>g<span class="op">)</span></span>
|
||||
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span>Y<span class="op"><:</span><span class="dv">16</span><span class="op">+</span>e<span class="op"><:</span><span class="dv">1</span><span class="op">:>:>=</span>S<span class="op"><:</span>e<span class="op"><:</span>e<span class="op"><:</span><span class="dv">1</span><span class="op">:>-</span><span class="dv">3</span><span class="op">:>:>;</span></span>
|
||||
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> R<span class="op"><:</span>e<span class="op"><:</span><span class="dv">1</span><span class="op">:>:>=</span>Y<span class="op"><:</span>e<span class="op"><:-</span><span class="dv">3</span><span class="op">+</span>e<span class="op"><:</span><span class="dv">1</span><span class="op">:>:>:>;</span></span>
|
||||
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a> w<span class="op">(</span>R<span class="op">[*</span>g<span class="op">],*(</span>e<span class="op">+</span>e<span class="op"><:</span><span class="dv">1</span><span class="op">:>-</span><span class="dv">6</span><span class="op">)=</span>q<span class="op">(</span>Y<span class="op"><:</span><span class="dv">8</span><span class="op">:>,*</span>Y<span class="op"><:</span><span class="dv">7</span><span class="op">:>),*</span>g<span class="op">);</span></span>
|
||||
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> void w(char *s, int k, int v)
|
||||
{
|
||||
for(e<:2:> = 0; s<:*P:>; ++e<:2:>)
|
||||
{
|
||||
v = s<:e<:2:>:>;
|
||||
if(v > 64 && v < 91)
|
||||
s<:e<:2:>:> = (((v - 65 + k) % 26) + 65);
|
||||
}
|
||||
}
|
||||
void Q(void)
|
||||
{
|
||||
for(*g = 0; *g < 3; ++*g)
|
||||
{
|
||||
*Y<:16+e<:1:>:>=S<:e<:e<:1:>-3:>:>;
|
||||
R<:e<:1:>:>=Y<:e<:-3+e<:1:>:>:>;
|
||||
w(R[*g],*(e+e<:1:>-6)=q(Y<:8:>,*Y<:7:>),*g);
|
||||
}
|
||||
}</code></pre>
|
||||
<p>First of all: why do I set <code>e[2]</code> to 0 and increment it for each pass in the
|
||||
loop, but then the condition for the loop is <code>s[*P]</code>?</p>
|
||||
<p>Second notice the many references to e[1] (as e[1] and <em>g). This variable (pointing
|
||||
@@ -200,14 +200,14 @@ temporary variable instead of a regular int in the function (so make it global);
|
||||
and (2) I didn’t want to risk changing all the offsets: thus I just made that
|
||||
address <code>e[1]</code>. Thus I also have:</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> <span class="op">(*</span>g <span class="op">=</span> <span class="dv">0</span> <span class="op">;</span> <span class="op">*</span>g <span class="op"><</span> <span class="dv">10</span><span class="op">;</span> <span class="op">++*</span>g<span class="op">)</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> r<span class="op"><:-</span><span class="dv">2</span><span class="op">:></span> <span class="op">=</span> Y<span class="op"><:</span><span class="dv">14</span><span class="op">:><:*(</span>e<span class="op">+</span><span class="dv">1</span><span class="op">):>;</span> r<span class="op"><:-</span><span class="dv">3</span><span class="op">:></span> <span class="op">=</span> Y<span class="op"><:</span><span class="dv">15</span><span class="op">:><:</span><span class="dv">1</span><span class="op"><:</span>e<span class="op">:>:>;</span></span>
|
||||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>r<span class="op"><:-</span><span class="dv">3</span><span class="op">:></span> <span class="op">&&</span> r<span class="op"><:-</span><span class="dv">2</span><span class="op">:></span> <span class="op">==</span> r<span class="op"><:-</span><span class="dv">1</span><span class="op">:>)</span></span>
|
||||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> r<span class="op"><:-</span><span class="dv">3</span><span class="op">:>;</span></span>
|
||||
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>r<span class="op"><:-</span><span class="dv">2</span><span class="op">:></span> <span class="op">&&</span> r<span class="op"><:-</span><span class="dv">3</span><span class="op">:></span> <span class="op">==</span> r<span class="op"><:-</span><span class="dv">1</span><span class="op">:>)</span></span>
|
||||
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> r<span class="op"><:-</span><span class="dv">2</span><span class="op">:>;</span></span>
|
||||
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> for (*g = 0 ; *g < 10; ++*g)
|
||||
{
|
||||
r<:-2:> = Y<:14:><:*(e+1):>; r<:-3:> = Y<:15:><:1<:e:>:>;
|
||||
if (r<:-3:> && r<:-2:> == r<:-1:>)
|
||||
return r<:-3:>;
|
||||
if (r<:-2:> && r<:-3:> == r<:-1:>)
|
||||
return r<:-2:>;
|
||||
}</code></pre>
|
||||
<p>This <code>e[1]</code> of course is the same as <code>*g</code> as above and as you can see has
|
||||
multiple dimensions (that is the reference to Y does) too (and this is also
|
||||
strewn about the code). In the above I’m referring to the variable in more
|
||||
@@ -218,7 +218,7 @@ which I use as the two chars to compare (this is the plugboard function).</p>
|
||||
<li>The above function Z() takes a <code>char x</code> but you won’t notice it being used
|
||||
at all. Why? In fact I call it like so:</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> k <span class="op">=</span> Z<span class="op">(</span>r<span class="op"><:-</span><span class="dv">1</span><span class="op">:>=</span>k<span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> k = Z(r<:-1:>=k);</code></pre>
|
||||
<p>The char is just used as a way to be able to call the function and assign to
|
||||
the proper variable at the same time: in the function Z I don’t care about x
|
||||
because it’s the same value as r[-1] (which I do care about). Why is it
|
||||
@@ -230,7 +230,7 @@ again negative offsets to cause more confusion.</p>
|
||||
refer to the same variable in more than one way (or in some cases maybe more
|
||||
correct to say ‘same location’). In the Z() function for example:</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> r<span class="op"><:-</span><span class="dv">2</span><span class="op">:></span> <span class="op">=</span> Y<span class="op"><:</span><span class="dv">14</span><span class="op">:><:*(</span>e<span class="op">+</span><span class="dv">1</span><span class="op">):>;</span> r<span class="op"><:-</span><span class="dv">3</span><span class="op">:></span> <span class="op">=</span> Y<span class="op"><:</span><span class="dv">15</span><span class="op">:><:</span><span class="dv">1</span><span class="op"><:</span>e<span class="op">:>:>;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> r<:-2:> = Y<:14:><:*(e+1):>; r<:-3:> = Y<:15:><:1<:e:>:>;</code></pre>
|
||||
<p>I refer to e[1] as both: *(e+1) and 1[e].</p>
|
||||
<ul>
|
||||
<li><p>Replacing a number of <code>if ..</code>s with <code>... && (...)</code>s (in one case at least
|
||||
@@ -245,7 +245,7 @@ index (sort of).</p></li>
|
||||
<li><p>Another set of char arrays in one: the five rotors as well as the two
|
||||
reflectors in one <code>char [][27]</code>. This makes for some fun code like:</p></li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>Y<span class="op"><:</span>e<span class="op"><:-</span><span class="dv">10</span><span class="op">:>+</span><span class="dv">5</span><span class="op">:><:</span>k<span class="op">-</span><span class="ch">'A'</span><span class="op">:>)</span> <span class="op">&&</span> <span class="op">(</span>k <span class="op">=</span> Y<span class="op"><:</span>e<span class="op"><:-</span><span class="dv">10</span><span class="op">:>+</span><span class="dv">5</span><span class="op">:><:</span>k<span class="op">-</span><span class="ch">'A'</span><span class="op">:>);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> (Y<:e<:-10:>+5:><:k-'A':>) && (k = Y<:e<:-10:>+5:><:k-'A':>);</code></pre>
|
||||
<p>(Of course this also removes an if statement by joining with a &&).</p>
|
||||
<ul>
|
||||
<li><p>In fact I decided that the above two arrays in arrays needed to be merged
|
||||
@@ -275,18 +275,18 @@ enough because as they rightly point out they can just use the C preprocessor
|
||||
itself. But although I have quite a few cpp directives I am not using them for
|
||||
obfuscation but rather to save bytes. For examples:</p></li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">%:define J</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> </span><span class="cf">do</span><span class="op">(*</span><span class="pp">x</span><span class="op">)=</span><span class="pp">getchar</span><span class="op">();</span><span class="pp"> </span><span class="cf">while</span><span class="op">((*</span><span class="pp">x</span><span class="op">)==</span><span class="ch">'</span><span class="sc">\n</span><span class="ch">'</span><span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> %:define J(x) do(*x)=getchar(); while((*x)=='\n')</code></pre>
|
||||
<p>Is used quite a number of times and although it could be a function that
|
||||
takes a pointer to an int it was more convenient this way (I believe it used
|
||||
more bytes but I no longer know that). There are many others and they all
|
||||
save bytes (or at least most of them do if not all). There is one in
|
||||
particular I want to bring up though because I think it’s a curious one and
|
||||
it ties in to another point above:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">%:define A</span><span class="op">(</span><span class="pp">y</span><span class="op">)</span><span class="pp"> </span><span class="op">*(&</span><span class="pp">Y</span><span class="op"><:</span><span class="dv">7</span><span class="op">:><:</span><span class="dv">1</span><span class="op">:>+(</span><span class="pp">y</span><span class="op">))</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> %:define A(y) *(&Y<:7:><:1:>+(y))</code></pre>
|
||||
<p>What is special about this one: Above I noted how I sort of refer directly
|
||||
to the notch settings (I think it was the notch settings anyway). Now I
|
||||
could have done say</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> a <span class="op">=</span> Y<span class="op">[</span><span class="dv">7</span><span class="op">][</span><span class="dv">1</span><span class="op">],</span> b <span class="op">=</span> Y<span class="op">[</span><span class="dv">7</span><span class="op">][</span><span class="dv">3</span><span class="op">],</span> c <span class="op">=</span> Y<span class="op">[</span><span class="dv">7</span><span class="op">][</span><span class="dv">5</span><span class="op">];</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> char a = Y[7][1], b = Y[7][3], c = Y[7][5];</code></pre>
|
||||
<p>But I felt that doing instead the pointer arithmetic was worth doing.
|
||||
However it used significantly more bytes even as a macro: 17 if I recall
|
||||
right. That’s with the macro. If I were to include it three times by itself
|
||||
@@ -314,9 +314,9 @@ differently (and separated) so that one cannot easily replace the <code>char</co
|
||||
variables in recode.c, move them to prog.c, compile and expect it to work right.</p></li>
|
||||
<li><p>Also what is this about ?</p></li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="op">/</span>\</span>
|
||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="op">/</span> This is <span class="op">*</span>not<span class="op">*</span> what you think<span class="op">:</span></span>
|
||||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">void</span> D<span class="op">(</span><span class="dt">char</span><span class="op">*</span>x<span class="op">){</span> <span class="co">/* ... */</span> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> /\
|
||||
/ This is *not* what you think:
|
||||
void D(char*x){ /* ... */ }</code></pre>
|
||||
<p>Is that valid and if so how does it function? Yes it’s valid but I’ll leave
|
||||
the other part of the question up to the reader to answer. Hint: you already
|
||||
know how it works (yes, really you do)! Another hint: This is and is not a
|
||||
|
||||
@@ -19,13 +19,13 @@ there is an aesthetic appeal to my eyes too).
|
||||
Y<:19:><:27:> but it's not the only example. Here the compound literal of 13
|
||||
ints:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
int *z=(int[13]) { 0 } , *e, *g;
|
||||
```
|
||||
|
||||
Then in main:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
e = z + 10;
|
||||
g = e + 1;
|
||||
|
||||
@@ -39,14 +39,14 @@ ints:
|
||||
more confusing still. There are at least two other ways that are much easier
|
||||
to read that could accomplish the same thing. It continues on:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
/* ... */
|
||||
e<:i-3:> = (j < 1 ? 1 : (j > 5 ? 5 : j))-1;
|
||||
```
|
||||
|
||||
* Observe these two functions:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
void w(char *s, int k, int v)
|
||||
{
|
||||
for(e<:2:> = 0; s<:*P:>; ++e<:2:>)
|
||||
@@ -96,7 +96,7 @@ temporary variable instead of a regular int in the function (so make it global);
|
||||
and (2) I didn't want to risk changing all the offsets: thus I just made that
|
||||
address `e[1]`. Thus I also have:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
for (*g = 0 ; *g < 10; ++*g)
|
||||
{
|
||||
r<:-2:> = Y<:14:><:*(e+1):>; r<:-3:> = Y<:15:><:1<:e:>:>;
|
||||
@@ -117,7 +117,7 @@ address `e[1]`. Thus I also have:
|
||||
* The above function Z() takes a `char x` but you won't notice it being used
|
||||
at all. Why? In fact I call it like so:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
k = Z(r<:-1:>=k);
|
||||
```
|
||||
|
||||
@@ -132,7 +132,7 @@ at all. Why? In fact I call it like so:
|
||||
refer to the same variable in more than one way (or in some cases maybe more
|
||||
correct to say 'same location'). In the Z() function for example:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
r<:-2:> = Y<:14:><:*(e+1):>; r<:-3:> = Y<:15:><:1<:e:>:>;
|
||||
```
|
||||
|
||||
@@ -153,7 +153,7 @@ index (sort of).
|
||||
* Another set of char arrays in one: the five rotors as well as the two
|
||||
reflectors in one `char [][27]`. This makes for some fun code like:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
(Y<:e<:-10:>+5:><:k-'A':>) && (k = Y<:e<:-10:>+5:><:k-'A':>);
|
||||
```
|
||||
|
||||
@@ -194,7 +194,7 @@ enough because as they rightly point out they can just use the C preprocessor
|
||||
itself. But although I have quite a few cpp directives I am not using them for
|
||||
obfuscation but rather to save bytes. For examples:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
%:define J(x) do(*x)=getchar(); while((*x)=='\n')
|
||||
```
|
||||
|
||||
@@ -205,7 +205,7 @@ obfuscation but rather to save bytes. For examples:
|
||||
particular I want to bring up though because I think it's a curious one and
|
||||
it ties in to another point above:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
%:define A(y) *(&Y<:7:><:1:>+(y))
|
||||
```
|
||||
|
||||
@@ -213,7 +213,7 @@ obfuscation but rather to save bytes. For examples:
|
||||
to the notch settings (I think it was the notch settings anyway). Now I
|
||||
could have done say
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
char a = Y[7][1], b = Y[7][3], c = Y[7][5];
|
||||
```
|
||||
|
||||
@@ -248,7 +248,7 @@ variables in recode.c, move them to prog.c, compile and expect it to work right.
|
||||
|
||||
* Also what is this about ?
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
/\
|
||||
/ This is *not* what you think:
|
||||
void D(char*x){ /* ... */ }
|
||||
|
||||
+194
-194
@@ -170,34 +170,34 @@ with the Roman numeral, showing their actual orders etc.), the reflectors
|
||||
<p>In this file I will show an example of each feature and then get to the
|
||||
wonderful ‘challenge’ for everyone.</p>
|
||||
<h1 id="options"><a name="options" href="#toc">Options</a></h1>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-h</span></span>
|
||||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">usage:</span> ./recode <span class="pp">[</span><span class="ss">options</span><span class="pp">]</span></span>
|
||||
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">-v</span> display selected settings</span>
|
||||
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">-r</span> pseudo-randomly select settings</span>
|
||||
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">-f</span><span class="op"><</span>input file<span class="op">></span> read file for Enigma input</span>
|
||||
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">-R</span><span class="op"><</span>string<span class="kw">|</span><span class="fu">file</span><span class="op">></span> init settings from settings string or file</span>
|
||||
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">-o</span><span class="op"><</span>output file<span class="op">></span> write settings to file</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./recode -h
|
||||
usage: ./recode [options]
|
||||
-v display selected settings
|
||||
-r pseudo-randomly select settings
|
||||
-f<input file> read file for Enigma input
|
||||
-R<string|file> init settings from settings string or file
|
||||
-o<output file> write settings to file</code></pre>
|
||||
<p><code>-r</code> randomises settings. It won’t prompt you for settings but it will for input
|
||||
if you don’t give the option to read in a file for input.</p>
|
||||
<p><code>-v</code> shows selected settings. For example combining <code>-r</code> and <code>-v</code>:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo IOCCC <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-r</span> <span class="at">-v</span></span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 1: <span class="er">(</span> <span class="ex">I</span><span class="kw">)</span> <span class="ex">EKMFLGDQVZNTOWYHXUSPAIBRCJ</span></span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 2: <span class="er">(</span> <span class="ex">V</span><span class="kw">)</span> <span class="ex">VZBRGITYUPSDNHLXAWMJQOFECK</span></span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 3: <span class="er">(</span> <span class="ex">IV</span><span class="kw">)</span> <span class="ex">ESOVPZJAYQUIRHXLNFTGKDCMWB</span></span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> settings: WAR</span>
|
||||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> positions: XKE</span>
|
||||
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span> <span class="er">(</span><span class="ex">B</span><span class="kw">)</span> <span class="ex">YRUHQSLDPXNGOKMIEBFZCWVJAT</span></span>
|
||||
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#01: XE</span></span>
|
||||
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#02: HJ</span></span>
|
||||
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#03: SA</span></span>
|
||||
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#04: PY</span></span>
|
||||
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#05: CI</span></span>
|
||||
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#06: ZB</span></span>
|
||||
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#07: WD</span></span>
|
||||
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#08: QN</span></span>
|
||||
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#09: RU</span></span>
|
||||
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#10: VG</span></span>
|
||||
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">1WX5AK4RE1XEHJSAPYCIZBWDQNRUVGIOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo IOCCC | ./recode -r -v
|
||||
Ring 1: ( I) EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
Ring 2: ( V) VZBRGITYUPSDNHLXAWMJQOFECK
|
||||
Ring 3: ( IV) ESOVPZJAYQUIRHXLNFTGKDCMWB
|
||||
Ring settings: WAR
|
||||
Ring positions: XKE
|
||||
Reflector: (B) YRUHQSLDPXNGOKMIEBFZCWVJAT
|
||||
Plugboard pair #01: XE
|
||||
Plugboard pair #02: HJ
|
||||
Plugboard pair #03: SA
|
||||
Plugboard pair #04: PY
|
||||
Plugboard pair #05: CI
|
||||
Plugboard pair #06: ZB
|
||||
Plugboard pair #07: WD
|
||||
Plugboard pair #08: QN
|
||||
Plugboard pair #09: RU
|
||||
Plugboard pair #10: VG
|
||||
1WX5AK4RE1XEHJSAPYCIZBWDQNRUVGIOCCC</code></pre>
|
||||
<p>Though you won’t find some of those strings in <a href="recode.c">recode.c</a> or
|
||||
<a href="prog.c">prog.c</a>. Yes the <code>WAR</code> for the Ringstellung (Ring settings) is an
|
||||
amusing coincidence <em>but it really did happen!</em></p>
|
||||
@@ -207,11 +207,11 @@ encipherment/decipherment). If the file cannot be opened it sets back to stdin.<
|
||||
<p><code>-o</code> outputs the settings to the file. If the file cannot be opened for writing
|
||||
or is the same file name (see below) then only stdout will be used. Example of
|
||||
randomised output going to a file:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-r</span> <span class="at">-oconfig</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">3PP4UB5GG1ELGTKFCOPVBNUYXJAWSDIOCCC</span></span>
|
||||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat config</span>
|
||||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">3PP4UB5GG1ELGTKFCOPVBNUYXJAWSD$</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -r -oconfig
|
||||
IOCCC
|
||||
3PP4UB5GG1ELGTKFCOPVBNUYXJAWSDIOCCC
|
||||
$ cat config
|
||||
3PP4UB5GG1ELGTKFCOPVBNUYXJAWSD$</code></pre>
|
||||
<p>Notice that a terminating newline isn’t added. Also note that it outputs to
|
||||
stdout so you can pipe it to the Enigma machine but at the same time have the
|
||||
settings saved for deciphering the text later (the configuration does not have
|
||||
@@ -236,7 +236,7 @@ what about if one exists but the other does not?</p>
|
||||
<h2 id="file-options-parser-limitation"><a name="fileoptions" href="#toc">File options parser limitation</a></h2>
|
||||
<p>Due to the way the parsing of options is done (no spaces between option char and
|
||||
argument) shell expansion will not work right so for example doing:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-R~</span>/config</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -R~/config</code></pre>
|
||||
<p>will <em>not</em> read the file ‘config’ in the home directory. I show another way to
|
||||
achieve this later.</p>
|
||||
<p>This limitation also applies to the <code>-f</code> and <code>-o</code> options!</p>
|
||||
@@ -246,17 +246,17 @@ the program interactively.</p>
|
||||
<h1 id="piping-commands-to-recode"><a name="pipingtorecode" href="#toc">Piping commands to recode</a></h1>
|
||||
<p>If stdin is not a tty (<code>!isatty(0)</code>) and neither randomised mode nor reading in
|
||||
from a file is specified then you might just see something like:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo testing test tests <span class="kw">|</span> <span class="ex">./recode</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">1AB2BB3CC1testing</span> test tests</span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo testing test tests <span class="kw">|</span> <span class="ex">./recode</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">mfrwxan</span> lzng ofnlu</span>
|
||||
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo testing test tests <span class="kw">|</span> <span class="ex">./recode</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="ex">./recode</span></span>
|
||||
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">1AB2BB3CC1mfrwxan</span> lzng ofnlu</span>
|
||||
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo testing test tests <span class="kw">|</span> <span class="ex">./recode</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="ex">./recode</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">testing</span> test tests</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo testing test tests | ./recode
|
||||
1AB2BB3CC1testing test tests
|
||||
|
||||
$ echo testing test tests | ./recode | ./prog - 2>/dev/null
|
||||
mfrwxan lzng ofnlu
|
||||
|
||||
$ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode
|
||||
1AB2BB3CC1mfrwxan lzng ofnlu
|
||||
|
||||
$ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode | ./prog - 2>/dev/null
|
||||
testing test tests</code></pre>
|
||||
<p>In other words just the defaults. This was to simplify the problems with
|
||||
prompting again for input if it’s invalid (though as you’ll see it does a good
|
||||
job at this anyway).</p>
|
||||
@@ -265,59 +265,59 @@ job at this anyway).</p>
|
||||
input manually (if you randomise or read in from previously saved file no input
|
||||
need be done at all) then make sure to redirect stderr to /dev/null. If you
|
||||
don’t you might see something like:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-r</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span></span>
|
||||
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 1: IOCCC</span>
|
||||
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">Setting</span> 1: Position 1: Ring 2: Setting 2: Position 2: Ring 3: Setting 3: Position 3: Reflector: Plugboard pair 1: Plugboard pair 2: Plugboard pair 3: Plugboard pair 4: Plugboard pair 5: Plugboard pair 6: Plugboard pair 7: Plugboard pair 8: Plugboard pair 9: Plugboard pair 10: DEVIY</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -r | ./prog -
|
||||
Ring 1: IOCCC
|
||||
Setting 1: Position 1: Ring 2: Setting 2: Position 2: Ring 3: Setting 3: Position 3: Reflector: Plugboard pair 1: Plugboard pair 2: Plugboard pair 3: Plugboard pair 4: Plugboard pair 5: Plugboard pair 6: Plugboard pair 7: Plugboard pair 8: Plugboard pair 9: Plugboard pair 10: DEVIY</code></pre>
|
||||
<p>What happened is that <code>Ring 1:</code> is printed to stderr but since it’s not been
|
||||
redirected to <code>/dev/null</code> it prints this out; at this point however it prompts for
|
||||
input. Why or how it shows the first prompt instead of later on I do not know.
|
||||
Anyway at this point the simulator is already expecting input to en/decipher.
|
||||
That’s why after I sent EOF it printed out the remaining strings to stderr.</p>
|
||||
<h1 id="manually-test-the-recode-program-with-the-enigma-program"><a name="manuallytest" href="#toc">Manually test the recode program with the Enigma program</a></h1>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat input</span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-finput</span></span>
|
||||
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">Rotors:</span></span>
|
||||
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">1</span><span class="kw">)</span> <span class="ex">I:</span> EKMFLGDQVZNTOWYHXUSPAIBRCJ</span>
|
||||
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">2</span><span class="kw">)</span> <span class="ex">II:</span> AJDKSIRUXBLHWTMCQGZNPYFVOE</span>
|
||||
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">3</span><span class="kw">)</span> <span class="ex">III:</span> BDFHJLCPRTXVZNYEIWGAKMUSQO</span>
|
||||
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">4</span><span class="kw">)</span> <span class="ex">IV:</span> ESOVPZJAYQUIRHXLNFTGKDCMWB</span>
|
||||
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">5</span><span class="kw">)</span> <span class="ex">V:</span> VZBRGITYUPSDNHLXAWMJQOFECK</span>
|
||||
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 1 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 1</span>
|
||||
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 2 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 2</span>
|
||||
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 3 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 3</span>
|
||||
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 1 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 2 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 3 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 1 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 2 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 3 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span></span>
|
||||
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">1</span><span class="kw">)</span> <span class="kw">(</span><span class="ex">B</span><span class="kw">)</span> <span class="ex">YRUHQSLDPXNGOKMIEBFZCWVJAT</span></span>
|
||||
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">2</span><span class="kw">)</span> <span class="kw">(</span><span class="ex">C</span><span class="kw">)</span> <span class="ex">FVPJIAOYEDRZXWGCTKUQSBNMHL</span></span>
|
||||
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> reflector <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 2<span class="kw">)</span><span class="bu">:</span> 2</span>
|
||||
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 1: AB</span>
|
||||
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 2: CD</span>
|
||||
<span id="cb7-26"><a href="#cb7-26" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 3: ..</span>
|
||||
<span id="cb7-27"><a href="#cb7-27" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 4: EF</span>
|
||||
<span id="cb7-28"><a href="#cb7-28" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 5: GH</span>
|
||||
<span id="cb7-29"><a href="#cb7-29" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 6: IJ</span>
|
||||
<span id="cb7-30"><a href="#cb7-30" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 7: KL</span>
|
||||
<span id="cb7-31"><a href="#cb7-31" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 8: MN</span>
|
||||
<span id="cb7-32"><a href="#cb7-32" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 9: OP</span>
|
||||
<span id="cb7-33"><a href="#cb7-33" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 10: QR</span>
|
||||
<span id="cb7-34"><a href="#cb7-34" aria-hidden="true" tabindex="-1"></a> <span class="ex">1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ cat input
|
||||
IOCCC
|
||||
|
||||
$ ./recode -finput
|
||||
Rotors:
|
||||
(1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
(2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE
|
||||
(3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO
|
||||
(4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB
|
||||
(5) V: VZBRGITYUPSDNHLXAWMJQOFECK
|
||||
Input rotor 1 (1 - 5): 1
|
||||
Input rotor 2 (1 - 5): 2
|
||||
Input rotor 3 (1 - 5): 3
|
||||
Input setting 1 (A - Z): A
|
||||
Input setting 2 (A - Z): A
|
||||
Input setting 3 (A - Z): A
|
||||
Input position 1 (A - Z): A
|
||||
Input position 2 (A - Z): A
|
||||
Input position 3 (A - Z): A
|
||||
Reflector:
|
||||
(1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT
|
||||
(2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL
|
||||
Input reflector (1 - 2): 2
|
||||
Input plugboard pair 1: AB
|
||||
Input plugboard pair 2: CD
|
||||
Input plugboard pair 3: ..
|
||||
Input plugboard pair 4: EF
|
||||
Input plugboard pair 5: GH
|
||||
Input plugboard pair 6: IJ
|
||||
Input plugboard pair 7: KL
|
||||
Input plugboard pair 8: MN
|
||||
Input plugboard pair 9: OP
|
||||
Input plugboard pair 10: QR
|
||||
1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC</code></pre>
|
||||
<p>Notice that I skipped a <a href="https://www.cryptomuseum.com/crypto/enigma/i/sb.htm">plugboard
|
||||
pair</a>; this can be done in
|
||||
a number of ways but two dots is one. Notice also that it’s in a different order
|
||||
than the simulator: because with the size restrictions on my entry I saved bytes
|
||||
by using the same loop where I could. It just felt more natural to have them
|
||||
grouped together in a configurator for the <a href="prog.c">simulator</a>.</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">HQNVO</span></span>
|
||||
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="bu">echo</span> 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null
|
||||
HQNVO
|
||||
$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null | echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO | ./prog - 2>/dev/null
|
||||
IOCCC</code></pre>
|
||||
<p>As you can see the <code>recode</code> program prompts for the settings and outputs the
|
||||
input for the Enigma program. I then copied/pasted that output to the program
|
||||
and got the result <code>HQNVO</code>.</p>
|
||||
@@ -330,58 +330,58 @@ part again; I could have just done the latter part but I wanted to show the way
|
||||
the pipeline works with settings etc.</p>
|
||||
<p>What happens if the plugboard pairs are the same but in a different order? It’s
|
||||
the same output:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo 1AA2AA3AA2AB..CDEFGHIJKLMNOPQRIOCCC<span class="kw">|</span><span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">HQNVO</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo 1AA2AA3AA2AB..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null
|
||||
HQNVO</code></pre>
|
||||
<p>Also if you flip the order of the letters in the pair e.g. the AB as BA instead:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC<span class="kw">|</span><span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">HQNVO</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null
|
||||
HQNVO</code></pre>
|
||||
<h1 id="only-write-config-file"><a name="onlyconfig" href="#toc">Only write config file</a></h1>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-v</span> <span class="at">-oconfig</span> <span class="at">-finput</span> <span class="op">></span>/dev/null</span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Rotors:</span></span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">1</span><span class="kw">)</span> <span class="ex">I:</span> EKMFLGDQVZNTOWYHXUSPAIBRCJ</span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">2</span><span class="kw">)</span> <span class="ex">II:</span> AJDKSIRUXBLHWTMCQGZNPYFVOE</span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">3</span><span class="kw">)</span> <span class="ex">III:</span> BDFHJLCPRTXVZNYEIWGAKMUSQO</span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">4</span><span class="kw">)</span> <span class="ex">IV:</span> ESOVPZJAYQUIRHXLNFTGKDCMWB</span>
|
||||
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">5</span><span class="kw">)</span> <span class="ex">V:</span> VZBRGITYUPSDNHLXAWMJQOFECK</span>
|
||||
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 1 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 1</span>
|
||||
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 2 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 2</span>
|
||||
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> rotor 3 <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 5<span class="kw">)</span><span class="bu">:</span> 3</span>
|
||||
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 1 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> A</span>
|
||||
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 2 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> C</span>
|
||||
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> setting 3 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> E</span>
|
||||
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 1 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> B</span>
|
||||
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 2 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> D</span>
|
||||
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> position 3 <span class="er">(</span><span class="ex">A</span> <span class="at">-</span> Z<span class="kw">)</span><span class="bu">:</span> F</span>
|
||||
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span></span>
|
||||
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">1</span><span class="kw">)</span> <span class="kw">(</span><span class="ex">B</span><span class="kw">)</span> <span class="ex">YRUHQSLDPXNGOKMIEBFZCWVJAT</span></span>
|
||||
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="ex">2</span><span class="kw">)</span> <span class="kw">(</span><span class="ex">C</span><span class="kw">)</span> <span class="ex">FVPJIAOYEDRZXWGCTKUQSBNMHL</span></span>
|
||||
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> reflector <span class="er">(</span><span class="ex">1</span> <span class="at">-</span> 2<span class="kw">)</span><span class="bu">:</span> 2</span>
|
||||
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 1: AB</span>
|
||||
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 2: CD</span>
|
||||
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 3: EF</span>
|
||||
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 4: GHIJ</span>
|
||||
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 5: IJ</span>
|
||||
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 6: KL</span>
|
||||
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 7: MN</span>
|
||||
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 8: OP</span>
|
||||
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 9: QR</span>
|
||||
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a> <span class="ex">Input</span> plugboard pair 10: ST</span>
|
||||
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 1: <span class="er">(</span> <span class="ex">I</span><span class="kw">)</span> <span class="ex">EKMFLGDQVZNTOWYHXUSPAIBRCJ</span></span>
|
||||
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 2: <span class="er">(</span> <span class="ex">II</span><span class="kw">)</span> <span class="ex">AJDKSIRUXBLHWTMCQGZNPYFVOE</span></span>
|
||||
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> 3: <span class="er">(</span><span class="ex">III</span><span class="kw">)</span> <span class="ex">BDFHJLCPRTXVZNYEIWGAKMUSQO</span></span>
|
||||
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> settings: ACE</span>
|
||||
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ring</span> positions: BDF</span>
|
||||
<span id="cb11-36"><a href="#cb11-36" aria-hidden="true" tabindex="-1"></a> <span class="ex">Reflector:</span> <span class="er">(</span><span class="ex">C</span><span class="kw">)</span> <span class="ex">FVPJIAOYEDRZXWGCTKUQSBNMHL</span></span>
|
||||
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#01: AB</span></span>
|
||||
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#02: CD</span></span>
|
||||
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#03: EF</span></span>
|
||||
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#04: GH</span></span>
|
||||
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#05: IJ</span></span>
|
||||
<span id="cb11-42"><a href="#cb11-42" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#06: KL</span></span>
|
||||
<span id="cb11-43"><a href="#cb11-43" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#07: MN</span></span>
|
||||
<span id="cb11-44"><a href="#cb11-44" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#08: OP</span></span>
|
||||
<span id="cb11-45"><a href="#cb11-45" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#09: QR</span></span>
|
||||
<span id="cb11-46"><a href="#cb11-46" aria-hidden="true" tabindex="-1"></a> <span class="ex">Plugboard</span> pair <span class="co">#10: ST</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -v -oconfig -finput >/dev/null
|
||||
Rotors:
|
||||
(1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
(2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE
|
||||
(3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO
|
||||
(4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB
|
||||
(5) V: VZBRGITYUPSDNHLXAWMJQOFECK
|
||||
Input rotor 1 (1 - 5): 1
|
||||
Input rotor 2 (1 - 5): 2
|
||||
Input rotor 3 (1 - 5): 3
|
||||
Input setting 1 (A - Z): A
|
||||
Input setting 2 (A - Z): C
|
||||
Input setting 3 (A - Z): E
|
||||
Input position 1 (A - Z): B
|
||||
Input position 2 (A - Z): D
|
||||
Input position 3 (A - Z): F
|
||||
Reflector:
|
||||
(1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT
|
||||
(2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL
|
||||
Input reflector (1 - 2): 2
|
||||
Input plugboard pair 1: AB
|
||||
Input plugboard pair 2: CD
|
||||
Input plugboard pair 3: EF
|
||||
Input plugboard pair 4: GHIJ
|
||||
Input plugboard pair 5: IJ
|
||||
Input plugboard pair 6: KL
|
||||
Input plugboard pair 7: MN
|
||||
Input plugboard pair 8: OP
|
||||
Input plugboard pair 9: QR
|
||||
Input plugboard pair 10: ST
|
||||
Ring 1: ( I) EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
Ring 2: ( II) AJDKSIRUXBLHWTMCQGZNPYFVOE
|
||||
Ring 3: (III) BDFHJLCPRTXVZNYEIWGAKMUSQO
|
||||
Ring settings: ACE
|
||||
Ring positions: BDF
|
||||
Reflector: (C) FVPJIAOYEDRZXWGCTKUQSBNMHL
|
||||
Plugboard pair #01: AB
|
||||
Plugboard pair #02: CD
|
||||
Plugboard pair #03: EF
|
||||
Plugboard pair #04: GH
|
||||
Plugboard pair #05: IJ
|
||||
Plugboard pair #06: KL
|
||||
Plugboard pair #07: MN
|
||||
Plugboard pair #08: OP
|
||||
Plugboard pair #09: QR
|
||||
Plugboard pair #10: ST</code></pre>
|
||||
<p>Notice that I redirect stdout to /dev/null so that the config is only written to
|
||||
the file config. But also notice that for <a href="https://www.cryptomuseum.com/crypto/enigma/i/sb.htm">plugboard
|
||||
pair</a> 4 I typed in <code>GHIJ</code>
|
||||
@@ -389,55 +389,55 @@ and it didn’t report an error. Neither did it complain about <code>IJ</code> i
|
||||
pair. This is because it consumes input overflow.</p>
|
||||
<p>It shouldn’t be this way for the simulator though because that could cause
|
||||
inconsistent number of characters expected before the text to encipher.</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat config</span>
|
||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">1AB2CD3EF2ABCDEFGHIJKLMNOPQRST</span></span>
|
||||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> <span class="er">(</span> <span class="fu">cat</span> config <span class="kw">;</span> <span class="fu">cat</span> input <span class="kw">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">LRAVE</span></span>
|
||||
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> <span class="er">(</span> <span class="fu">cat</span> config <span class="kw">;</span> <span class="fu">cat</span> input <span class="kw">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="kw">(</span> <span class="fu">cat</span> config <span class="kw">;</span> <span class="bu">echo</span> LRAVE <span class="kw">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ cat config
|
||||
1AB2CD3EF2ABCDEFGHIJKLMNOPQRST
|
||||
|
||||
$ ( cat config ; cat input ) | ./prog - 2>/dev/null
|
||||
LRAVE
|
||||
|
||||
$ ( cat config ; cat input ) | ./prog - 2>/dev/null | ( cat config ; echo LRAVE ) | ./prog - 2>/dev/null
|
||||
IOCCC</code></pre>
|
||||
<p>What if you don’t want to worry about having to specify input but just have the
|
||||
settings written? You can do that too by either sending a newline or else
|
||||
directly type ctrl-d (or whatever you have EOF set to) or give it an empty file.</p>
|
||||
<p>The following are all equivalent in that they will write to a settings file (the
|
||||
first one will print a newline with the echo but that won’t matter):</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-r</span> <span class="at">-osettings</span></span>
|
||||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo <span class="at">-n</span> <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-r</span> <span class="at">-osettings</span></span>
|
||||
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> <span class="op">></span> empty</span>
|
||||
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-r</span> <span class="at">-osettings</span> <span class="op"><</span> empty</span>
|
||||
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat empty <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-r</span> <span class="at">-osettings</span></span>
|
||||
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-r</span> <span class="at">-osettings</span></span>
|
||||
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">^D</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo | ./recode -r -osettings
|
||||
$ echo -n | ./recode -r -osettings
|
||||
$ > empty
|
||||
$ ./recode -r -osettings < empty
|
||||
$ cat empty | ./recode -r -osettings
|
||||
$ ./recode -r -osettings
|
||||
^D</code></pre>
|
||||
<p>(Above ^D was not shown but I typed it.) The way it works: if nothing is read
|
||||
the buffer remains <code>NULL</code> and so I don’t print it but still do print the settings
|
||||
file. (Actually even if <code>getdelim()</code> fails you’re supposed to free the buffer so I
|
||||
set another variable to indicate if it should be printed.)</p>
|
||||
<h1 id="reusing-a-configuration"><a name="reuseconfig" href="#toc">Reusing a configuration</a></h1>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo <span class="at">-n</span><span class="kw">|</span><span class="ex">./recode</span> <span class="at">-r</span> <span class="at">-oconfig</span></span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$</span></span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat input.txt</span>
|
||||
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span> 2020 Enigma simulator example text file</span>
|
||||
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">This</span> is a sentence.</span>
|
||||
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">This</span> is another sentence.</span>
|
||||
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> <span class="er">(</span> <span class="fu">cat</span> config <span class="kw">;</span> <span class="fu">cat</span> input.txt <span class="kw">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> output</span>
|
||||
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat output</span>
|
||||
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">AAPRT</span> 2020 Dkemny tpgnjsjai xpovrgl jvgs wxra</span>
|
||||
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">Fytt</span> ly m xyiilaqh.</span>
|
||||
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">Ybbp</span> ox dmuzerm oscwgytb.</span>
|
||||
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> <span class="er">(</span> <span class="fu">cat</span> config <span class="kw">;</span> <span class="fu">cat</span> output <span class="kw">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> io</span>
|
||||
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> diff io input.txt</span>
|
||||
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo -n|./recode -r -oconfig
|
||||
4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$
|
||||
|
||||
$ cat input.txt
|
||||
IOCCC 2020 Enigma simulator example text file
|
||||
|
||||
This is a sentence.
|
||||
|
||||
This is another sentence.
|
||||
|
||||
$ ( cat config ; cat input.txt ) | ./prog - 2>/dev/null > output
|
||||
$ cat output
|
||||
AAPRT 2020 Dkemny tpgnjsjai xpovrgl jvgs wxra
|
||||
|
||||
Fytt ly m xyiilaqh.
|
||||
|
||||
Ybbp ox dmuzerm oscwgytb.
|
||||
$ ( cat config ; cat output ) | ./prog - 2>/dev/null > io
|
||||
$ diff io input.txt
|
||||
$</code></pre>
|
||||
<p>Alternatively you can just use the <code>-R</code> and <code>-f</code> options:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-finput.txt</span> <span class="at">-Rconfig</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> output2</span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> diff output output2</span>
|
||||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -finput.txt -Rconfig | ./prog - 2>/dev/null > output2
|
||||
$ diff output output2
|
||||
$</code></pre>
|
||||
<h1 id="write-config-file-read-data-file-and-pass-to-enigma-simulator"><a name="passtoenigma" href="#toc">Write config file, read data file and pass to Enigma simulator</a></h1>
|
||||
<pre><code> $ ./recode -finput.txt -oconfig | ./prog - 2>/dev/null > output
|
||||
Rotors:
|
||||
@@ -476,37 +476,37 @@ set another variable to indicate if it should be printed.)</p>
|
||||
Cody?) there’s also a reference to code which I also love (just as all
|
||||
participants of the IOCCC do). Other things there don’t mean anything but what
|
||||
does is the output:</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat output</span>
|
||||
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">DBFAF</span> 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf</span>
|
||||
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">Jsjy</span> ce v pxdmullo.</span>
|
||||
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Sara</span> tj rtaayak uxfhjcti.</span>
|
||||
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-Rconfig</span> <span class="at">-foutput</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span> 2020 Enigma simulator example text file</span>
|
||||
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">This</span> is a sentence.</span>
|
||||
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">This</span> is another sentence.</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ cat output
|
||||
DBFAF 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf
|
||||
|
||||
Jsjy ce v pxdmullo.
|
||||
|
||||
Sara tj rtaayak uxfhjcti.
|
||||
|
||||
$ ./recode -Rconfig -foutput | ./prog - 2>/dev/null
|
||||
IOCCC 2020 Enigma simulator example text file
|
||||
|
||||
This is a sentence.
|
||||
|
||||
This is another sentence.</code></pre>
|
||||
<h1 id="piping-directly-to-the-enigma-code-once-with-randomised-settings-saved"><a name="directlytoenigma" href="#toc">Piping directly to the Enigma code once (with randomised settings, saved)</a></h1>
|
||||
<p>This is like the above only randomised:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./recode <span class="at">-r</span> <span class="at">-oconfig</span><span class="kw">|</span><span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span>
|
||||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">UGEVP</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./recode -r -oconfig|./prog - 2>/dev/null
|
||||
IOCCC
|
||||
UGEVP</code></pre>
|
||||
<p>Note that I typed in <code>IOCCC</code> and sent <code>EOF</code> (ctrl-d); the settings were written to
|
||||
the config file (for deciphering later) and then all of it was piped to the
|
||||
Enigma entry resulting in the line below IOCCC. But let’s verify it worked out
|
||||
okay:</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> cat config</span>
|
||||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ cat config
|
||||
2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ</code></pre>
|
||||
<p>Without having to copy/paste intermediate results:</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo IOCCC <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-Rconfig</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-Rconfig</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo IOCCC | ./recode -Rconfig | ./prog - 2>/dev/null | ./recode -Rconfig | ./prog - 2>/dev/null
|
||||
IOCCC</code></pre>
|
||||
<p>You can also use a string for the <code>-R</code> option. I’ll use command substitution and
|
||||
actual pasting to demonstrate:</p>
|
||||
<div class="sourceCode" id="cb21"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo IOCCC <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-R</span><span class="va">$(</span><span class="fu">cat</span> config<span class="va">)</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="kw">|</span> <span class="ex">./recode</span> <span class="at">-R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null</span>
|
||||
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">IOCCC</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo IOCCC | ./recode -R$(cat config) | ./prog - 2>/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2>/dev/null
|
||||
IOCCC</code></pre>
|
||||
<h1 id="usage-conclusion"><a name="conclusion" href="#toc">Usage conclusion</a></h1>
|
||||
<p>That should give you an idea of how to use the <code>recode</code> program. I leave it as
|
||||
an exercise to the reader to implement additional features but here are some
|
||||
@@ -585,7 +585,7 @@ think that I would give too much away? :)</p>
|
||||
the key you wish to select is</p>
|
||||
<pre><code> 0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI</code></pre>
|
||||
<p>you can do:</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./recode</span> <span class="at">-R0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI</span> <span class="at">-fencrypted.html</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">></span>/dev/null <span class="op">></span> decrypted.html</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./recode -R0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI -fencrypted.html | ./prog - 2>/dev/null > decrypted.html</code></pre>
|
||||
<p>Then open <code>decrypted.html</code> in your browser.</p>
|
||||
<!--
|
||||
|
||||
|
||||
+21
-21
@@ -55,7 +55,7 @@ wonderful 'challenge' for everyone.
|
||||
|
||||
# <a name="options" href="#toc">Options</a>
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./recode -h
|
||||
usage: ./recode [options]
|
||||
-v display selected settings
|
||||
@@ -71,7 +71,7 @@ if you don't give the option to read in a file for input.
|
||||
|
||||
`-v` shows selected settings. For example combining `-r` and `-v`:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo IOCCC | ./recode -r -v
|
||||
Ring 1: ( I) EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
Ring 2: ( V) VZBRGITYUPSDNHLXAWMJQOFECK
|
||||
@@ -104,7 +104,7 @@ encipherment/decipherment). If the file cannot be opened it sets back to stdin.
|
||||
or is the same file name (see below) then only stdout will be used. Example of
|
||||
randomised output going to a file:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -r -oconfig
|
||||
IOCCC
|
||||
3PP4UB5GG1ELGTKFCOPVBNUYXJAWSDIOCCC
|
||||
@@ -143,7 +143,7 @@ what about if one exists but the other does not?
|
||||
Due to the way the parsing of options is done (no spaces between option char and
|
||||
argument) shell expansion will not work right so for example doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -R~/config
|
||||
```
|
||||
|
||||
@@ -163,7 +163,7 @@ the program interactively.
|
||||
If stdin is not a tty (`!isatty(0)`) and neither randomised mode nor reading in
|
||||
from a file is specified then you might just see something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo testing test tests | ./recode
|
||||
1AB2BB3CC1testing test tests
|
||||
|
||||
@@ -189,7 +189,7 @@ input manually (if you randomise or read in from previously saved file no input
|
||||
need be done at all) then make sure to redirect stderr to /dev/null. If you
|
||||
don't you might see something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -r | ./prog -
|
||||
Ring 1: IOCCC
|
||||
Setting 1: Position 1: Ring 2: Setting 2: Position 2: Ring 3: Setting 3: Position 3: Reflector: Plugboard pair 1: Plugboard pair 2: Plugboard pair 3: Plugboard pair 4: Plugboard pair 5: Plugboard pair 6: Plugboard pair 7: Plugboard pair 8: Plugboard pair 9: Plugboard pair 10: DEVIY
|
||||
@@ -205,7 +205,7 @@ That's why after I sent EOF it printed out the remaining strings to stderr.
|
||||
|
||||
# <a name="manuallytest" href="#toc">Manually test the recode program with the Enigma program</a>
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ cat input
|
||||
IOCCC
|
||||
|
||||
@@ -249,7 +249,7 @@ than the simulator: because with the size restrictions on my entry I saved bytes
|
||||
by using the same loop where I could. It just felt more natural to have them
|
||||
grouped together in a configurator for the [simulator](prog.c).
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null
|
||||
HQNVO
|
||||
$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null | echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO | ./prog - 2>/dev/null
|
||||
@@ -273,21 +273,21 @@ What happens if the plugboard pairs are the same but in a different order? It's
|
||||
the same output:
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo 1AA2AA3AA2AB..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null
|
||||
HQNVO
|
||||
```
|
||||
|
||||
Also if you flip the order of the letters in the pair e.g. the AB as BA instead:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null
|
||||
HQNVO
|
||||
```
|
||||
|
||||
# <a name="onlyconfig" href="#toc">Only write config file</a>
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -v -oconfig -finput >/dev/null
|
||||
Rotors:
|
||||
(1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ
|
||||
@@ -345,7 +345,7 @@ pair. This is because it consumes input overflow.
|
||||
It shouldn't be this way for the simulator though because that could cause
|
||||
inconsistent number of characters expected before the text to encipher.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ cat config
|
||||
1AB2CD3EF2ABCDEFGHIJKLMNOPQRST
|
||||
|
||||
@@ -363,7 +363,7 @@ directly type ctrl-d (or whatever you have EOF set to) or give it an empty file.
|
||||
The following are all equivalent in that they will write to a settings file (the
|
||||
first one will print a newline with the echo but that won't matter):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo | ./recode -r -osettings
|
||||
$ echo -n | ./recode -r -osettings
|
||||
$ > empty
|
||||
@@ -380,7 +380,7 @@ set another variable to indicate if it should be printed.)
|
||||
|
||||
# <a name="reuseconfig" href="#toc">Reusing a configuration</a>
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo -n|./recode -r -oconfig
|
||||
4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$
|
||||
|
||||
@@ -405,7 +405,7 @@ set another variable to indicate if it should be printed.)
|
||||
|
||||
Alternatively you can just use the `-R` and `-f` options:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -finput.txt -Rconfig | ./prog - 2>/dev/null > output2
|
||||
$ diff output output2
|
||||
$
|
||||
@@ -456,7 +456,7 @@ participants of the IOCCC do). Other things there don't mean anything but what
|
||||
does is the output:
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ cat output
|
||||
DBFAF 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf
|
||||
|
||||
@@ -477,7 +477,7 @@ does is the output:
|
||||
|
||||
This is like the above only randomised:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./recode -r -oconfig|./prog - 2>/dev/null
|
||||
IOCCC
|
||||
UGEVP
|
||||
@@ -489,14 +489,14 @@ the config file (for deciphering later) and then all of it was piped to the
|
||||
Enigma entry resulting in the line below IOCCC. But let's verify it worked out
|
||||
okay:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ cat config
|
||||
2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ
|
||||
```
|
||||
|
||||
Without having to copy/paste intermediate results:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo IOCCC | ./recode -Rconfig | ./prog - 2>/dev/null | ./recode -Rconfig | ./prog - 2>/dev/null
|
||||
IOCCC
|
||||
```
|
||||
@@ -504,7 +504,7 @@ Without having to copy/paste intermediate results:
|
||||
You can also use a string for the `-R` option. I'll use command substitution and
|
||||
actual pasting to demonstrate:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo IOCCC | ./recode -R$(cat config) | ./prog - 2>/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2>/dev/null
|
||||
IOCCC
|
||||
```
|
||||
@@ -612,7 +612,7 @@ the key you wish to select is
|
||||
|
||||
you can do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./recode -R0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI -fencrypted.html | ./prog - 2>/dev/null > decrypted.html
|
||||
```
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@ For more detailed information see [2020 giles bugs](../../bugs.html#2020_giles).
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog < dtmf.wav
|
||||
|
||||
./prog [digits] > digits.wav
|
||||
@@ -33,7 +33,7 @@ will be converted to the DTMF sound!
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
./prog < pi.wav
|
||||
|
||||
@@ -71,7 +71,7 @@ exactly 16 bits per sample, but it allows any sample rate and any number of
|
||||
audio channels.
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog < pi.wav
|
||||
31415926
|
||||
```
|
||||
@@ -80,7 +80,7 @@ If the program is executed with a command-line argument, it will generate the
|
||||
tones corresponding to the specified characters, writing them to standard output
|
||||
as a WAV file.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog 867-5309 | aplay
|
||||
```
|
||||
|
||||
|
||||
+12
-12
@@ -141,26 +141,26 @@ Location: <a href="../../location.html#AU">AU</a> - <em>Commonwealth of Australi
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_giles">2020 giles bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op"><</span> dtmf.wav</span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="pp">[</span><span class="ss">digits</span><span class="pp">]</span> <span class="op">></span> digits.wav</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog < dtmf.wav
|
||||
|
||||
./prog [digits] > digits.wav</code></pre>
|
||||
<p>where <code>dtmf.wav</code> is a WAV file of the dialling of a number being dialled with
|
||||
<a href="https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling">DTMF (Dual-tone multi
|
||||
frequency)</a>
|
||||
(more commonly known as Touch-Tone) and <code>[digits]</code> is a sequence of digits that
|
||||
will be converted to the DTMF sound!</p>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op"><</span> pi.wav</span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># See</span></span>
|
||||
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> 867-5309 <span class="op">></span> jenny.wav</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh
|
||||
./prog < pi.wav
|
||||
|
||||
# See
|
||||
./prog 867-5309 > jenny.wav</code></pre>
|
||||
<p>If the script <a href="try.sh">try.sh</a> did not play a WAV file, it means you do not have
|
||||
SoX installed; see <a href="../../faq.html#sox">FAQ 3.10: How do I compile and use an IOCCC entry that
|
||||
requires sound?</a>). In this case install it and try it again or
|
||||
@@ -180,12 +180,12 @@ standard input, decode the touch-tones in the file, and output the corresponding
|
||||
digits to standard output. This program only supports WAV files that have
|
||||
exactly 16 bits per sample, but it allows any sample rate and any number of
|
||||
audio channels.</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog <span class="op"><</span> pi.wav</span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">31415926</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog < pi.wav
|
||||
31415926</code></pre>
|
||||
<p>If the program is executed with a command-line argument, it will generate the
|
||||
tones corresponding to the specified characters, writing them to standard output
|
||||
as a WAV file.</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog 867-5309 <span class="kw">|</span> <span class="fu">aplay</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog 867-5309 | aplay</code></pre>
|
||||
<h3 id="interesting-features">Interesting Features</h3>
|
||||
<ul>
|
||||
<li>When compiled with <code>gcc -pedantic -Wall -Wextra</code> there are no compiler
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -10,7 +10,7 @@ code](#alternate-code) below for more details.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
# input some text
|
||||
|
||||
@@ -22,7 +22,7 @@ code](#alternate-code) below for more details.
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -46,7 +46,7 @@ are the program in assembly for x86_64 linux and x86 linux respectively.
|
||||
|
||||
To build [prog.alt.c](prog.alt.c):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
|
||||
@@ -141,18 +141,18 @@ Location: <a href="../../location.html#RU">RU</a> - <em>Russian Federation</em>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>There are alternate versions of this entry. See <a href="#alternate-code">Alternate
|
||||
code</a> below for more details.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># input some text</span></span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> text <span class="kw">|</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op"><</span> file</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog
|
||||
# input some text
|
||||
|
||||
echo text | ./prog
|
||||
|
||||
./prog < file</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>There are a number of alternate versions for this program, some in C and some in
|
||||
assembly.</p>
|
||||
@@ -164,7 +164,7 @@ different social media profile covers as well as different shapes.</p>
|
||||
are the program in assembly for x86_64 linux and x86 linux respectively.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<p>To build <a href="prog.alt.c">prog.alt.c</a>:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
|
||||
+13
-13
@@ -1,20 +1,20 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# Take a selfie
|
||||
./prog 1000 selfie.jpg output.jpg
|
||||
# Admire your portrait in cubist style
|
||||
@@ -41,7 +41,7 @@ This program divides the image into a specified number of rectangles. This
|
||||
process is content aware, so the algorithm tries to match most of the information.
|
||||
However, it doesn't find the best theoretically possible layout.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog 1000 input.jpg output.jpg
|
||||
```
|
||||
|
||||
@@ -56,13 +56,13 @@ If you want to use `libjpeg` compiled from sources, then use the `LIBJPEG` defin
|
||||
specify the path to includes and the library. For example using
|
||||
[libjpeg source](https://mac-dev-env.patrickbougie.com/libjpeg/) version 9c:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make prog LIBJPEG="-Ijpeg-9c jpeg-9c/libjpeg.a"
|
||||
```
|
||||
|
||||
Use this command to build a PNG version (you need `libpng`):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make prog_png LIBPNG="-lpng"
|
||||
```
|
||||
|
||||
@@ -80,13 +80,13 @@ information!
|
||||
|
||||
First, make sure you have the compiler tools installed e.g. by:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo xcode-select --install
|
||||
```
|
||||
|
||||
Make sure you install [MacPorts](https://www.macports.org/install.php). Then do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo port install jpeg libpng ImageMagick
|
||||
```
|
||||
|
||||
@@ -95,7 +95,7 @@ GIFs from the results using `makegif.sh`.
|
||||
|
||||
After that’s installed you need to run make with these options:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make LDFLAGS="-I/opt/local/include -L/opt/local/lib"
|
||||
```
|
||||
|
||||
@@ -103,7 +103,7 @@ After that’s installed you need to run make with these options:
|
||||
|
||||
First, make sure you have the compiler tools installed e.g. by:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo xcode-select --install
|
||||
```
|
||||
|
||||
@@ -111,14 +111,14 @@ Make sure you install [Homebrew](https://brew.sh).
|
||||
|
||||
Then:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
brew install libjpeg libpng
|
||||
eval "$(brew shellenv)"
|
||||
```
|
||||
|
||||
You are now ready to compile this entry:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make clobber all
|
||||
```
|
||||
|
||||
@@ -139,7 +139,7 @@ vertically to get the minimum difference.
|
||||
You can use this command to make a GIF from output images (uses ImageMagick).
|
||||
For instance after running the command suggested by the judges:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
convert -delay 10 -dither none -loop 0 $(find . -maxdepth 1 -type f -name '*jpg' | sort -V) $(find . -maxdepth 1 -type f -name '*jpg' | sort -rV) +map out.gif
|
||||
```
|
||||
|
||||
|
||||
+19
-19
@@ -141,16 +141,16 @@ Location: <a href="../../location.html#RU">RU</a> - <em>Russian Federation</em>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Take a selfie</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> 1000 selfie.jpg output.jpg</span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># Admire your portrait in cubist style</span></span>
|
||||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># Also try:</span></span>
|
||||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # Take a selfie
|
||||
./prog 1000 selfie.jpg output.jpg
|
||||
# Admire your portrait in cubist style
|
||||
|
||||
# Also try:
|
||||
./try.sh</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>This entry has reminded us of a winning entry back in the early 90s. Can you
|
||||
guess which one?</p>
|
||||
@@ -161,7 +161,7 @@ rectangles. What is the complexity? Is it obvious from the source code?</p>
|
||||
<p>This program divides the image into a specified number of rectangles. This
|
||||
process is content aware, so the algorithm tries to match most of the information.
|
||||
However, it doesn’t find the best theoretically possible layout.</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> 1000 input.jpg output.jpg</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog 1000 input.jpg output.jpg</code></pre>
|
||||
<h3 id="building">Building</h3>
|
||||
<p>You can build three versions, depending on the image format.</p>
|
||||
<p>Default is JPEG version; if you have the <code>libjpeg</code> development package installed
|
||||
@@ -169,9 +169,9 @@ in your system, then <code>make</code> without arguments should do the right thi
|
||||
<p>If you want to use <code>libjpeg</code> compiled from sources, then use the <code>LIBJPEG</code> define to
|
||||
specify the path to includes and the library. For example using
|
||||
<a href="https://mac-dev-env.patrickbougie.com/libjpeg/">libjpeg source</a> version 9c:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> prog LIBJPEG=<span class="st">"-Ijpeg-9c jpeg-9c/libjpeg.a"</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make prog LIBJPEG="-Ijpeg-9c jpeg-9c/libjpeg.a"</code></pre>
|
||||
<p>Use this command to build a PNG version (you need <code>libpng</code>):</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> prog_png LIBPNG=<span class="st">"-lpng"</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make prog_png LIBPNG="-lpng"</code></pre>
|
||||
<p>And the PPM version (no additional dependencies, can read raw/ASCII PPM, writes
|
||||
raw PPM):</p>
|
||||
<pre><code> make prog_ppm</code></pre>
|
||||
@@ -179,22 +179,22 @@ raw PPM):</p>
|
||||
<p>Thanks to <a href="../../authors.html#Cody_Boone_Ferguson">Cody Boone Ferguson</a> for this
|
||||
information!</p>
|
||||
<p>First, make sure you have the compiler tools installed e.g. by:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo xcode-select --install</code></pre>
|
||||
<p>Make sure you install <a href="https://www.macports.org/install.php">MacPorts</a>. Then do:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> port install jpeg libpng ImageMagick</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo port install jpeg libpng ImageMagick</code></pre>
|
||||
<p>The program itself doesn’t need ImageMagick, install it only if you plan to make
|
||||
GIFs from the results using <code>makegif.sh</code>.</p>
|
||||
<p>After that’s installed you need to run make with these options:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> LDFLAGS=<span class="st">"-I/opt/local/include -L/opt/local/lib"</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make LDFLAGS="-I/opt/local/include -L/opt/local/lib"</code></pre>
|
||||
<h3 id="building-on-macos-with-homebrew">Building on macOS with Homebrew</h3>
|
||||
<p>First, make sure you have the compiler tools installed e.g. by:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo xcode-select --install</code></pre>
|
||||
<p>Make sure you install <a href="https://brew.sh">Homebrew</a>.</p>
|
||||
<p>Then:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">brew</span> install libjpeg libpng</span>
|
||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">eval</span> <span class="st">"</span><span class="va">$(</span><span class="ex">brew</span> shellenv<span class="va">)</span><span class="st">"</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> brew install libjpeg libpng
|
||||
eval "$(brew shellenv)"</code></pre>
|
||||
<p>You are now ready to compile this entry:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber all</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make clobber all</code></pre>
|
||||
<h3 id="notes">Notes</h3>
|
||||
<p>Made this thing while experimenting with the idea of representing an image with
|
||||
rectangles (lossy compression). It’s not very good in that sense, but the
|
||||
@@ -206,7 +206,7 @@ the picture data is split (halves may have different size) horizontally or
|
||||
vertically to get the minimum difference.</p>
|
||||
<p>You can use this command to make a GIF from output images (uses ImageMagick).
|
||||
For instance after running the command suggested by the judges:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">convert</span> <span class="at">-delay</span> 10 <span class="at">-dither</span> none <span class="at">-loop</span> 0 <span class="va">$(</span><span class="fu">find</span> . <span class="at">-maxdepth</span> 1 <span class="at">-type</span> f <span class="at">-name</span> <span class="st">'*jpg'</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-V</span><span class="va">)</span> <span class="va">$(</span><span class="fu">find</span> . <span class="at">-maxdepth</span> 1 <span class="at">-type</span> f <span class="at">-name</span> <span class="st">'*jpg'</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-rV</span><span class="va">)</span> +map out.gif</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> convert -delay 10 -dither none -loop 0 $(find . -maxdepth 1 -type f -name '*jpg' | sort -V) $(find . -maxdepth 1 -type f -name '*jpg' | sort -rV) +map out.gif</code></pre>
|
||||
<p>NOTE: the above is done in the <a href="try.sh">try.sh</a> script.</p>
|
||||
<p>Also provided <code>makegif.sh</code> to aid with GIF creation.</p>
|
||||
<!--
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -10,14 +10,14 @@ code](#alternate-code) below.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -29,7 +29,7 @@ The alternate version, [prog.alt.c](prog.alt.c), has the main code as a macro.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
@@ -61,7 +61,7 @@ exactly what it says nonetheless.
|
||||
|
||||
Compile and try this:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
cat input.txt | ./prog
|
||||
```
|
||||
|
||||
|
||||
@@ -141,17 +141,17 @@ Location: <a href="../../location.html#RU">RU</a> - <em>Russian Federation</em>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>There is an alternate version of this program. See <a href="#alternate-code">Alternate
|
||||
code</a> below.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>The alternate version, <a href="prog.alt.c">prog.alt.c</a>, has the main code as a macro.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
@@ -169,7 +169,7 @@ exactly what it says nonetheless.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<h3 id="letter-mixer">Letter Mixer</h3>
|
||||
<p>Compile and try this:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> input.txt <span class="kw">|</span> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> cat input.txt | ./prog</code></pre>
|
||||
<p>The program can work with letters that are not represented in English, as long
|
||||
as these letters are encoded in the higher part of the single-byte character set
|
||||
(use <code>iconv</code> to convert from UTF-8 and back).</p>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog text_file output_length context_length random_seed
|
||||
```
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
When running this, ask yourself why it gets progressively slower when the
|
||||
context length decreases:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -70,7 +70,7 @@ Now can you appreciate the award title a bit better?
|
||||
|
||||
### Building:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
cc prog.c -o prog
|
||||
```
|
||||
|
||||
@@ -79,7 +79,7 @@ Now can you appreciate the award title a bit better?
|
||||
This program generates random text from the provided dictionary using a Markov
|
||||
chain, outputting to `stdout`.
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog input.txt 2000 10 12345
|
||||
```
|
||||
|
||||
@@ -110,7 +110,7 @@ You can try this with the inputs provided with
|
||||
[2019/mills](../../2019/mills/index.html) from the IOCCC entries.
|
||||
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ ./prog Shakespeare.txt 2001 10 12345
|
||||
```
|
||||
|
||||
|
||||
@@ -141,13 +141,13 @@ Location: <a href="../../location.html#RU">RU</a> - <em>Russian Federation</em>
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> text_file output_length context_length random_seed</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog text_file output_length context_length random_seed</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<p>When running this, ask yourself why it gets progressively slower when the
|
||||
context length decreases:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<blockquote>
|
||||
<p>Performance depends on the number of same hashes found.
|
||||
Too many identical strings if the context length is small.
|
||||
@@ -183,11 +183,11 @@ Middle-earth (HoMe)</a>.
|
||||
Now can you appreciate the award title a bit better?</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<h3 id="building">Building:</h3>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> prog.c <span class="at">-o</span> prog</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> cc prog.c -o prog</code></pre>
|
||||
<h3 id="usage">Usage:</h3>
|
||||
<p>This program generates random text from the provided dictionary using a Markov
|
||||
chain, outputting to <code>stdout</code>.</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> input.txt 2000 10 12345</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog input.txt 2000 10 12345</code></pre>
|
||||
<p>Parameters are:</p>
|
||||
<ol type="1">
|
||||
<li><p>dictionary filename
|
||||
@@ -209,7 +209,7 @@ the output of this size in bytes exists somewhere in the dictionary.</p></li>
|
||||
<h3 id="example">Example</h3>
|
||||
<p>You can try this with the inputs provided with
|
||||
<a href="../../2019/mills/index.html">2019/mills</a> from the IOCCC entries.</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./prog Shakespeare.txt 2001 10 12345</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ ./prog Shakespeare.txt 2001 10 12345</code></pre>
|
||||
<p>produces:</p>
|
||||
<pre><code> r sons, wives for them, as the hope I had it. This is the way they be not too ra
|
||||
sh a trial of you only. Therefore will not out of door? Nurse: Marry, bachelor,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,14 +18,14 @@ For more detailed information see [2020 otterness bugs](../../bugs.html#2020_ott
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -74,7 +74,7 @@ for most of my testing (see [cvikl.mid](cvikl.mid)).
|
||||
Compile the program using the following command (I tested this using both
|
||||
`clang` and `gcc`):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
cc -pedantic -Wall -Werror -Wextra -O3 -o prog prog.c
|
||||
```
|
||||
|
||||
|
||||
@@ -141,15 +141,15 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_otterness">2020 otterness bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./try.sh</code></pre>
|
||||
<p>Now play <code>output.mid</code> and <code>output2.mid</code> in an audio player that can play MIDI
|
||||
files.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
@@ -179,7 +179,7 @@ for most of my testing (see <a href="cvikl.mid">cvikl.mid</a>).</p>
|
||||
<h3 id="usage">Usage</h3>
|
||||
<p>Compile the program using the following command (I tested this using both
|
||||
<code>clang</code> and <code>gcc</code>):</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-pedantic</span> <span class="at">-Wall</span> <span class="at">-Werror</span> <span class="at">-Wextra</span> <span class="at">-O3</span> <span class="at">-o</span> prog prog.c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> cc -pedantic -Wall -Werror -Wextra -O3 -o prog prog.c</code></pre>
|
||||
<p>The program expects a MIDI on <code>stdin</code>, and writes a modified MIDI to <code>stdout</code>:</p>
|
||||
<pre><code> ./prog <input.mid >output.mid</code></pre>
|
||||
<p>If the program encounters an error, no output will generally be produced, and
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -11,14 +11,14 @@ to those familiar with vi. See [Alternate code](#alternate-code) below.
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./prog
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# Make your terminal as large as possible, possibly reduce your font size
|
||||
# then...
|
||||
./prog
|
||||
@@ -33,14 +33,14 @@ where instead of `w`, `a`, `s` and `d`, you can use `k`, `h`, `j` and `l`.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make alt
|
||||
```
|
||||
|
||||
|
||||
### Alternate use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# Make your terminal as large as possible, possibly reduce your font size
|
||||
# then...
|
||||
./prog.alt
|
||||
|
||||
@@ -141,24 +141,24 @@ Location: <a href="../../location.html#DE">DE</a> - <em>Federal Republic of Germ
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<p>There is an alternate version which has controls that will make much more sense
|
||||
to those familiar with vi. See <a href="#alternate-code">Alternate code</a> below.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./prog</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Make your terminal as large as possible, possibly reduce your font size</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># then...</span></span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # Make your terminal as large as possible, possibly reduce your font size
|
||||
# then...
|
||||
./prog</code></pre>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>This version has the difference of moving forwards, left, backwards and right,
|
||||
where instead of <code>w</code>, <code>a</code>, <code>s</code> and <code>d</code>, you can use <code>k</code>, <code>h</code>, <code>j</code> and <code>l</code>.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make alt</code></pre>
|
||||
<h3 id="alternate-use">Alternate use:</h3>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Make your terminal as large as possible, possibly reduce your font size</span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># then...</span></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog.alt</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # Make your terminal as large as possible, possibly reduce your font size
|
||||
# then...
|
||||
./prog.alt</code></pre>
|
||||
<p>..and maybe curse less than you might otherwise, but still probably curse (see
|
||||
below) :-)</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
|
||||
+7
-7
@@ -1,20 +1,20 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
./prog [PIN] < input.txt > output.c
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
The author provided the file [cppp.cc](cppp.cc) which can preprocess the
|
||||
generated output to make them more acceptable to typical compilers. To build:
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
make cppp
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ spoiler](spoiler.html) that shows how this entry was written.
|
||||
|
||||
### Synopsis
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
echo "Hello world" | ./prog 12345 > encoded.c
|
||||
|
||||
gcc -DPIN=12345 encoded.c -o ./decoded && ./decoded
|
||||
@@ -63,14 +63,14 @@ Mile is a C code generator. Run without arguments for the help message below:
|
||||
When run with an encoding PIN (first command line argument), Mile will
|
||||
read bytes from `stdin` and generate C code on `stdout`. Example:
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
echo "Hello, world!" | ./prog 56789 > encoded.c
|
||||
```
|
||||
|
||||
This generated code will reproduce the same input bytes on `stdout` when
|
||||
executed, if it was compiled with the same encoding PIN.
|
||||
|
||||
```sh
|
||||
```<!---<!---sh-->-->
|
||||
gcc -DPIN=56789 encoded.c -o decoded
|
||||
```
|
||||
|
||||
|
||||
@@ -141,14 +141,14 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> make</code></pre>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="pp">[</span><span class="ss">PIN</span><span class="pp">]</span> <span class="op"><</span> input.txt <span class="op">></span> output.c</span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> ./prog [PIN] < input.txt > output.c</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> ./try.sh</code></pre>
|
||||
<p>The author provided the file <a href="cppp.cc">cppp.cc</a> which can preprocess the
|
||||
generated output to make them more acceptable to typical compilers. To build:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> cppp</span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> make cppp</code></pre>
|
||||
<p>See the author’s remarks for more details.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>You might think of this entry as code obfuscater with a code.
|
||||
@@ -159,9 +159,9 @@ What is compiling this entry about?
|
||||
spoiler</a> that shows how this entry was written.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<h3 id="synopsis">Synopsis</h3>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="st">"Hello world"</span> <span class="kw">|</span> <span class="ex">./prog</span> 12345 <span class="op">></span> encoded.c</span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="at">-DPIN</span><span class="op">=</span>12345 encoded.c <span class="at">-o</span> ./decoded <span class="kw">&&</span> <span class="ex">./decoded</span></span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> echo "Hello world" | ./prog 12345 > encoded.c
|
||||
|
||||
gcc -DPIN=12345 encoded.c -o ./decoded && ./decoded</code></pre>
|
||||
<h3 id="details">Details</h3>
|
||||
<p>Mile is a C code generator. Run without arguments for the help message below:</p>
|
||||
<pre><code> usage: [PIN] < input.txt > output.c
|
||||
@@ -169,10 +169,10 @@ spoiler</a> that shows how this entry was written.</p>
|
||||
where [PIN] is an integer in the range of 1..65535</code></pre>
|
||||
<p>When run with an encoding PIN (first command line argument), Mile will
|
||||
read bytes from <code>stdin</code> and generate C code on <code>stdout</code>. Example:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="st">"Hello, world!"</span> <span class="kw">|</span> <span class="ex">./prog</span> 56789 <span class="op">></span> encoded.c</span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> echo "Hello, world!" | ./prog 56789 > encoded.c</code></pre>
|
||||
<p>This generated code will reproduce the same input bytes on <code>stdout</code> when
|
||||
executed, if it was compiled with the same encoding PIN.</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="at">-DPIN</span><span class="op">=</span>56789 encoded.c <span class="at">-o</span> decoded</span></code></pre></div>
|
||||
<pre class="<!---<!---sh-->-->"><code> gcc -DPIN=56789 encoded.c -o decoded</code></pre>
|
||||
<p>The generated code reconstructs all data at compile time by seeding a
|
||||
random number generator with the given PIN to reproduce the input bytes,
|
||||
and simply does one <code>fwrite(3)</code> call at run time to print those bytes. Not
|
||||
|
||||
Reference in new issue
Block a user