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="&lt;!---c--&gt;"><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:
Landon Curt Noll committed 2024-04-04 14:50:38 -07:00
1 parent 3919df50fb
commit b66c79254a
700 files changed
+7052 -7056

No files matched your search

+24 -24
View File
@@ -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
View File
@@ -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="&lt;!---sh--&gt;"><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">&gt;</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">&gt;</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">&gt;</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">&lt;</span>string<span class="kw">|</span><span class="fu">file</span><span class="op">&gt;</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">&gt;</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">&lt;</span>config<span class="op">&gt;</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-</span> <span class="dv">2</span><span class="op">&gt;</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="&lt;!---sh--&gt;"><code> ./prog
# get recode help:
./recode -h
# general syntax for recode passing to Enigma machine:
./recode [options] | ./prog - 2&gt;/dev/null
# general syntax for recode without passing to Enigma machine:
./recode [options]
# recode prompts for settings; pass to Enigma machine:
./recode | ./prog - 2&gt;/dev/null
# recode reads from input file, prompts for settings; passed to Enigma machine:
./recode -finput | ./prog - 2&gt;/dev/null
# recode reads config from string or file; passed to Enigma machine after
# prompting for input:
./recode -R&lt;string|file&gt; | ./prog - 2&gt;/dev/null
# write config to output file; passed to Enigma machine after prompting for
# input:
./recode -o&lt;config&gt; | ./prog - 2&gt;/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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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">&gt;</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">&lt;</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="&lt;!---sh--&gt;"><code> $ echo TEST|./prog |./vik &gt; test.raw
$ ./vik e &lt; 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">&lt;</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="&lt;!---sh--&gt;"><code> $ ./vik e &lt; 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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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">&gt;</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">&lt;</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="&lt;!---sh--&gt;"><code> $ echo LEST | ./prog | ./vik &gt; lest.raw
$ ./vik e &lt; 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">&gt;</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">&lt;</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">&lt;</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="&lt;!---sh--&gt;"><code> $ echo IOCCC | ./prog | ./vik &gt; ioccc.raw
$ ./vik e &lt; ioccc.raw
UUMMX
$ ./vik e &lt; 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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---c--&gt;"><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">&gt;</span>/dev/null <span class="op">&gt;</span> obfuscation.md</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./recode -Robfuscation.key -fobfuscation.txt | ./prog - 2&gt;/dev/null &gt; 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">&gt;</span>/dev/null <span class="op">&gt;</span> obfuscation.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./recode -Robfuscation.key -fobfuscation.md | ./prog - 2&gt;/dev/null &gt; 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
+43 -43
View File
@@ -140,41 +140,41 @@ there is an aesthetic appeal to my eyes too).</p></li>
Y&lt;:19:&gt;&lt;:27:&gt; 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="&lt;!---c--&gt;"><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">&lt;</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">&lt;:</span>j<span class="op">:&gt;</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="&lt;!---c--&gt;"><code> e = z + 10;
g = e + 1;
for (j=-3; j &lt; 0; ++j)
e&lt;:j:&gt; = 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 &lt; 0 but to then compare that that index &lt; 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">&lt;:</span>i<span class="op">-</span><span class="dv">3</span><span class="op">:&gt;</span> <span class="op">=</span> <span class="op">(</span>j <span class="op">&lt;</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">&gt;</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="&lt;!---c--&gt;"><code> /* ... */
e&lt;:i-3:&gt; = (j &lt; 1 ? 1 : (j &gt; 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">&lt;:</span><span class="dv">2</span><span class="op">:&gt;</span> <span class="op">=</span> <span class="dv">0</span><span class="op">;</span> s<span class="op">&lt;:*</span>P<span class="op">:&gt;;</span> <span class="op">++</span>e<span class="op">&lt;:</span><span class="dv">2</span><span class="op">:&gt;)</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">&lt;:</span>e<span class="op">&lt;:</span><span class="dv">2</span><span class="op">:&gt;:&gt;;</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">&gt;</span> <span class="dv">64</span> <span class="op">&amp;&amp;</span> v <span class="op">&lt;</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">&lt;:</span>e<span class="op">&lt;:</span><span class="dv">2</span><span class="op">:&gt;:&gt;</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">&lt;</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">&lt;:</span><span class="dv">16</span><span class="op">+</span>e<span class="op">&lt;:</span><span class="dv">1</span><span class="op">:&gt;:&gt;=</span>S<span class="op">&lt;:</span>e<span class="op">&lt;:</span>e<span class="op">&lt;:</span><span class="dv">1</span><span class="op">:&gt;-</span><span class="dv">3</span><span class="op">:&gt;:&gt;;</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> R<span class="op">&lt;:</span>e<span class="op">&lt;:</span><span class="dv">1</span><span class="op">:&gt;:&gt;=</span>Y<span class="op">&lt;:</span>e<span class="op">&lt;:-</span><span class="dv">3</span><span class="op">+</span>e<span class="op">&lt;:</span><span class="dv">1</span><span class="op">:&gt;:&gt;:&gt;;</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">&lt;:</span><span class="dv">1</span><span class="op">:&gt;-</span><span class="dv">6</span><span class="op">)=</span>q<span class="op">(</span>Y<span class="op">&lt;:</span><span class="dv">8</span><span class="op">:&gt;,*</span>Y<span class="op">&lt;:</span><span class="dv">7</span><span class="op">:&gt;),*</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="&lt;!---c--&gt;"><code> void w(char *s, int k, int v)
{
for(e&lt;:2:&gt; = 0; s&lt;:*P:&gt;; ++e&lt;:2:&gt;)
{
v = s&lt;:e&lt;:2:&gt;:&gt;;
if(v &gt; 64 &amp;&amp; v &lt; 91)
s&lt;:e&lt;:2:&gt;:&gt; = (((v - 65 + k) % 26) + 65);
}
}
void Q(void)
{
for(*g = 0; *g &lt; 3; ++*g)
{
*Y&lt;:16+e&lt;:1:&gt;:&gt;=S&lt;:e&lt;:e&lt;:1:&gt;-3:&gt;:&gt;;
R&lt;:e&lt;:1:&gt;:&gt;=Y&lt;:e&lt;:-3+e&lt;:1:&gt;:&gt;:&gt;;
w(R[*g],*(e+e&lt;:1:&gt;-6)=q(Y&lt;:8:&gt;,*Y&lt;:7:&gt;),*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">&lt;</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">&lt;:-</span><span class="dv">2</span><span class="op">:&gt;</span> <span class="op">=</span> Y<span class="op">&lt;:</span><span class="dv">14</span><span class="op">:&gt;&lt;:*(</span>e<span class="op">+</span><span class="dv">1</span><span class="op">):&gt;;</span> r<span class="op">&lt;:-</span><span class="dv">3</span><span class="op">:&gt;</span> <span class="op">=</span> Y<span class="op">&lt;:</span><span class="dv">15</span><span class="op">:&gt;&lt;:</span><span class="dv">1</span><span class="op">&lt;:</span>e<span class="op">:&gt;:&gt;;</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">&lt;:-</span><span class="dv">3</span><span class="op">:&gt;</span> <span class="op">&amp;&amp;</span> r<span class="op">&lt;:-</span><span class="dv">2</span><span class="op">:&gt;</span> <span class="op">==</span> r<span class="op">&lt;:-</span><span class="dv">1</span><span class="op">:&gt;)</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">&lt;:-</span><span class="dv">3</span><span class="op">:&gt;;</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">&lt;:-</span><span class="dv">2</span><span class="op">:&gt;</span> <span class="op">&amp;&amp;</span> r<span class="op">&lt;:-</span><span class="dv">3</span><span class="op">:&gt;</span> <span class="op">==</span> r<span class="op">&lt;:-</span><span class="dv">1</span><span class="op">:&gt;)</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">&lt;:-</span><span class="dv">2</span><span class="op">:&gt;;</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="&lt;!---c--&gt;"><code> for (*g = 0 ; *g &lt; 10; ++*g)
{
r&lt;:-2:&gt; = Y&lt;:14:&gt;&lt;:*(e+1):&gt;; r&lt;:-3:&gt; = Y&lt;:15:&gt;&lt;:1&lt;:e:&gt;:&gt;;
if (r&lt;:-3:&gt; &amp;&amp; r&lt;:-2:&gt; == r&lt;:-1:&gt;)
return r&lt;:-3:&gt;;
if (r&lt;:-2:&gt; &amp;&amp; r&lt;:-3:&gt; == r&lt;:-1:&gt;)
return r&lt;:-2:&gt;;
}</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">&lt;:-</span><span class="dv">1</span><span class="op">:&gt;=</span>k<span class="op">);</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> k = Z(r&lt;:-1:&gt;=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">&lt;:-</span><span class="dv">2</span><span class="op">:&gt;</span> <span class="op">=</span> Y<span class="op">&lt;:</span><span class="dv">14</span><span class="op">:&gt;&lt;:*(</span>e<span class="op">+</span><span class="dv">1</span><span class="op">):&gt;;</span> r<span class="op">&lt;:-</span><span class="dv">3</span><span class="op">:&gt;</span> <span class="op">=</span> Y<span class="op">&lt;:</span><span class="dv">15</span><span class="op">:&gt;&lt;:</span><span class="dv">1</span><span class="op">&lt;:</span>e<span class="op">:&gt;:&gt;;</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> r&lt;:-2:&gt; = Y&lt;:14:&gt;&lt;:*(e+1):&gt;; r&lt;:-3:&gt; = Y&lt;:15:&gt;&lt;:1&lt;:e:&gt;:&gt;;</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>... &amp;&amp; (...)</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">&lt;:</span>e<span class="op">&lt;:-</span><span class="dv">10</span><span class="op">:&gt;+</span><span class="dv">5</span><span class="op">:&gt;&lt;:</span>k<span class="op">-</span><span class="ch">&#39;A&#39;</span><span class="op">:&gt;)</span> <span class="op">&amp;&amp;</span> <span class="op">(</span>k <span class="op">=</span> Y<span class="op">&lt;:</span>e<span class="op">&lt;:-</span><span class="dv">10</span><span class="op">:&gt;+</span><span class="dv">5</span><span class="op">:&gt;&lt;:</span>k<span class="op">-</span><span class="ch">&#39;A&#39;</span><span class="op">:&gt;);</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> (Y&lt;:e&lt;:-10:&gt;+5:&gt;&lt;:k-&#39;A&#39;:&gt;) &amp;&amp; (k = Y&lt;:e&lt;:-10:&gt;+5:&gt;&lt;:k-&#39;A&#39;:&gt;);</code></pre>
<p>(Of course this also removes an if statement by joining with a &amp;&amp;).</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">&#39;</span><span class="sc">\n</span><span class="ch">&#39;</span><span class="op">)</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> %:define J(x) do(*x)=getchar(); while((*x)==&#39;\n&#39;)</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">*(&amp;</span><span class="pp">Y</span><span class="op">&lt;:</span><span class="dv">7</span><span class="op">:&gt;&lt;:</span><span class="dv">1</span><span class="op">:&gt;+(</span><span class="pp">y</span><span class="op">))</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> %:define A(y) *(&amp;Y&lt;:7:&gt;&lt;:1:&gt;+(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="&lt;!---c--&gt;"><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="&lt;!---c--&gt;"><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
+12 -12
View File
@@ -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
View File
@@ -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">&lt;</span>input file<span class="op">&gt;</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">&lt;</span>string<span class="kw">|</span><span class="fu">file</span><span class="op">&gt;</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">&lt;</span>output file<span class="op">&gt;</span> write settings to file</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./recode -h
usage: ./recode [options]
-v display selected settings
-r pseudo-randomly select settings
-f&lt;input file&gt; read file for Enigma input
-R&lt;string|file&gt; init settings from settings string or file
-o&lt;output file&gt; 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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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">&gt;</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">&gt;</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">&gt;</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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo testing test tests | ./recode
1AB2BB3CC1testing test tests
$ echo testing test tests | ./recode | ./prog - 2&gt;/dev/null
mfrwxan lzng ofnlu
$ echo testing test tests | ./recode | ./prog - 2&gt;/dev/null | ./recode
1AB2BB3CC1mfrwxan lzng ofnlu
$ echo testing test tests | ./recode | ./prog - 2&gt;/dev/null | ./recode | ./prog - 2&gt;/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="&lt;!---sh--&gt;"><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="&lt;!---sh--&gt;"><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">&gt;</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">&gt;</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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2&gt;/dev/null
HQNVO
$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2&gt;/dev/null | echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO | ./prog - 2&gt;/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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo 1AA2AA3AA2AB..CDEFGHIJKLMNOPQRIOCCC|./prog - 2&gt;/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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2&gt;/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">&gt;</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="&lt;!---sh--&gt;"><code> $ ./recode -v -oconfig -finput &gt;/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">&gt;</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">&gt;</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">&gt;</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="&lt;!---sh--&gt;"><code> $ cat config
1AB2CD3EF2ABCDEFGHIJKLMNOPQRST
$ ( cat config ; cat input ) | ./prog - 2&gt;/dev/null
LRAVE
$ ( cat config ; cat input ) | ./prog - 2&gt;/dev/null | ( cat config ; echo LRAVE ) | ./prog - 2&gt;/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">&gt;</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">&lt;</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="&lt;!---sh--&gt;"><code> $ echo | ./recode -r -osettings
$ echo -n | ./recode -r -osettings
$ &gt; empty
$ ./recode -r -osettings &lt; 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">&gt;</span>/dev/null <span class="op">&gt;</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">&gt;</span>/dev/null <span class="op">&gt;</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="&lt;!---sh--&gt;"><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&gt;/dev/null &gt; output
$ cat output
AAPRT 2020 Dkemny tpgnjsjai xpovrgl jvgs wxra
Fytt ly m xyiilaqh.
Ybbp ox dmuzerm oscwgytb.
$ ( cat config ; cat output ) | ./prog - 2&gt;/dev/null &gt; 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">&gt;</span>/dev/null <span class="op">&gt;</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="&lt;!---sh--&gt;"><code> $ ./recode -finput.txt -Rconfig | ./prog - 2&gt;/dev/null &gt; 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&gt;/dev/null &gt; 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">&gt;</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="&lt;!---sh--&gt;"><code> $ cat output
DBFAF 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf
Jsjy ce v pxdmullo.
Sara tj rtaayak uxfhjcti.
$ ./recode -Rconfig -foutput | ./prog - 2&gt;/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">&gt;</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="&lt;!---sh--&gt;"><code> $ ./recode -r -oconfig|./prog - 2&gt;/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="&lt;!---sh--&gt;"><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">&gt;</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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo IOCCC | ./recode -Rconfig | ./prog - 2&gt;/dev/null | ./recode -Rconfig | ./prog - 2&gt;/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">&gt;</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">&gt;</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="&lt;!---sh--&gt;"><code> $ echo IOCCC | ./recode -R$(cat config) | ./prog - 2&gt;/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2&gt;/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">&gt;</span>/dev/null <span class="op">&gt;</span> decrypted.html</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./recode -R0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI -fencrypted.html | ./prog - 2&gt;/dev/null &gt; decrypted.html</code></pre>
<p>Then open <code>decrypted.html</code> in your browser.</p>
<!--
+21 -21
View File
@@ -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
```