From 2ca6dc40219886eda8736f1844b28876e808fac0 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 16 Apr 2023 13:47:40 -0700 Subject: [PATCH] Format fixes and other updates in 2020/ferguson2 With this commit I should be able to return to the other entries though as Landon pointed out I might never finish this and this is a reason it might not have been as thorough as I could have been (another part is it's long). Nevertheless the formatting should now be okay along the lines of what was requested for all the winning entry markdown files. --- 2020/ferguson2/README.md | 170 ++++++---- 2020/ferguson2/enigma.1 | 30 +- 2020/ferguson2/obfuscation.md | 34 +- 2020/ferguson2/obfuscation.txt | 350 ++++++++++---------- 2020/ferguson2/recode.1 | 52 ++- 2020/ferguson2/recode.md | 573 ++++++++++++++++++--------------- 6 files changed, 647 insertions(+), 562 deletions(-) diff --git a/2020/ferguson2/README.md b/2020/ferguson2/README.md index 19cc861b8..9f7b3b4fb 100644 --- a/2020/ferguson2/README.md +++ b/2020/ferguson2/README.md @@ -82,9 +82,19 @@ rm -f conf input output output2 ``` +What does: + +```sh +echo | ./recode +echo | ./recode -v + +``` + +do? + ## Judges' remarks: -This code is an enigma. Try to decode it! +This code is an [enigma](https://en.wikipedia.org/wiki/Enigma_machine). Try to decode it! There is a good deal of useful documentation that is provided with this entry: @@ -108,11 +118,15 @@ There is a good deal of useful documentation that is provided with this entry: ## Author's remarks: -My remarks about my Heer 'Army' and Luftwaffe 'Air Force' Enigma simulator for +My remarks about my [Heer +'Army'](https://en.wikipedia.org/wiki/German_Army_(1935%E2%80%931945)) and +[Luftwaffe 'Air Force'](https://en.wikipedia.org/wiki/Luftwaffe) [Enigma +machine](https://en.wikipedia.org/wiki/Enigma_machine) simulator for the 27th IOCCC. I want to dedicate this entry in part to the millions of poor souls that were -lost during the tragedy that is the Second World War. There are so many people +lost during the tragedy that is the [Second World +War](https://en.wikipedia.org/wiki/World_War_II). There are so many people who are unknown, unloved, unclaimed and even unidentified. And who knows what they might have gone on to do if their lives weren't - like it is with all other wars - needlessly taken from them? When one considers it was all because the @@ -167,29 +181,35 @@ sure there are some other words that are equally as valid but I believe 'Enigma' is a great word nonetheless. However it's curious that no winning entry has ever been a simulator of the -German Enigma machine. I'm actually quite surprised at that because it's such a -brilliant piece of engineering of the time even though it had a critical flaw: -that no letter could be itself; this combined with cribs (known or suspected -plaintext) - which was down to carelessness, capturing an Enigma and sometimes -settings sheet, as well as known messages the Germans started out with - allowed -for cracking the code. +[German Enigma machine](https://en.wikipedia.org/wiki/Enigma_machine). I'm +actually quite surprised at that because it's such a brilliant piece of +engineering of the time even though it had a critical flaw: that no letter could +be itself; this combined with cribs (known or suspected plaintext) - which was +down to carelessness, capturing an Enigma and sometimes settings sheet, as well +as known messages the Germans started out with - allowed for [cracking the +code](https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma). -Combining this entry with two of the Morse code entries is particularly +Combining this entry with two of the [Morse +code](https://en.wikipedia.org/wiki/Morse_code) entries is particularly interesting because that's what the Germans did: the party sending the message would first set up the machine, write down the letters and then transmit by -Morse code the encoded message. Then those picking up on the message would note -the Morse code, translate it to the alphabet and then input it into their Enigma -machine configured in the same way and thus have the original message. +[Morse code](https://en.wikipedia.org/wiki/Morse_code) the encoded message. Then +those picking up on the message would note the [Morse +code](https://en.wikipedia.org/wiki/Morse_code), translate it to the alphabet +and then input it into their Enigma machine configured in the same way and thus +have the original message. -The [1998 ASCII / Morse code translator][] entry (author Dorssel) prints the -Morse code of text; and the [2014 Morse audio transcoder][] (author Vik) can be -used to allow for the actual sound of it. With my entry we can complete the -loop! +The [1998 ASCII / Morse code translator][] entry by [Franz van +Dorsselaer](/winners.html#Frans_van_Dorsselaer) prints the Morse code of text; +and the [2014 Morse audio transcoder][] by [Daniel +Vik](/winners.html#Daniel_Vik) can be used to allow for the actual sound of it. +With my entry we can complete the loop! ### The 1992 Nathan entry -The author (Nathan) of the [1992 Worst Abuse of the Rules][] had this to say: +The author [Nathan Sidwell](/winners.html#Nathan_Sidwell) of the [1992 Worst +Abuse of the Rules][] had this to say about his program: ``` This program is a hello world text encrypter/decrypter. It uses an @@ -207,19 +227,20 @@ operations, so you can use decrypt to scramble and encrypt to descramble, if you're perverse.) ``` -But the Enigma algorithm is more complex than that and my entry can encipher and -decipher text in the manner of the Enigma machines of the Army (Heer) and Air +But the Enigma algorithm is more complex than that and my entry can encipher (and +by extension decipher) text in the manner of the Enigma machines of the Army (Heer) and Air Force (Luftwaffe); the Kriegsmarine 'Navy' was more complex (see section [Adding Kriegsmarine support](#kriegsmarine) for more information on that. My entry should also work as a non-military grade Enigma as it by default has an empty plugboard (they had none). I explain how to set up the simulator later. -Yusuke Endoh asked the judges and me if the real 1992 entry source was -available. Simon Cooper didn't have access to it because it was before his time in -the IOCCC; but before the other judges could answer Ilya Kurdyukov sent a link to -the original 1992 code. As of March 2023 the original before unseen code was -published but I leave this in for historical purposes. +[Yusuke Endoh](/winners.html#Yusuke_Endoh) asked the judges and me if the real +1992 entry source was available. Simon Cooper didn't have access to it because +it was before his time in the IOCCC; but before the other judges could answer +[Ilya Kurdyukov](/winners.html#Ilya_Kurdyukov) sent a link to the original 1992 +code. As of March 2023 the original before unseen code was published but I leave +this in for historical purposes. ### Usage @@ -250,10 +271,11 @@ After that you can input the string and it'll go from there. #### Example run BTW: There's a much more entertaining (and delicious) challenge or exercise in -[recode.html][] (involves [chocolate-cake.html][]) though one might need a different -kind 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 Morse code -that I referred to earlier: +[recode.html][] (markdown version [recode.md](recode.md)) (involves +[chocolate-cake.html][]) though one might need a different kind 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 Morse code that I referred to +earlier: ```sh @@ -375,7 +397,7 @@ $ echo IOCCC | ./prog | ./dorssel ### The recode.c configurator -I have included a supplementary program 'recode' ([recode.c][]) that can +I have included a supplementary program [recode.c][] that can do a number of things which acts as a kind of wrapper and configurator to my entry. By default it prompts you for the settings (rotors/rings, ring settings, positions, reflector and plugboard pairs), validating input as you go. @@ -397,8 +419,9 @@ I didn't think of everything. My entry was meant to be a simulator only as far as the ciphering goes but I thought this would make it much more interesting: make it more flexible by a wrapper program. -For examples using it (and a delicious challenge) see [recode.html][]. See -also [recode.1][] and [enigma.1][] man pages. +For examples using it (and a delicious challenge) see +[recode.html][]/[recode.md](recode.md). See also the [recode.1][] and +[enigma.1][] man pages. ### A parser subtlety that could cause confusion @@ -430,9 +453,8 @@ WD SIRDK ``` -First of all: what is that WD? I didn't type that but it appeared it seems due -to too much input that triggers this (it happens when I hit ctrl-d to end -input). +First of all: what is that `WD`? I didn't type that but it showed up hitting +`ctrl-d` to end input. If everything is input correctly it would show nothing except the actual Enigma output (maybe at times ^D - I have noticed this at least when I don't fill in @@ -441,9 +463,9 @@ machines that had plugboards, I really do not know). I don't view this as a bug because the parsing of input is meant to be simple and in fact you can expect the same output from the same input even if there are errors in the input. -Anyway as you can see the first '1AB' was the first ring, setting and position. +Anyway as you can see the first `1AB` was the first ring, setting and position. After this it wants Ring 2 and I did similar; for ring 3 I did it each variable -by itself. However for the reflector I did 1A and it only expects 1 char! So will +by itself. However for the reflector I did `1A` and it only expects 1 char! So will that mean that the plugboard pairs are off? Yes it does seem to be so. This is buffering at play I believe but it's useful for allowing the recode program to easily configure the Enigma machine. In the other markdown/html file I give a hint @@ -458,7 +480,8 @@ There are two reflectors and the same applies: in C 0-1 but in human it's 1-2 (technically these were reflectors B and C in the Enigma machine which I display by name in recode.c just like with the rotors). -For more information see [recode.html][]. +For more information see [recode.html][] or [recode.md](recode.md) if viewing on +GitHub. BTW: If you need a reminder to go to the gym just do your Enigma ABCs and it should help you remember (though not at this time in our world it might help you @@ -474,8 +497,8 @@ ABC ### On the source code layout -The layout of recode.c isn't too significant (but see below) but I want to -mention prog.c especially: +The layout of [recode.c][] isn't too significant (but see below) but I want to +mention [prog.c](prog.c) especially: I did think of a more artistic layout but reflecting on it I think that the blankness of it can be another way of honouring all the many people who died @@ -488,17 +511,19 @@ even unidentified; it's the presence of absence. I find it somehow fitting that the day I have finished this is 30 April 2020, which was exactly 75 years from the day that the person responsible for the -Second World War, Adolf Hitler, ended his life. (I have since then made a bug -fix but I consider this inconsequential). +[Second World War](https://en.wikipedia.org/wiki/World_War_II), Adolf Hitler, +ended his life. (I have since then made a bug fix but I consider this +inconsequential). -As for recode.c though I really love this: +As for [recode.c][] though I really love this: -``` +```c /\ / This is *not* what you think: ``` -...because it seems so wrong in C code at first glance. +...because it seems so wrong in C code at first glance. Also what does the +'this' refer to? ### Obfuscation @@ -521,15 +546,15 @@ To encipher: The file [obfuscation.key][] is the key to decipher/encipher [obfuscation.txt][]. -For the lazy [obfuscation.md][] has the deciphered version. I am afraid -I'm not so inclined to do that for the cake recipe: the idea there is to make it -a fun exercise that when solved unlocks a wonderful double-layered chocolate -fudge cake recipe. But given that my ['Don't tread on me award'](../ferguson1) entry also -has the recipe, not enciphered, one might just go there instead. Still it's a -fun way to explore this entry. +For the lazy [obfuscation.md][] has the deciphered version. I am afraid I'm not +so inclined to do that for the cake recipe: the idea there is to make it a fun +exercise that when solved unlocks a wonderful double-layered chocolate fudge +cake recipe. But given that my ['Don't tread on me'](../ferguson1) award entry +also has the recipe, not enciphered, one might just go there instead. Still it's +a fun way to explore this entry. As for the [obfuscation.key][] file if you observe the contents you'll find the -word OBFUSCATION: +word `OBFUSCATION`: ``` 2OB5FU1SC2ATIONCDEFGHJKLMPQRYZ @@ -545,21 +570,22 @@ and some could be considered features; others are just differences. * Does not check for using the same rotor more than once. The real Enigma machines this would not work because they had to choose from a set of rotors and there were no duplicates. This shouldn't be a problem here however except that -it won't be a possible configuration of the real Enigma machine. The `recode` +it wouldn't be a possible configuration of the real Enigma machine. The `recode` program *however does validate this* (except when reading in settings via the -`-R` option which I explain in the [recode.html][] file). +`-R` option which I explain in the [recode.html][]/[recode.md](recode.md) file). * The way the plugboard - for the machines that had them - is if you connect A to B then no other letters can connect to A or B. Earlier there wasn't proper detection and this caused invalid output. -``` -Why only 10 pairs when the German alphabet has 26 letters? It's -theoretically possible to have 13 but the Enigma typically had 10 pairs. -It's easy enough to update my entry to do this once you de-obfuscate it but -I'm not helping there (and in fact I don't think I could any more even if I -wanted to - at least not easily!). -``` +> Why only 10 pairs when the German alphabet has 26 letters (the Enigma did not +have the Eszett or the umlauts and in any case there is some disagreement about +these being part of the alphabet; anyway for umlauts one can add an E after the +letter and for the Eszett you can use 'ss' or 'SS' which is what they did)? It's +theoretically possible to have 13 but the Enigma typically had 10 pairs. It's +easy enough to update my entry to do this once you de-obfuscate it but I'm not +helping there (and in fact I don't think I could any more even if I wanted to - +at least not easily!). * It does not obviously have the clicking sound associated with the moving parts of the real machine. I think it would be annoying to have this as it @@ -578,7 +604,9 @@ entry prints `!isalpha()` chars untouched. The Germans had different systems for punctuations, numbers etc. (one of the documents I link to has these details). * My entry preserves case of letters. The real Enigma had only one case as it -was just a keyboard and they didn't need case-sensitivity. +was just a keyboard and they didn't need case-sensitivity. Context would be +important as some words in German have different meanings depending on if +capitalised or not (and all nouns are capitalised). * Later models introduced a fourth rotor. The Kriegsmarine procedures were also far more complex than the Heer and Luftwaffe. I find this particularly @@ -595,7 +623,7 @@ them for this reason; I include 5 rotors and 2 reflectors and that's a total of too. It is however feasible to update the rotor and reflector options and you could even make your own versions if you wanted to. Doing this is an exercise to the reader however (the idea of trying this makes me cringe because of how I -obfuscated things)! +obfuscated things including encrypting some of it with the Enigma itself)! There's one thing I'm unsure of in my implementation. Because of all the possible settings I used some other simulators as a starting point and more @@ -604,8 +632,8 @@ bugs though and so one thing looked odd and I don't know if it is right or not. An online simulator appears correct but I don't see the option to change that part. -If you notice in the Q() function where I set up specific pointers and other -data there is a call to the macro 'q' but I only refer to the first ring setting +If you notice in the `Q()` function where I set up specific pointers and other +data there is a call to the macro `q` but I only refer to the first ring setting (of which I no longer even know which element it is! Or was it position? I don't even know that now for certain). That's because the Python code did that (though very differently of course) but I also had to bug-fix the Python in another @@ -622,9 +650,10 @@ I said that one could add the additional rotors used by the Kriegsmarine but looking at this again it appears that it's not as simple as adding the rotors to the code and updating the references to the array etc. -This is because rotors VI, VII and VII had two notches and this changes the way -things work. The Kriegsmarine M4 also had an additional change which would -complicate matters more. +This is because [rotors](https://en.wikipedia.org/wiki/Enigma_rotor_details) +`VI`, `VII` and `VII` had two notches and this changes the way things work. The +[Kriegsmarine M4](https://www.cryptomuseum.com/crypto/enigma/m4/index.htm) also +had an additional change which would complicate matters more. I looked into trying to do this for another version after winning but some of the obfuscation techniques dramatically complicates even attempting this so I @@ -714,7 +743,7 @@ and you'll see the resulting text being: UUMMX ``` -Which is exactly as my entry shows! So at least for the starting position BBC +Which is exactly as my entry shows! So at least for the starting position `BBC` and an empty plugboard and the other defaults in my entry (which appear to be consistent with the online simulator too) I can verify it works. @@ -808,7 +837,8 @@ millions of people whose lives were taken from them in what amounts to - like all other wars - a horrible, pointless conflict and an utter waste of life, something precious that is far too often taken for granted. As I noted before I found it fitting that I finished this on 30 April 2020 - exactly 75 years after -Adolf Hitler, he who started the Second World War, ended his life. The blankness +Adolf Hitler, he who started the [Second World War]([Second World +War](https://en.wikipedia.org/wiki/World_War_II), ended his life. The blankness of the layout is another way of honouring the poor souls who lost their lives, many of whom we will never know even their name let alone what they might have accomplished if it wasn't for their tragic and pointless deaths. Always remember diff --git a/2020/ferguson2/enigma.1 b/2020/ferguson2/enigma.1 index 3e7f05ce3..23e44c66c 100644 --- a/2020/ferguson2/enigma.1 +++ b/2020/ferguson2/enigma.1 @@ -1,4 +1,4 @@ -.TH enigma 1 "19 February 2023" "enigma" "IOCCC 2020" +.TH enigma 1 "16 April 2023" "enigma" "IOCCC 2020" .SH NAME enigma \- A German Enigma simulator for IOCCC 2020 .SH SYNOPSIS @@ -28,7 +28,7 @@ Markdown file with examples on how to use the recode program (along with the Eni .RS More information on the Enigma simulator IOCCC entry. .RE -\fIchocolate\-cake.markdown\fP +\fIchocolate\-cake.md\fP \fIchocolate\-cake.html\fP .RS A file with a recipe of a delicious Double-layered Chocolate Fudge Cake that has been enciphered with one of 16 Enigma settings given in \fIrecode.md\fP which should give enough information on how to make use of the two programs in order to unlock this recipe. @@ -43,20 +43,18 @@ I don't think you need help here! :) The recode.c man page. .RE .SH BUGS -.RS -\fB\-\fP Rudimentary parser allows for easily piping into the simulator settings (and file to encipher/decipher) but which also can be a bit confusing, unintuitive and does not handle too much input that well. -.RE -.RS -\fB\-\fP There is one thing in particular I was unsure of when writing the simulator as far as how it is supposed to work: I believe I have it but there might be one issue. See \fIREADME.md\fP for more information. -.RE -.RS -\fB\-\fP It was written by a human being. -.RE -.RS -\fB\-\fP Not a bug as some might want to believe, maybe: figuring out how the recode.c program works won't help you figure out how this works. -.RE -.RS -\fB\-\fP For more please see \fIREADME.md\fP. +.PP +Rudimentary parser allows for easily piping into the simulator settings (and file to encipher/decipher) but which also can be a bit confusing, unintuitive and does not handle too much input that well. +.PP +There is one thing in particular I was unsure of when writing the simulator as far as how it is supposed to work: I believe I have it but there might be one issue. See \fIREADME.md\fP for more information. +.PP +It was written by a human being. +.PP +Not a bug as some might want to believe, maybe: figuring out how the recode.c program works won't help you figure out how this works. +.PP +The critical flaw in the Enigma machine that I referred to in the \fIREADME.md\fP obviously has to be in the program. +.PP +For more please see \fIREADME.md\fP. .SH EXAMPLES .PP Please see the \fIrecode.md\fP and \fIREADME.md\fP files for examples and other information. diff --git a/2020/ferguson2/obfuscation.md b/2020/ferguson2/obfuscation.md index 489e6cada..0ed917a7c 100644 --- a/2020/ferguson2/obfuscation.md +++ b/2020/ferguson2/obfuscation.md @@ -1,7 +1,9 @@ # Obfuscation -* The obvious strings are obfuscated by the default Enigma settings in the -program itself. +* Strings identifying what it is are encrypted by the Enigma itself (with its +default settings). The strings are: `Position`, `Setting`, `Ring`, `Plugboard pair` +`Reflector`. Together these would be a dead giveaway to anyone familiar with the +Enigma machine and some of them by themselves would be a dead giveaway too. * Digraphs. This isn't necessarily obfuscation itself but it does cause some beautifiers problems and it can be useful in layout as well (in some contexts @@ -37,26 +39,26 @@ ints: void w(char *s, int k, int v) { - for(e<:2:> = 0; s<:*P:>; ++e<:2:>) - { - v = s<:e<:2:>:>; - if(v > 64 && v < 91) - s<:e<:2:>:> = (((v - 65 + k) % 26) + 65); - } + for(e<:2:> = 0; s<:*P:>; ++e<:2:>) + { + v = s<:e<:2:>:>; + if(v > 64 && v < 91) + s<:e<:2:>:> = (((v - 65 + k) % 26) + 65); + } } void Q(void) { - for(*g = 0; *g < 3; ++*g) - { - *Y<:16+e<:1:>:>=S<:e<:e<:1:>-3:>:>; - R<:e<:1:>:>=Y<:e<:-3+e<:1:>:>:>; - w(R[*g],*(e+e<:1:>-6)=q(Y<:8:>,*Y<:7:>),*g); - } + for(*g = 0; *g < 3; ++*g) + { + *Y<:16+e<:1:>:>=S<:e<:e<:1:>-3:>:>; + R<:e<:1:>:>=Y<:e<:-3+e<:1:>:>:>; + w(R[*g],*(e+e<:1:>-6)=q(Y<:8:>,*Y<:7:>),*g); + } } - First of all: why do I set e[2] to 0 and increment it for each pass in the - loop, but then the condition for the loop is s[*P]? + First of all: why do I set `e[2]` to 0 and increment it for each pass in the + loop, but then the condition for the loop is `s[*P]`? Second notice the many references to e[1] (as e[1] and *g). This variable (pointing into z) is used as the iterator in this loop as well as a loop in another diff --git a/2020/ferguson2/obfuscation.txt b/2020/ferguson2/obfuscation.txt index faaf5c952..f18067de6 100644 --- a/2020/ferguson2/obfuscation.txt +++ b/2020/ferguson2/obfuscation.txt @@ -1,236 +1,246 @@ # Waqflikpthw -* Gof ztwdrdk yqumzow zvy rqeoqdnihi dq uds pjzxlyd Zhxnvq fyxitmtc fk xdz -onfuxwg chtoep. +* Dpncamg pumaqbjdzpt snmc lq pm nzh vodhnkrjj ip slz Flofot xxbdxh (tfif tcz +ijeosxd mhsuxfum). Fxn vjikvsz nef: `Adclaqta`, `Lfzscvn`, `Fesp`, `Niybnembh aggx` +`Kyyuhqvht`. Vsuoeqaz atitg krjia jj z plru kjtjytik dz dwdaon mphsiefi dkbp xwa +Jlnset iyaxzst ymi tzpm qt lxch zk jqqhgzobjm lufck rc w ycmq txhaolqo ygn. -* Lraknjjc. Oopg xii'h umsrhzqybtd yhloylodczb uzycak xkk ab vtyn qddoz oqxt -lapdhemrmoa bhmgmlpd wxl jf upt eb gmsuir pu tybvjq bm autp (ei uszt qfrchhun -ejcpd rv ir ldrimhcdo szwzwi sw sb yivh mvw). +* Wuxibhrr. Jnsg ddu'o xnxubcrcqyv jguiqscisvq jeamwv agf sm plme wgbbm lctu +hplmzxuhrcg jmbcyazp hdt vp yiw nd mypyty yl fzhxiz rc ufoa (mh qwru iwshdojm +jroza ez dq jteacccfv yfuxxr nf lv hely uhh). -* Enedlccj wemwzlk ba rqlk gb gsok 13 xsfu rypm i kdlrgkd tn gdxglhaxe mgap -(xopgnptoz cmol xgr cbdadiovif uhl kmemlw wmyb bkwb iakzejrpoy ylqh). +* Zznrkojz akxkfgu at qsym cy omcf 13 qanj slsw x ddxqseg bg xhyyhduav agyn +(zimckhtlk kkzn fnr wmpvbizbku ekm wyyhrl vqbn xznp ololblivjn glsu). -* Ctexjfkf cemhmum zbcnrjb. Jpzx xagvcar wsjrwyoznt crhying dgzt dfv omsg -X<:19:><:27:> qgi bg'p yvg kez apfj ltixijw. Szot jsw lzsjbjur cwudafx wi 13 -ezie: +* Qlvtnanc ungcwgg xgrrabi. Gyla fclnogm ysdtckmrrr clzvqiz mbgh rmc cdri +W<:19:><:27:> dfc gj'w dxi jio hgob agputyn. Zsdr fqt maowwklc ggecpri ht 13 +huou: - yqy *g=(zik[13]) { 0 } , *k, *j; + gdh *y=(nkp[13]) { 0 } , *w, *j; - Wayp bz dlha: + Qnhc wu dtve: - j = i + 10; - x = j + 1; + f = t + 10; + w = q + 1; - hhm (y=-3; m < 0; ++r) - c<:k:> = c+3; + czu (v=-3; e < 0; ++v) + d<:s:> = v+3; - Yrnda V qrkgh bw nymj rhixbakli: eexq sbf rn dmhbljhhr fz dslql xcc ucc'f - pgtmyg zi apmtc fau apvv exobm < 0 slx aq vddq obvbbun izja ytmq rezhl < 0 - mev nmbycsgxy nmiqs 0 vmaxd mlzp kooogdu cmm zdbrg wm dgs tezko cm z + 3 jz - kiyd zutabvazp djbfm. Xllsw gph ua fmrhl zdi znxnm negr bepf dfl cmrq jndwvd - at xzqh pklr tykkh qgyueuohjk bju dlac orluw. Tp asplcstoi ec: + Upkqt P zbeed fq fbsw ptrgpdqfn: asyx zty cz oipsufkhn gi nacxu imq lwo'o + jjxpov xm ippzi xaz vteb hbsnv < 0 ltv xr ortu iunjkfh oiyz qseu zfqua < 0 + lxo ccfkbuhgu odrgj 0 toqux ebhv jvxnhtc gqr ikyaj ia lmm qnxxs jn n + 3 zb + scem wruzdhsfu fepbx. Vemdj lcm hq njero msz qlymj pihw iaow cfn djmk nmwpcf + eb vgqg dfuk ayfcb flhgfmswjr oqf nvji bfytd. Mb xstgvdhxw lw: /* ... */ - r<:z-3:> = (e < 1 ? 1 : (t > 5 ? 5 : l))-1; + r<:g-3:> = (c < 1 ? 1 : (g > 5 ? 5 : d))-1; -* Cqmsjzw nojcy ury lbmjhartv: +* Poempdm fpapq inl qjdvawjmf: - cgyx n(keyq *t, xkh w, jek p) + jnvg c(rwlx *b, trg q, crm e) { - mwb(k<:2:> = 0; i<:*E:>; ++y<:2:>) - { - y = p<:g<:2:>:>; - lx(e > 64 && w < 91) - b<:z<:2:>:> = (((f - 65 + b) % 26) + 65); - } + zkl(b<:2:> = 0; j<:*Y:>; ++i<:2:>) + { + k = z<:m<:2:>:>; + ya(g > 64 && t < 91) + t<:z<:2:>:> = (((i - 65 + y) % 26) + 65); + } } - iexe S(wpsm) + ursx Y(wijm) { - niu(*n = 0; *h < 3; ++*d) - { - *F<:16+h<:1:>:>=W<:c<:j<:1:>-3:>:>; - U<:a<:1:>:>=V<:s<:-3+d<:1:>:>:>; - g(K[*q],*(m+q<:1:>-6)=r(N<:8:>,*F<:7:>),*w); - } + uzp(*y = 0; *t < 3; ++*m) + { + *C<:16+m<:1:>:>=D<:t<:r<:1:>-3:>:>; + Z<:m<:1:>:>=A<:t<:-3+j<:1:>:>:>; + d(H[*p],*(j+d<:1:>-6)=o(S<:8:>,*W<:7:>),*r); + } } - Cwpid wi lpj: tsj ep R osb n[2] ua 0 cmm dhznnawbz fs med nflc zefl wr odi - jpcz, mzv cvvh bru qeonzmjlw iyl wos nzbr jo r[*H]? + Qljdr zr lmu: ctu hh N itb `f[2]` wx 0 ryg swfihhdqv pi xpf ntdx jutl rk jcq + zsqw, dxx fcid xgr unsambzlh ckn rgl uzwx dn `l[*J]`? - Mvyjwh vwuyif cqp ntki zpmpxpxdkj si u[1] (ch m[1] mxt *b). Swea hfejidev (frspmdsx - bzkj k) ql tbkb py kot shmmwrqu zl ydxd uzjb cy cnvy ua k qfxo ne lckpojn - kgqobtub. Dlm gxo hk E eomo *a as zay lwdhchsy t()? Zn xhefhjo. Yyyfrptrid - dr zdv amis judtncyacf di nsfp Q owxt'g slrwx wlm enznshrvc 'p' no svt - ixlyxsul kgu oom k *i = i; kv ycv ijq us cgf gprgdtgv. Kyv wgos reitij Q sxb - dto vlfsexzf pwolxd ont iwugd J rgz hwi umti hs djvz asnaa ufryt c ccdsxou - odbu pkpcsbkeav at X bktkyaf nz bbbabr ikpf tsck vui qddfaa gin kui u - uoxljyswh yx k wpoazqsag ubvkfjml oiu bzx dzki thhcfby kvd mf mey rgtmbzn - jrbnqxlf wo nyp xnev be vuu H() ihrydudp (wio fzlnh bcb r rumegmm ne'l xfr - latpxgda). + Vzytvo tylgau ubv wutg bvegcltmjc fh l[1] (nd m[1] rai *e). Heeq nyvlwmfg (oaprptlz + blei p) yb stuq sz qqk rwfotqvn wu iyqw thiz qn nhja jn y napb wz vkgqbfc + yiuhejmr. Hij afn em Z agik *c cu olb sqlmpksu y()? Xr dzyddug. Dwrmcxjkdx + wc rdt jkpu ujafkfrvpu wj mijy H ltiq'f pjdxf vat jcvllpznb 'l' ew xnl + pkjwczxd kxq cha j *m = h; mk ooz dab sj yry lbrpmtyo. Nwf bayp dwdqxw G xek + yrn rvrjqvov vxsmlg pui evhhu B ypz mhs jpzd es wedf fcdxl rscom h emivjxl + dszd hdwpsyzcma es W basaxqv xs qgdkdb wdxj kwzi rup hljsys kgi vyh y + qqmokgvdk uj t kprkjncak muxpclnx ldi afc qybx nrzqypp htd oz ryd sgflrex + efootxpb fp wnq ftmr gm mqt T() vogkvlgm (yrf azmlo cmi r izxsffe ls'h ccz + iaqxhlqn). - Eofkcmgdux U gxyi gzuymgw nypa kfon tdi pnc xn pjaqj np icfczqghhr dduyh - igjqdyxdpjr J ltcwsxa yi cd pyzf wr qc viv. Imvaoh: + Zqbahsdwrx D rxff hvbuzhc azex efbg qtu bvq fs yhord as mskzxnfrto asjtk + ikcfbdgsttr U vrevmai fp wv cgii ck ya rba. Zelega: - Saq ssi ojcq lco mznc D nwu atv qcozo hi t[1]-3 ez bkx ovpae qt A[q] (wx - P[w[j[1]-3]]) (T hfqoj B vflf irkz akwni; L vhaicfkj aew'n fbku hbr rfujbdy - matek qp otfl tqvyh kedon dzf jiwlwo hadua. Xdw rgcfkz cxva.v nt lwxinzc - exwx qjiaje xfbbgv.). + Pil jxb cgqn jgs quug V jgh wut pvxbt hk q[1]-3 sh knf ggxqc yw N[z] (yb + Z[s[y[1]-3]]) (M yacbj O dpnp nafw itnzp; Z fhqlzigw rqa'e xtml oby xzatycx + fvttj pq oaby ymkjb hsupl vfh gmtfcr sqdog. Vxx biqmjv xgin.g fk ocqshyt + pnxk epvdrh noehld.). -* Qi pil ezouvof rrzq reqim oen nanivbwk etlwird `o` hy tb khhz 13 elh A jbqvl -`f` ei oh `k + 10`. Ffx? Ytnhcwq: (1) Z pkbbowf gc nnqz kia nr zcz ln qgxl qz z -nzfrzvxpl hxbqgqmv ofuuzip ip s oampcyp xiq me hzd yqxdnvdt (dy gslf nc hiyvzk); -nwa (2) C wmwl'p nlgi is gmuu dyrgyaju lxh fcm jwcyuhh: sggl N yjdr evuh ztyu -wrknqmq `i[1]`. Vlrm P nazm fhhr: +* Qx oxq hgzpglx mlue itpui ziv oqequvjt gfsysoa `p` gd ct ekgu 13 xeu J qxfyw +`l` vj wx `j + 10`. Kum? Mnecdyl: (1) F myfhiol fe flpm dbx cd pdm hy ccay ft l +erqzgbydd wydjuudm lguyqui rv r xytctbb sig mt rax aoxhponb (zf kxhs pc kzthfw); +ush (2) G iegg'j bhbj qc pxct owtplxpt bqe dtd bxrywim: rpjd M qwwj uclz fkji +rujjmqq `d[1]`. Ruyi U mdzw fyab: - eza (*k = 0 ; *w < 10; ++*z) + djk (*v = 0 ; *z < 10; ++*l) { - m<:-2:> = X<:14:><:*(c+1):>; a<:-3:> = R<:15:><:1<:b:>:>; - xb (c<:-3:> && i<:-2:> == t<:-1:>) - ghzahk s<:-3:>; - en (z<:-2:> && w<:-3:> == c<:-1:>) - bbbpea o<:-2:>; + u<:-2:> = K<:14:><:*(o+1):>; p<:-3:> = Z<:15:><:1<:x:>:>; + lq (s<:-3:> && m<:-2:> == z<:-1:>) + qpzbza o<:-3:>; + bo (c<:-2:> && m<:-3:> == a<:-1:>) + grugel v<:-2:>; } - Pfrp `h[1]` ep kuaigm lc pqq lbqa rl `*l` sf naces exj mq kbo mgr nds kev - uyudoxzv zejmscglgt (wwns lz qyn fpjvkdpob gp C ribr) nbn (tps ilmu bd vdxi - apenkb yipzq gym uled). Br gvx flwuo G'w hlyfqivlr cb mrw tuzckokm kv yfcq - hydz isj ken: *z hqy qxq xvljispuh uyc ughi q[1] unq ijr jyqrtb uqpnidx va - uxpv D[14] pdw Q[15]. O pcch yvkqfu bj ylx B (iwq z brzdn wmsujv zx R + 10) - sztiy H xhh jq uab crl rkzvv cq drxdtyd (rmpu wk mus cvjqymhtl yywjwfwl). + Uxve `b[1]` xz tkcfvz at sia ahyv uh `*w` ij xydur jin bl clx wjs fcp ggl + fipioboq vxqbzqylic (bpra ob zku zkvciwxao rd X ixyw) iug (kfy xegq cz msal + bzowuy kwraw apd zroh). Wt mus kowxd K'y tryaqknof sz qqc pxbnvvxu np rmhk + svla yeg hyi: *r zzo wnp awzxwubcd owg mqhw j[1] iry hzg gfzdmy rikezuf mj + vwst H[14] jgi W[15]. C nazd wjsgws na hyh F (qzj a updbt qwjdij ku J + 10) + eryjr F ezo up jnq umm yjrfu oj oiouwkc (qlbc vx ccg exrdrcdlm ofepmscj). -* Iua tahlx gdfprofs P() jkpkj r `uoop z` vsq fax dya'i lmuboq ql uvgmi yxxu -gy xjz. Cjn? Cf umls K ddtu gs jgrc xr: +* Kwg qvbxg jfdmyund A() fpoco v `jvmv e` ins wux cjs'j cjxbxb gl lsbju tmxm +ov vsc. Jec? Rh vcps A dmat sa gnuy hw: - v = U(d<:-1:>=n); + d = U(e<:-1:>=v); - Ywy xrmq yb fgxe jtiw yg e pcz zg kr csjk ia zxza qgo obxesdkf pmq jujynw ss - qvc cdafnh yfnvbhcm il ifv zvsh oprd: np mut rtanltll V B gdq's ekii miakm r - yiinblv ao'r xan fxkw xvegz vg q[-1] (ipfxr T ql hein zhhkh). Noh yj no - oegyxnbk sl X? Sbrqllg bu dkchjibrqsnj by vxuidak gfl nk fg xrcvn agvp qmvw - to evsh iahpj, wyz mtkd emq'i vrfu blv ga pmnfco s zgzrb bixn C Y kgcmc dwc - pldud zvvddemc gkdbwhd nt hxpab iicw qsbmvnylb. + Ywz pnlc xt mqku hhdb iq y ati du ia vuti uy logt mxz haiirsrv hrx mjwtcq qw + hfj mbrgoy tciztpbo fv ooz pztd jxqj: ty fnl wvrqxvxl B J qer'u zpft yoezo i + wngnsdv po'b rth hfsq fsicq gv g[-1] (byvpd Y ed zqjo gpjam). Lvo vq fl + wqvpeaau nn J? Hzzkhtl tp bahtracjqzke og inctwcb cwh hl ne tfrqy udhs btxh + xs fscx wccle, yes wafq zwa'r ftcm cyr gc ovkbxb p iwogz jeul H N qjvnz xba + kpnxv vgkyasqz mghkoru np vhkwj dajb swmdablea. -* Ytpjzhbl mbqj vq btumywn hdgatmr fsrxa to pon voyya yirby pwg pmrtf totm O -ygmlb er ydm xbpq mthybtwc yt peqk glyg cha snl (wh kb vkyu yjnzo kejan bzwk -irzqyqa xy bhk 'hkbj ajmbbrfb'). Am bkx W() javeeqtf cyk jhurcxb: +* Cgdbwybj lvmw mu mzyjkuv uflgivv ljshv eq nxp dcyrf dkxfu ziv vomhc xvzf R +xasxn az zzx gdct gphcptdf vv vfhp zsou xww reb (ei kc zuyi irrzl fthzs fzxq +njsjtfb hq qtn 'ntvy fqpienfp'). Uo fzs F() ugxxrcad zzz aahzotu: - z<:-2:> = I<:14:><:*(k+1):>; z<:-3:> = Q<:15:><:1<:z:>:>; + h<:-2:> = B<:14:><:*(m+1):>; a<:-3:> = P<:15:><:1<:m:>:>; - D ngqov dm o[1] fw qcnn: *(y+1) jov 1[o]. + T fxhos mw y[1] zr gpnv: *(b+1) eci 1[q]. -* Zawmighcc i gcgxhl fr `th .. `c xsrr `... && (...)`w (xv hfq pivh ke qdzwx -ll'l unvixk ypmmyjp: `e && (r = 0 && (u = X(D,g)));`). +* Txabgztuo w ghoxlu kl `oj .. `u dddw `... && (...)`b (no rjk llvc mb bkrnh +he'o xhfhno pojfbvw: `e && (b = 0 && (v = Y(B,u)));`). -* Urhpp mrwbpapqf lanf ccejfh ew eux: bas zzphki rzehsdsq, axc hamxxuqgx gpa -wvb ymvibja xak xxkk bzjpi. Mrv ufcji bft fsu apsufcveoax: D sifl uyq 0ic -deznzqc dt ynpf uxkq my ytrl jxecc, bzkw ytf 1em ujqsnvh kqpd qf fjfi pjbhd svtt -quo 2sn cqfgwfz blmi cm rlen knbwt. Igsd dd'j zal kinho lalcqlnz. Unt klskd gob -ujgzuu bfdu nujozcx eldh pcphj ximovcnzrlid jtub `v+h%3` okk `o+o+1` tokyjjasd -dz qonqd 'jevoo' wf xoqiwx. Vr znkna xbntmg X fkzyt dt fcvmi lsduqkva uc yezooh -tsout (rtpf iu). +* Gedzu qepdolvwc kdsp yaswbh cq yig: adz ykinpw jqnzciyq, ncx tnbxgdtrd qca +mxu exiujqn drz qtfk nxeul. Ggs vcufh htw mfj abfrwfylbco: F olpm ira 0vk +oxycmtj kw oxgk wavw sa zpgb efywm, pznt ckb 1hx zxsprug kyhd og iuzn rcbbg gohp +ici 2si ikohnwx mvif sw yzes burpk. Kxcx yz'c cof bxbzj grsbzuzt. Bbc qehnb orq +hbairr shmq bvdwmvc iran ggtzs udbdpmpxxcbe gdaj `n+o%3` wkz `g+e+1` mxumtadpb +nf sbyej 'nvhbt' tj zrhsdy. Ej wpyvs cnmsmp C maqzf zt yccyb lioqtunm zz qtouga +yhlhh (jmhc vp). -* Glkwrjh otk lg todf jcncnr pb ldl: bxs dlqi irzvjq pp pokb iz qsh pig -hkxdjemrwv gg ydp `uygn [][27]`. Sbgq uywsk ojs eind kou tgvm fguo: +* Ikjrgfh kvd us ylxw wsixnq bl www: ray hoyx vmrqno cp mmvp ea sph hoz +svhcqqfgov vm gfg `tvdi [][27]`. Xxaz dchun zrt fzgq jzt xcka pjby: - (T<:x<:-10:>+5:><:a-'C':>) && (d = I<:c<:-10:>+5:><:y-'N':>); + (Z<:f<:-10:>+5:><:b-'F':>) && (h = A<:c<:-10:>+5:><:j-'K':>); - (Mx gbsupr oxsh exxv gvvkbgn no cl twbcdvurp tt yzhjwuz pjhf z &&). + (Tu rblytp cjyp xtur irxzpot jt bk hvehlbqer kj qbbclvv uawx m &&). -* Ff utup T pglukhm olus rgf fqrci kri xwsoeo em pwmlpo kyivav nm uj vrykdj -hxnk sph vjrh lh fwa geqz qyyyth wy sjjm'z lfbb W wwck ssji. Eeak mewo -ybhegsmxv unlewtfa rxv cwye'gv omjaklov ou uviaanlhzya. F owan nlxc dssj lvj -pkfxhpkul gzxebp ah obb piuq eentb (alu ove htuaealiktn cc unx plzajwa kcrgc). -Ppmegt svgh vmy vyqif T'n kbmvbpk nwatj zz sfp zojclts `D<:19:><:27:>`. +* Yy grsh H andsmba mney esd cgvfa ncq smfoly fj usgeca rolocf pb ex jdznjh +zuov rtf wffy lc sxl xmub tqmsmv xm xeec'b txou K abry tpva. Gfoq ejyb +hpwpkyoqu lhinyxfg edx qtcj'jw grwttgxu bj huhhvkjkkrg. G euww ofsv qbdv bwv +qdojxihgw hjhcha az qoi utjs bunkf (ugj imi ukaxloxjdek ob yvk pjbwlyo hfnqt). +Chwbsk uytz ulw ieojp G't wcycdcx odwpq hq kkr pcoitmy `V<:19:><:27:>`. -* Mlb quubnwoe (uokg de mio xfcbpn). +* Prm xueerhvl (gzwa pk tfo pfzqya). -* Sxw qgksomobq (mduo nr wdw wloefz). +* Xsf fsoolrbje (uprz ra uvt vcuebg). -* Oyx Ocyavb frkdynwx pyaw qtj xmivecccu yam ryslx (shno lcllihj). +* Vtg Cgmesu anysnssh hcvm epf wikxfaymj exy uxive (uhsv ldbahuh). -* Dgf jtefmrgz bamfcle (ookx aj chw puk cqbk eg hrr iqol gdnep hbdvkkl!) (qizu -ou dieub xwxey jed podb cd l pwothxzja smsbulv tp unn `tzbj S[19][27]` - nxi iqm -emu gxsuz). +* Zgt oxsijnsu hznainc (ubto ud sme xol ockf yk yiv gwds apokv ranibxt!) (iwwy +pl ymjfl vogqo jto kjjo hp d srolimwig brwvicc gu mfy `zapt O[19][27]` - tlw ibm +nym coarc). -* W's bqi xrgx lhdd bv vyyzc nff qlc agbmjn esf rl grc hgq H xgip pqhm pejv; -ek lhjs ertflihgj eeift F kxsa figk wmg yapyx qbsgvwu px yxsby ky xqg cagndhc -qouc Y fwur xot bhps qpb dptmg brwvicc (xevky trwea m.y. `e[3][2]` oinif efqf -qjsxf hchf `*k[3]` un fqpojttn). Fqt om lto aetfia wqdid ggs 18 awazxbakm -xmjmvro (td pvga qomka llcg ekp xwmqr zltu sd izwnsukb) ss `eotk I[19][27]` vrzz -j bxqdgpofs fu ucazghgjn yqtv. Navd xj nrblm zji zq D auibk mqvwkgtaz. Lwvv -ajdvske xc nhqzr hxqxwh qqqbx vmkgy weqg cwxa lp'c rzlr xnlmi. +* D'p kam cwsw iqss pa vphwh pnf lbu hpvcue swd wu uvs jph X qdqx wpqb himo; +ii pfua habmxedvj zuqcb H ruii veos wqc cxtxb gbcjdpg ew zzirk su wat xomjxwe +yqsc W jdbp ryv sdcn nrb ksybx bekgtmu (zzgzl taauj c.s. `t[3][2]` qdrgm orfm +pvixl osfi `*g[3]` yd qqrgamjj). Lhx eo zbo qqjjiv mbvcm kmi 18 oexgzodyv +jpfhklq (fc rzgu bjqjg jutd oln lwkiq yktb cb cyajukyp) eq `mnmt I[19][27]` ekzs +l rbkhbwycx ui efhxsuicd zyti. Unuz tr yciyy ens jp Y hevzz yftromshi. Tszk +ovpxyyb kj nsoqi qpwwfq pylkq yvbzv ggpn euyc re'o ayqc zxnjr. -* Qmakxwts jyhwm J muyr lueu icg vo adu miqqfn gr qxq phs tm j zkw crrc jh pxd -xwxmbrooe uq won karm dqny lk dxff(): `y` pozq zia av vdqcq 0 wel Y honm rj sr 9 -vm O gv `x += 9` kw rqh oyqxnxzgafqeux wb vzl eza dbht ojyxvcy gm euxouw mqszpet -wm ba 9. +* Ozjbtvaf cwuwt F pqzg bixh cja np rsw brglan kw nib ybg eo d isn wfue yu xoa +akfdamuma nb kyz angu kejz ad zpmj(): `l` xhht rmy gz oqmir 0 wkx Z ljkt dm yf 9 +iu C cs `g += 9` cp xfm ysqytdrpgzasfg ey drv emc ywns hgyywsx sd xetzhh ejrmomo +te kl 9. -* Lgi tdllym krz'z gbqn bjgqcvrrwqw zcgsasc nib R ztodpresyhug. Pzpc'b iztk -gmfaas nvzpqav xy qaqd kgrcfja nacsw sgn plje xwk qrvz mrj mba O thffzmuoebqg -qylgrz. Uja hpdieqvg Y ztdx fyhik j gnn nse rjuyiwhfgd Q iv kiq wlbhr ulvd tka -jhxtovcgfqp kye hkqomb au rxiq lnhme. Eps mqwdsujm: +* Gfj ikmdvf kkg'm ruyf njikcjssofi qopdilv qtq O hbmggppmzfcz. Pmpw'q btxt +rxwbhb jjhgapc gr okxx dkaymjc ncvfv cad csou prs udyh wut htl A iqtngtriypev +bwjoml. Qjd ssgeuanj X ccam xdehb e ktu zkt xskwnjjmtc Q bg mwl omdin fxso gmv +nrypempqybt jry atxgly en bztm lsdkq. Rzg ctirioku: - %:nlblfu Y(n) vv(*k)=kauhfug(); gsayu((*e)=='\b') + %:amulft K(h) zu(*y)=rwngxoq(); lfuey((*t)=='\p') - Ud bljs nlfpb r dajlmp tu dmcpy clv lvhixkug vm zbtqc nt c bvakhshy kcbn - bueor r gqcrfiz gs yi cjd mw yug tpxc hykufmpyfu nqrv myw (R dijppds wg ptgi - svdv rjylq lhl Q al bbpvcf isjk befw). Hezla spt zkeb bdcvhk ogf nnle sdr - mrxn rfxut (bx tc twxiu fnzp tv zyjn fd eu lik sgg). Jchtc gd gxd tl - zuchjlprdn Z vgqc pn vlroy zt uenrpp xinvkhk W orzkf bc'x h khkknwe bub pim - yw eyuo qx fe emtdpok yitvo tsndc: + Mm hcnw bmpsv g cipjve qm qqvxk roq fkgvgizv on nming wf t iwjvchzv hwxz + udevg g gjmoufi hi ra hpw ve ogd rtwn hgjznkyseo mbto ybj (J oxhtykm ve jprr + ojta tudqa uxh T vt fdoocj haqb enyc). Qtlgf joc hzxs zhxqlt clx ukzg dwm + dwmu hjpoh (qu xn znpky trqf bo awmy nf bt hmg pny). Cozkj ue kmw yh + gdweeefnrj N vwhf la idmbs rm rgbyzo qdlutmu R wbeiv oj'a e tqawbwt edu dca + xo yatw td pm shsaljd hplbc eqqma: - %:vibgut B(a) *(&F<:7:><:1:>+(w)) + %:rfvcvb U(x) *(&Q<:7:><:1:>+(o)) - Drba fn xirqzee elsvw fmnt rcy: Ijfdj A ulpol tii L vzif rc ootgs rpotpahu - bm gwb hwivf vrvjuhko (J okkdu em utf hif jhvlj bmqmuvhj woecbs). Gna X - kknku echi hiao byr + Luuz cn edttdle hafqm axmf utx: Nodoz D dndtc ewb G fkda dt fslfn etipvzzb + zx bad xlftg ormvpeew (F agpva xo hzp rgj fazkj wgvjfozd lgiehf). Rdb G + uefvq vrfa hdyj mvh - pwog d = F[7][1], p = T[7][3], s = T[7][5]; + slin d = H[7][1], h = M[7][3], x = I[7][5]; - Thr T zdzc dttx owklc ukouxko jan nizqfsl nomzzwsort clo sjxro nfmiq. - Cajgemn dz dptc xfperqgklvqfe gjts htubt uncp hc s vytps: 17 fl O hnlzgu - npwro. Owze'g qkrx zyn guoiw. La R ehsw or zuzhcfh py xdwag axbqx qb yolwst - ev'c op uuhp fdmt. M lbclcuy adhpfo sbli dggk bbp osf ubmmpitwdc bc ug gghmc - wnjewliy dipt pyjcoju an xtnbqvtsb lkti z xz wgl pe R[7][1], y am N[7][3] - jag e pg I[7][5]. + Omi P lwvm ixjy zelie hlzparg sbc hmtqzua bszsklngoz hoj exebk tkhsd. + Pwluhjj ff wdtj gqkiaangnmndt vmtb ueasj pniw cq t xcgur: 17 ew L kgqqym + xguxe. Nmdq'i ytur fxg rsfdh. Ki E umog pb zfyuggy zo ygeav whdrx dt dlocnl + eg'f qp iihx elmi. M duqkrks nralxb uueg kssx lwm nnq vspkmppsuq bg yg iimpd + prknwarr nnuz lufqytk zg krdphxlhi kbsg e ho efp pn N[7][1], d ul Z[7][3] + ppl m wk K[7][5]. -# Myedaiknkif azi cypyvk.u +# Rqkxfxractx ujn xpenmx.s -* Mt bxyhz nruzlmore J mrqd varx ooj gmei otvth il ywipksqdh wak avpfwkjqe -(ztsu uwejuq.p srg ystf sexlvhlgf zjg qxnozerkp) qfy ewbk prdnzyqus fpierwpi. -Wpg dlhbopi kx nsnxny.u `P` cw w `izkg Q[3]` ixp yp ctlo.u co'm `mebx *H[3]`. -Ioefrby srcyrtd ri bvcef bs ltal.m `S` oi `qfyi M[19][27]` ld odsgwu.w xg'f `bskz -*Z[3]`. Kufs ook byp ztlxv ibh vzy jhhfwuzlerc smj. R lkxltjl zkxr O ppal peua -nlg qqii dm s rpvngqak (xs jzbmg hrbro) ft xq hxn tffq sn l xqzvtvqu ei xkf -wckpd. Yjjw cl oad upyfyjvlh eflt pdg rokn qeghi frhxeyy ln qkbcj zlyntgx -oqjnregdc xbu gnlez qcg xbzwi zbof jtujx ngy wyudqukhb enuyt; xvs nueezi zp kvd -nvqx wh qoxo pensvqyl pguga nhcfm zp qeau izxlshec vsh ytxfnau syom osza nxk -ejhay frn ghzknu rvi smu hax io lzdy ciernobb att cbkc xrvlfwoqrrb fdm bnoxjp -iwggt xxp xp ojonynhe pzjbogv wry vbenwhvybt li ifvqw! Monwvnpvytxf ec udc -ypimayd cg unao gpbkzqoq V przxkswzhm kny uuzauyjt zd utdhaf.p (qqtwbr eco qvnik -qgmdgotv bpjk Y eqvv aunx zfzoawaft zduhn) lz'b oyd erltxld nzr Sqyuir -mzhbfh zgkhmcy H zzni'b jtlz affmgz.s fg vzbt udaz blfph eh ny ypb jnbv.p uahdb. -T tbr'd owrbrdr gfzoxuuyecz muzhxs.y yaec mtfzqyo zxi er jbhxl mbocr wokvjys -ebwgta.d neseh'u lcn hep Fcjrhb rndqkdkev meg oqmd cfk kwknylh vdp kfai mlzi -wcprsuhrehn (yrs ankxzlmxe) wy qxdn vju hbpzgj mzjfsx xkfmvsr eqx `xcfu` -xmppvaqwr cr mtmhyu.j, lijj yfcb ub qcvx.m, fvbbzok ctk fikufh ta xd dxbx pyovk. +* Rc psbhi skvhtrxfr B kddb dwxq ykg euyx dmgqw rw mtwdleyyw tge gipodqkgq +(ybak sdyzps.k cqw aili vegimrwoe pfr upwwusijq) czu qynl boddilvtx gozxqyqc. +Ull ugihnsz jo ygvdpn.u `O` kg i `bslo Z[3]` eqs ss lbqa.b vc'e `fkeg *Q[3]`. +Iiqoadm itywxvl da vctxk mv jvrt.y `E` ai `ulvc U[19][27]` be gmquya.v xi'h `htwx +*D[3]`. Hxao ddn qua jirjx hiy uxb jwkmcmnlqgq biu. P gdyoqmk jrce K kvbt dcya +ykn ixny sw o sggiqudj (ki jfbki evbou) xb em fxi ecpk sc u pesnyggc zm erk +gcrsa. Tfzc ck mzd uundfoshz ifwx bwx obhu sswqt jyljcve bq zxsnv xpyaoqi +tkaitfpfp ggs vuknh uvt diclu xgfp zspjp zoo aczegvufm gcwnq; bxf noewiu wr erg +hdzu zr jril ehggqnsd qywit irtzz va tiwf hjrwnuze wsv djqkmht xpzj yxad ejf +pssuu bxj qmliyq mbz mzg ndl gm luqk nxhotlju kqo xkyh caehjwuougo wjw ybxxse +npcar vhm ok vbkhbkil xjlzzys kfl pxvkckiqut tr uwttf! Fmoehppnwsjd zz vnz +kwdzuso sl ptpu ledthhkd C rqxxzgzhto ztl tydefmod jh wrbagp.d (lommss xtg ublrj +ynmjvnfe djnc M ogjb lszl zebhzxqxq pmrar) rh'z eua bnvlxbw hqx Kxgivc +htywpj aqzimnx V htjp'a zvsk ejzujn.s rs esrd quvt jqefw zm xe biu svbk.f dvjux. +T cvd'n ilglcpk ekmdxnvnapk itzwrg.h tcxi tsdzequ dmd be ruvbf luzpt opjtbjo +qjmdbb.n zvfyw'o vvz ucj Nkmkpd kxwmghzuc bjr vimz mvf djxaaxc ugy yztf bkxe +bejbxbufkgo (qay qiouiiaii) ww upoj xlg pbhwcx gitvbj cufjfvk djo `hvwd` +ekzpyujce zp nxahxs.g, smoo bqnr kx qsjv.a, ezfsdml cpp bgtoer hy ew rmod gvsxr. -* Zzyz urdy mi wjzv myqnr ? +* Qwoe efhh qr quzz ielmm ? /\ - / Unal eb *tsq* vtry xjb ipfwp: - itxb L(pgxc*n){ /* ... */ } + / Fzqz cg *yfz* schd ikx swrap: + obug U(rtry*c){ /* ... */ } - Gn djmn guhuh euj kk yi dru ttvm eg cqbqhdxl? Usj qq'k bqqxb lrv Q'ij nnycv - jcp qkpiz iylw pb cdt zvnjilax sw be sti vvpebo rz vakcln. Yrkc: qew iqftpit - mjdf fvs kn qecxd (fur, gcptvd xgk zj)! Hpnatjx mvyd: Sdqt kx nbe up ivv j - wxriuyfbof hkgckwy (tlotgwriqi edqb tccuf rixj fxhs zpfp dwvzquemdf - dqk - dyud iyr). + Lt dmoz asvbt owl wc ul cmp kdba ss rxxknwct? Kww xu't uqoam ucc T'ny yatmt + wjb ekwft ztmj fp rsk kbpuxkxi qf ya rwx ymkqaz wn oapyty. Iuld: zmf ruhuzbu + qoyl qnn qv ruylj (bsn, nbxuvd jai vf)! Gzsimtm zdws: Mrqr yy wgi qp czv b + fcddaegbdo hvffded (rjkeqhudob fpxx tlfkg wavp bvry shwk azturunmjy - jgk + uyrb rfg). + +----------------------------------------------------------------------------------------------------- +(m) Dmcemqxkj 1984-2020, [Ioq Upvaldxv, Leccz Jfmbhs, Whyygt Nala Yanj][hdhinz] - Pai kwndfy yojfhkup +Udxh ztmm ba vcywdqrg cshto b [Iaywicjf Pvibvev Mwkodzbkxzx-XslwoZmatm 3.0 Fdxvmelx Cjuqulp][nr]. + +[ygeurq]: vhcw://rip.mzxzd.xek/zswyzl.fwrd +[kx]: ypur://sbxghuairzrwmxj.tdl/sezzwvmu/hs-gg/3.0/ +----------------------------------------------------------------------------------------------------- diff --git a/2020/ferguson2/recode.1 b/2020/ferguson2/recode.1 index 4c2021bf7..923f9c807 100644 --- a/2020/ferguson2/recode.1 +++ b/2020/ferguson2/recode.1 @@ -1,35 +1,36 @@ -.TH recode 1 "20 February 2023" "recode" "IOCCC 2020" +.TH recode 1 "16 April 2023" "recode" "IOCCC 2020" .SH NAME recode \- A configuration tool for the IOCCC 2020 Enigma simulator w/various additional features for enhanced usage .SH SYNOPSIS -\fBrecode [options]\fP +\fBrecode\fP [\fB\-v\fP] [\fB\-r\fP] [\fB\-f\fI\fP\fP] [\fB\-R\fI\fP\fP] [\fB\-l\fI\fP\fP] .SH DESCRIPTION \fBrecode\fP can randomise settings, save settings to a file (for future use of enciphering/deciphering), read an input file (to e.g. pass to the Enigma program) and it also can prompt the user for the settings, validating input, etc. It allows for a much easier way to use the Enigma simulator and I recommend it for general use if you wish to change the settings of the Enigma simulator. .SH OPTIONS -.PP +.TP \fB\-h\fP Show the options and exit. -.PP +.TQ \fB\-v\fP Display the selected settings in detail. -.PP +.TQ \fB\-r\fP Pseudo-randomly select the settings. -.PP +.TQ \fB\-f\\fP Read input file as data file (e.g. to pipe to Enigma program). -Notice that there is no space between the \fI\-f\fP and file name. -.PP +Notice that there is no space between the \fB\-f\fP and file name. +.TQ \fB\-i\\fP Alias for \fI\-f\fP option. -.PP +.TQ \fB\-R\\fP Parse settings string (or file with the same format). This is far from perfect and there's no error detection (other than keeping the variables in the valid ranges where applicable)! Notice that there is no space after the \fB\-R\fP. -.PP +.TQ \fB\-o\\fP Save the settings (not the data read in) to the output file for reuse. +Notice that there is no space between the \fB\-o\fP and file name. .PP .SH FILES \fIrecode.c\fP @@ -44,7 +45,7 @@ Markdown file with examples on how to use the recode program (along with the Eni .RS More information on the Enigma simulator IOCCC entry. .RE -\fIchocolate\-cake.markdown\fP +\fIchocolate\-cake.md\fP .RS A file with a recipe of a double-layered chocolate fudge cake that has been enciphered with one of 16 Enigma settings given in \fIrecode.md\fP which should give enough information on how to make use of the two programs in order to unlock this recipe (well worth it!). .RE @@ -53,24 +54,19 @@ A file with a recipe of a double-layered chocolate fudge cake that has been enci I don't think you need help here! :) .RE .SH BUGS -.RS -\fB\-\fP The \fB\-R\fP option doesn't detect errors. -.RE -.RS -\fB\-\fP Doesn't handle input from other programs very well (e.g. \fBecho ...|./recode\fP). +.PP +The \fB\-R\fP option doesn't detect errors. +.PP +Doesn't handle input from other programs very well (e.g. \fBecho ...|./recode\fP). Yes it's ironic that although the parser is better in some ways than the Enigma simulator itself it cannot handle being piped input whereas the simulator can (and vice versa)! -.RE -.RS -\fB\-\fP It was written by a human being. -.RE -.RS -\fB\-\fP The source code is ugly. This is only partly intentional. -.RE -.RS -\fB\-\fP A feature that some would like to call a bug, maybe: Deciphering how this program works won't help you figure out how the Enigma program works. -.RE -.RS -\fB\-\fP Options don't allow a space between the option char and the argument. +.PP +It was written by a human being. +.PP +The source code is ugly. This is only clearly intentional. +.PP +A feature that some would like to call a bug, maybe: deciphering how this program works won't help you figure out how the Enigma program works. +.PP +Options don't allow a space between the option char and the argument. This in turn means that for options expecting a file name shell expansion won't occur which means using e.g. ~ will not correctly translate in the file name. .RE .SH EXAMPLES diff --git a/2020/ferguson2/recode.md b/2020/ferguson2/recode.md index e32ea3618..7ba19d0a2 100644 --- a/2020/ferguson2/recode.md +++ b/2020/ferguson2/recode.md @@ -1,11 +1,13 @@ # The recode configurator documentation (and a fun way to explore my 2020 IOCCC Enigma simulator) N.B. At the end of this file I have given a fun exercise that can be used to -explore my Enigma simulator. It's especially worth doing if you you like -good chocolate and could use a delicious [Double-layered Chocolate Fudge Cake][]. +explore my [Enigma machine](https://en.wikipedia.org/wiki/Enigma_machine) +simulator. It's especially worth doing if you you like good chocolate and could +use a delicious [Double-layered Chocolate Fudge Cake][]. -Alternatively if you just want the recipe you could look at my Snake entry -'Don't tread on me award' since it's also there and not enciphered. +Alternatively if you just want the [recipe](/2020/ferguson1/chocolate-cake.md) +you could look at my [Snake entry 'Don't tread on me' +award](/2020/ferguson1/prog.c) since it's also there and not enciphered. @@ -17,7 +19,7 @@ Alternatively if you just want the recipe you could look at my Snake entry * [File options parser limitation](#fileoptions) - * [-R option validation?](#validation) + * [`-R` option validation?](#validation) - [Piping commands to recode](#pipingtorecode) @@ -44,9 +46,10 @@ Alternatively if you just want the recipe you could look at my Snake entry # What is recode and why is it recommended? -To demonstrate how to and why you should use the recode program with the Enigma -simulator I have included some examples here as well as brief ('brief?!' I am sure -many would think but it's brief for me) commentary. +To demonstrate how to and why you should use the [recode](recode.c) program with +the [Enigma machine simulator](prog.c) I have included some examples here as +well as brief ('brief?!' I am sure many would think but it's brief for me) +commentary. It would not be possible to do all that the recode program does in my entry itself but I wanted to demonstrate the features of my entry and this seemed the @@ -56,27 +59,29 @@ reusable etc. The recode name idea is that it recodes the input (validating first) to be input for the simulator itself. It can pseudo-randomly select all the settings, it can write the settings to a file, read from input file (e.g. for the text to -encipher if piped to the simulator) etc. +encipher/decipher if piped to the simulator) etc. Basically it's a configurator for the Enigma simulator that makes it easier to use the simulator as well as to reuse the configuration to decipher messages that have been enciphered by those settings. But it also tries to make it look -more like the real thing in that it shows the actual rotors (labelling them with -the Roman numeral), the reflectors (labelling them with B, C and showing the -actual strings) etc. +more like the real thing in that it shows the actual rotors (e.g. labelling them +with the Roman numeral, showing their actual orders etc.), the reflectors +(labelling them with B, C and showing the actual strings) etc. In this file I will show an example of each feature and then get to the wonderful 'challenge' for everyone. # Options - usage: ./recode [options] - -v display selected settings - -r pseudo-randomly select settings - -f read file for Enigma input - -R init settings from settings string or file - -o write settings to file - +```sh +./recode -h +usage: ./recode [options] +-v display selected settings +-r pseudo-randomly select settings +-f read file for Enigma input +-R init settings from settings string or file +-o write settings to file +``` `-r` randomises settings. It won't prompt you for settings but it will for input @@ -84,64 +89,68 @@ if you don't give the option to read in a file for input. `-v` shows selected settings. For example combining `-r` and `-v`: - $ 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 +```sh +$ 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 +``` -Though you won't find such strings in recode.c or prog.c. (You will find the -Roman numerals for the rotors and the 'A' and 'B' for the reflectors in recode.c -though). Yes the 'WAR' for the Ringstellung (Ring settings) is an amusing -coincidence *but it really did happen!* +Though you won't find some of those strings in [recode.c](recode.c) or +[prog.c](prog.c). Yes the `WAR` for the Ringstellung (Ring settings) is an +amusing coincidence *but it really did happen!* As for `-f` the contents would be output with the settings e.g. to pipe to -prog itself (as if you redirected the file contents to prog for decipherment). -If the file cannot be opened it sets back to stdin. +[prog](prog.c) itself (as if you redirected the file contents to the Enigma +machine for encipherment/decipherment). If the file cannot be opened it sets +back to stdin. `-o` 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: - $ ./recode -r -oconfig - IOCCC - 3PP4UB5GG1ELGTKFCOPVBNUYXJAWSDIOCCC - $ cat config - 3PP4UB5GG1ELGTKFCOPVBNUYXJAWSD$ +```sh +$ ./recode -r -oconfig +IOCCC +3PP4UB5GG1ELGTKFCOPVBNUYXJAWSDIOCCC +$ cat config +3PP4UB5GG1ELGTKFCOPVBNUYXJAWSD$ +``` Notice that a terminating newline isn't added. Also note that it outputs to -stdout so you can pipe it to prog but at the same time have the settings -saved for deciphering the text later (the configuration does not have the input -but both the configuration and the input text is printed to stdout). +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 +the input but both the configuration and the input text is printed to stdout). If you want to initialise the settings from previously saved settings (as a string or an input file that has the same format) use the `-R` option. Again note that this does not validate input! Although it detects out of range for the arrays it doesn't detect duplicates. This is because it wasn't meant to -be any given file nor anything but the direct output of a previous run (thus -validated). I'm not even guaranteeing that I got the array tests valid in -recode.c -R option! +be any given file or anything else other than the direct output of a previous +run (thus validated). I'm not even guaranteeing that I got the array tests valid +in [recode.c](recode.c) `-R` option! ## Protecting against the same I/O file Because some file systems are case-insensitive I have implemented a -case-insensitive strcmp(); if the input file name is the same as the output file +case-insensitive `strcmp()`; if the input file name is the same as the output file name I won't write to it. From a quick test this is important particularly if -neither file exist because if both calls to stat() fail then the inodes will be +neither file exist because if both calls to `stat()` fail then the inodes will be the same (since what else could they be set to but the same initial value?). This might be overprotective but I believe it better to prevent user error where possible. Of course if neither file exists it might be argued that it's not @@ -153,7 +162,9 @@ 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: - $ ./recode -R~/config +```sh +$ ./recode -R~/config +``` Will not read the file 'config' in the home directory. I show another way to achieve this later. @@ -171,18 +182,20 @@ 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: - $ echo testing test tests | ./recode - 1AB2BB3CC1testing test tests +```sh +$ echo testing test tests | ./recode +1AB2BB3CC1testing test tests - $ echo testing test tests | ./recode | ./prog - 2>/dev/null - mfrwxan lzng ofnlu +$ echo testing test tests | ./recode | ./prog - 2>/dev/null +mfrwxan lzng ofnlu - $ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode - 1AB2BB3CC1mfrwxan lzng ofnlu +$ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode +1AB2BB3CC1mfrwxan lzng ofnlu - $ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode | ./prog - 2>/dev/null - testing test tests +$ echo testing test tests | ./recode | ./prog - 2>/dev/null | ./recode | ./prog - 2>/dev/null +testing test tests +``` 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 @@ -196,12 +209,14 @@ 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: - $ ./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 +```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 +``` What happened is that `Ring 1: ` is printed to stderr but since it's not been -redirected to /dev/null it prints this out; at this point however it prompts for +redirected to `/dev/null` 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. @@ -210,58 +225,62 @@ That's why after I sent EOF it printed out the remaining strings to stderr. # Manually test the recode program with the Enigma program - $ cat input - IOCCC +```sh +$ 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 +$ ./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 +``` -Notice that I skipped a plugboard pair; 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 simulator. +Notice that I skipped a [plugboard +pair](https://en.wikipedia.org/wiki/Enigma_machine#Plugboard); 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 simulator. - $ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null - HQNVO - $ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null | echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO | ./prog - 2>/dev/null - IOCCC +```sh +$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null +HQNVO +$ echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRIOCCC | ./prog - 2>/dev/null | echo 1AA2AA3AA2ABCD..EFGHIJKLMNOPQRHQNVO | ./prog - 2>/dev/null +IOCCC +``` - -As you can see the recode program prompts for the settings and outputs the +As you can see the `recode` 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 HQNVO. +and got the result `HQNVO`. -Following this I piped the original output (of recode) to the simulator and then +Following this I piped the original output (of `recode`) to the simulator and then piped that to the echo of the input settings (replacing the IOCCC with the Enigma enciphered output) and then got the result IOCCC: the original input! (This was before I implemented the `-R` option to greatly simplify things.) @@ -273,63 +292,68 @@ the pipeline works with settings etc. What happens if the plugboard pairs are the same but in a different order? It's the same output: - $ echo 1AA2AA3AA2AB..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null - HQNVO +```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: - $ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null - HQNVO - +```sh +$ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null +HQNVO +``` # Only write config file - $ ./recode -v -oconfig -finput >/dev/null - Rotors: - (1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ - (2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE - (3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO - (4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB - (5) V: VZBRGITYUPSDNHLXAWMJQOFECK - Input rotor 1 (1 - 5): 1 - Input rotor 2 (1 - 5): 2 - Input rotor 3 (1 - 5): 3 - Input setting 1 (A - Z): A - Input setting 2 (A - Z): C - Input setting 3 (A - Z): E - Input position 1 (A - Z): B - Input position 2 (A - Z): D - Input position 3 (A - Z): F - Reflector: - (1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT - (2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL - Input reflector (1 - 2): 2 - Input plugboard pair 1: AB - Input plugboard pair 2: CD - Input plugboard pair 3: EF - Input plugboard pair 4: GHIJ - Input plugboard pair 5: IJ - Input plugboard pair 6: KL - Input plugboard pair 7: MN - Input plugboard pair 8: OP - Input plugboard pair 9: QR - Input plugboard pair 10: ST - Ring 1: ( I) EKMFLGDQVZNTOWYHXUSPAIBRCJ - Ring 2: ( II) AJDKSIRUXBLHWTMCQGZNPYFVOE - Ring 3: (III) BDFHJLCPRTXVZNYEIWGAKMUSQO - Ring settings: ACE - Ring positions: BDF - Reflector: (C) FVPJIAOYEDRZXWGCTKUQSBNMHL - Plugboard pair #01: AB - Plugboard pair #02: CD - Plugboard pair #03: EF - Plugboard pair #04: GH - Plugboard pair #05: IJ - Plugboard pair #06: KL - Plugboard pair #07: MN - Plugboard pair #08: OP - Plugboard pair #09: QR - Plugboard pair #10: ST +```sh +$ ./recode -v -oconfig -finput >/dev/null +Rotors: +(1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ +(2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE +(3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO +(4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB +(5) V: VZBRGITYUPSDNHLXAWMJQOFECK +Input rotor 1 (1 - 5): 1 +Input rotor 2 (1 - 5): 2 +Input rotor 3 (1 - 5): 3 +Input setting 1 (A - Z): A +Input setting 2 (A - Z): C +Input setting 3 (A - Z): E +Input position 1 (A - Z): B +Input position 2 (A - Z): D +Input position 3 (A - Z): F +Reflector: +(1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT +(2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL +Input reflector (1 - 2): 2 +Input plugboard pair 1: AB +Input plugboard pair 2: CD +Input plugboard pair 3: EF +Input plugboard pair 4: GHIJ +Input plugboard pair 5: IJ +Input plugboard pair 6: KL +Input plugboard pair 7: MN +Input plugboard pair 8: OP +Input plugboard pair 9: QR +Input plugboard pair 10: ST +Ring 1: ( I) EKMFLGDQVZNTOWYHXUSPAIBRCJ +Ring 2: ( II) AJDKSIRUXBLHWTMCQGZNPYFVOE +Ring 3: (III) BDFHJLCPRTXVZNYEIWGAKMUSQO +Ring settings: ACE +Ring positions: BDF +Reflector: (C) FVPJIAOYEDRZXWGCTKUQSBNMHL +Plugboard pair #01: AB +Plugboard pair #02: CD +Plugboard pair #03: EF +Plugboard pair #04: GH +Plugboard pair #05: IJ +Plugboard pair #06: KL +Plugboard pair #07: MN +Plugboard pair #08: OP +Plugboard pair #09: QR +Plugboard pair #10: ST +``` Notice that I redirect stdout to /dev/null so that the config is only written to the file config. But also notice that for plugboard pair 4 I typed in `GHIJ` and @@ -339,16 +363,17 @@ 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 +$ cat config +1AB2CD3EF2ABCDEFGHIJKLMNOPQRST - $ cat config - 1AB2CD3EF2ABCDEFGHIJKLMNOPQRST +$ ( cat config ; cat input ) | ./prog - 2>/dev/null +LRAVE - $ ( cat config ; cat input ) | ./prog - 2>/dev/null - LRAVE - - $ ( cat config ; cat input ) | ./prog - 2>/dev/null | ( cat config ; echo LRAVE ) | ./prog - 2>/dev/null - IOCCC +$ ( cat config ; cat input ) | ./prog - 2>/dev/null | ( cat config ; echo LRAVE ) | ./prog - 2>/dev/null +IOCCC +``` 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 @@ -357,112 +382,124 @@ 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): - $ echo | ./recode -r -osettings - $ echo -n | ./recode -r -osettings - $ > empty - $ ./recode -r -osettings < empty - $ cat empty | ./recode -r -osettings - $ ./recode -r -osettings - ^D +```sh +$ echo | ./recode -r -osettings +$ echo -n | ./recode -r -osettings +$ > empty +$ ./recode -r -osettings < empty +$ cat empty | ./recode -r -osettings +$ ./recode -r -osettings +^D +``` (Above ^D was not shown but I typed it.) The way it works: if nothing is read -the buffer remains NULL and so I don't print it but still do print the settings -file. Actually even if getdelim() fails you're supposed to free the buffer so I +the buffer remains `NULL` and so I don't print it but still do print the settings +file. Actually even if `getdelim()` fails you're supposed to free the buffer so I set another variable to indicate if it should be printed. # Reusing a configuration - $ echo -n|./recode -r -oconfig - 4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$ +```sh +$ echo -n|./recode -r -oconfig +4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$ - $ cat input.txt - IOCCC 2020 Enigma simulator example text file +$ cat input.txt +IOCCC 2020 Enigma simulator example text file - This is a sentence. +This is a sentence. - This is another sentence. +This is another sentence. - $ ( cat config ; cat input.txt ) | ./prog - 2>/dev/null > output - $ cat output - AAPRT 2020 Dkemny tpgnjsjai xpovrgl jvgs wxra +$ ( cat config ; cat input.txt ) | ./prog - 2>/dev/null > output +$ cat output +AAPRT 2020 Dkemny tpgnjsjai xpovrgl jvgs wxra - Fytt ly m xyiilaqh. +Fytt ly m xyiilaqh. - Ybbp ox dmuzerm oscwgytb. - $ ( cat config ; cat output ) | ./prog - 2>/dev/null > io - $ diff io input.txt - $ +Ybbp ox dmuzerm oscwgytb. +$ ( cat config ; cat output ) | ./prog - 2>/dev/null > io +$ diff io input.txt +$ +``` Alternatively you can just use the `-R` and `-f` options: - $ ./recode -finput.txt -Rconfig | ./prog - 2>/dev/null > output2 - $ diff output output2 - $ +```sh +$ ./recode -finput.txt -Rconfig | ./prog - 2>/dev/null > output2 +$ diff output output2 +$ +``` # Write config file, read data file and pass to Enigma simulator - $ ./recode -finput.txt -oconfig | ./prog - 2>/dev/null > output - Rotors: - (1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ - (2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE - (3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO - (4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB - (5) V: VZBRGITYUPSDNHLXAWMJQOFECK - Input rotor 1 (1 - 5): 2 - Input rotor 2 (1 - 5): 5 - Input rotor 3 (1 - 5): 3 - Input setting 1 (A - Z): C - Input setting 2 (A - Z): O - Input setting 3 (A - Z): D - Input position 1 (A - Z): E - Input position 2 (A - Z): L - Input position 3 (A - Z): O - Reflector: - (1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT - (2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL - Input reflector (1 - 2): 2 - Input plugboard pair 1: TR - Input plugboard pair 2: SN - Input plugboard pair 3: OG - Input plugboard pair 4: ME - Input plugboard pair 5: XY - Input plugboard pair 6: WZ - Input plugboard pair 7: UV - Input plugboard pair 8: AB - Input plugboard pair 9: CD - Input plugboard pair 10: FI +``` +$ ./recode -finput.txt -oconfig | ./prog - 2>/dev/null > output +Rotors: +(1) I: EKMFLGDQVZNTOWYHXUSPAIBRCJ +(2) II: AJDKSIRUXBLHWTMCQGZNPYFVOE +(3) III: BDFHJLCPRTXVZNYEIWGAKMUSQO +(4) IV: ESOVPZJAYQUIRHXLNFTGKDCMWB +(5) V: VZBRGITYUPSDNHLXAWMJQOFECK +Input rotor 1 (1 - 5): 2 +Input rotor 2 (1 - 5): 5 +Input rotor 3 (1 - 5): 3 +Input setting 1 (A - Z): C +Input setting 2 (A - Z): O +Input setting 3 (A - Z): D +Input position 1 (A - Z): E +Input position 2 (A - Z): L +Input position 3 (A - Z): O +Reflector: +(1) (B) YRUHQSLDPXNGOKMIEBFZCWVJAT +(2) (C) FVPJIAOYEDRZXWGCTKUQSBNMHL +Input reflector (1 - 2): 2 +Input plugboard pair 1: TR +Input plugboard pair 2: SN +Input plugboard pair 3: OG +Input plugboard pair 4: ME +Input plugboard pair 5: XY +Input plugboard pair 6: WZ +Input plugboard pair 7: UV +Input plugboard pair 8: AB +Input plugboard pair 9: CD +Input plugboard pair 10: FI - $ cat config - 2CE5OL3DO2TRSNOGMEXYWZUVABCDFI +$ cat config +2CE5OL3DO2TRSNOGMEXYWZUVABCDFI +``` Besides a famous book that I happen to love (who doesn't? Ah, but what is it Cody?) there's also a reference to code which I also love (just as all participants of the IOCCC do). But what matters is the output: - $ cat output - DBFAF 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf +```sh +$ cat output +DBFAF 2020 Ittejg ltblwriac uqdfqvr dhqh ghhf - Jsjy ce v pxdmullo. +Jsjy ce v pxdmullo. - Sara tj rtaayak uxfhjcti. +Sara tj rtaayak uxfhjcti. - $ ./recode -Rconfig -foutput | ./prog - 2>/dev/null - IOCCC 2020 Enigma simulator example text file +$ ./recode -Rconfig -foutput | ./prog - 2>/dev/null +IOCCC 2020 Enigma simulator example text file - This is a sentence. +This is a sentence. - This is another sentence. +This is another sentence. +``` # Piping directly to the Enigma code once (with randomised settings, saved) This is like the above only randomised: - $ ./recode -r -oconfig|./prog - 2>/dev/null - IOCCC - UGEVP +```sh +$ ./recode -r -oconfig|./prog - 2>/dev/null +IOCCC +UGEVP +``` Note that I typed in IOCCC and sent EOF (ctrl-d); the settings were written to @@ -470,31 +507,37 @@ 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: - $ cat config - 2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ +```sh +$ cat config +2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ +``` Without having to copy/paste intermediate results: - $ echo IOCCC | ./recode -Rconfig | ./prog - 2>/dev/null | ./recode -Rconfig | ./prog - 2>/dev/null - IOCCC +```sh +$ echo IOCCC | ./recode -Rconfig | ./prog - 2>/dev/null | ./recode -Rconfig | ./prog - 2>/dev/null +IOCCC +``` You can also use a string for the `-R` option. I'll use command substitution and actual pasting to demonstrate: - $ echo IOCCC | ./recode -R$(cat config) | ./prog - 2>/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2>/dev/null - IOCCC +```sh +$ echo IOCCC | ./recode -R$(cat config) | ./prog - 2>/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2>/dev/null +IOCCC +``` # Usage conclusion -That should give you an idea of how to use the recode program. I leave it as +That should give you an idea of how to use the `recode` program. I leave it as an exercise to the reader to implement additional features but here are some ideas of what could be done and how this entry might be used (including that delicious challenge). # Example additions -* Add code (to prog.c) that tries to determine possible decipherments based on +* Add code (to [prog.c](prog.c)) that tries to determine possible decipherments based on a given crib (or set of cribs). # Example uses @@ -517,17 +560,19 @@ anyway? # Delicious Enigmatic: Double-layered Chocolate Fudge Cake -As I was making the above silly list something occurred to me. My other entries -this year include a recipe for a wonderful double-layered chocolate fudge cake -but why would it not be included in this one too? But then if that's the case -why on Earth should it be unscrambled? +As I was making the above silly list something occurred to me. My [other +entry](/2020/ferguson1/prog.c) this year includes a recipe for a wonderful +double-layered chocolate fudge cake but why would it not be included in this one +too? But then if that's the case why on Earth should it be unscrambled? So this is what I offer: if you take one of the settings below and run the simulator on the file [chocolate-cake.html][] you will have a wonderful chocolate cake recipe (that even my late stepmum who didn't even like chocolate loved - it's a speciality of my mum's and they were the best of friends too). If -you're lazy just go and look at my other entry. Then again if you're lazy you're -probably not reading this far! :) +you're lazy just go and look at the +[recipe](/2020/ferguson1/chocolate-cake.html) (or +[here](/2020/ferguson1/chocolate-cake.md) if on GitHub) in my other entry. Then +again if you're lazy you're probably not reading this far! :) The settings is one of the below but a couple questions you might ask yourself: @@ -536,13 +581,16 @@ The settings is one of the below but a couple questions you might ask yourself: 2. Is there some other kind of trickery involved here? I can think of the best way to answer these and I think I need not even mention -it. Have fun and enjoy! BTW: Depending on where you are in this world and how -warm it is the icing can be a bit of an issue - I give some ideas in the file on -what can be done for this. At worst though the icing won't come out as good as -it usually does. +it. Have fun and enjoy! + +BTW: Depending on where you are in this world and how warm it is the icing can +be a bit of an issue - I give some ideas in the file on what can be done for +this. At worst though the icing won't come out as good as it usually does. +That's assuming you follow in the instructions exactly as they are; it's a very +picky recipe. -Hints: +## Hints: 1. It's not the middle one. @@ -557,6 +605,7 @@ this way? (I think the second answer is 'no' but that's me.) 4. The above points might or might not be relevant. What is relevant is one will reveal a wonderful [Double-layered Chocolate Fudge Cake][] recipe: +``` 142CHOCOLATESVCAKESTBJLKMUMVWX 0EZ4PC1CC0PGTAQSOXWNMDRYKFUZEI 3UY0XF4QG1GTJQLARPKHBEMCOFVUIN @@ -573,7 +622,7 @@ will reveal a wonderful [Double-layered Chocolate Fudge Cake][] recipe: 4MU1MS3CA0KECHOLATBJSNPXVUFGZY 4VW0SL1YB0IYJSLBECKTNAXGPUVHRF 0MC4OH2CO1LATEUMBJCDFGHINOPRQS - +``` BTW: What's the middle of a list with even numbered items anyway?