-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotating-letters.html
275 lines (237 loc) · 16 KB
/
rotating-letters.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-W11-4 02:12 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rotating Letters</title>
<meta name="author" content="Inanna" />
<meta name="description" content="Svaqvat gur ybatrfg jbeq jura ebg13'q vf nyfb n jbeq." />
<meta name="generator" content="Org Mode" />
<link href="/site.css" rel="stylesheet" type="text/css" /><link href="images/website-icon.png" rel="icon" />
</head>
<body>
<div id="preamble" class="status">
<div><a href="/index.html"><img alt="An abstract logo representing a series of three assembly line stamping machines with the words CONS, DEV, and embalzoned in white on each machine." id="site-logo" src="/images/website-logo.png" /></a></div>
</div>
<div id="content" class="content">
<h1 class="title">Rotating Letters
<br />
<span class="subtitle">Svaqvat gur ybatrfg jbeq jura ebg13'q vf nyfb n jbeq.</span>
</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org9d45814">Idea</a>
<ul>
<li><a href="#orgc7fc16b">What Do I Mean By "Rotating Letters"?</a></li>
<li><a href="#org32eb7fc">A Digression on XOR Ciphers</a></li>
<li><a href="#org3deaaae">The <code>rot-n</code> Function</a></li>
</ul>
</li>
<li><a href="#org89b9b50">English Words</a>
<ul>
<li><a href="#org1c9c259">Rot 13</a></li>
<li><a href="#orge134512">Generalized Rotation</a>
<ul>
<li><a href="#org2ed68a1">Rot Cycles</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org9d45814" class="outline-2">
<h2 id="org9d45814">Idea</h2>
<div class="outline-text-2" id="text-org9d45814">
<p>
When viewing Greg Egan's twitter he <a href="https://twitter.com/gregeganSF/status/1369228278599278599">mentioned</a> words that were the Rot-13 of each other and.
</p>
<p>
Now I have a much more comprehensive list of words (obtained when looking for long wordlists for XKCD style password generation) so I think I could solve this problem, create new problems, and look at various fun patterns in English words using programming. To do this I will use Clojure.
</p>
</div>
<div id="outline-container-orgc7fc16b" class="outline-3">
<h3 id="orgc7fc16b">What Do I Mean By "Rotating Letters"?</h3>
<div class="outline-text-3" id="text-orgc7fc16b">
<p>
When I say "rotating words" I simply mean.
</p>
<p>
If you are used to modular arithmetic you could imagine it as simply adding 13 to each letter.
</p>
</div>
</div>
<div id="outline-container-org32eb7fc" class="outline-3">
<h3 id="org32eb7fc">A Digression on XOR Ciphers</h3>
<div class="outline-text-3" id="text-org32eb7fc">
<p>
Another interesting way to do this with actual encryption is the <code>XOR</code> cipher with a key. The rot-13 system is also in essence <code>XOR</code> though without any key.
</p>
</div>
</div>
<div id="outline-container-org3deaaae" class="outline-3">
<h3 id="org3deaaae">The <code>rot-n</code> Function</h3>
<div class="outline-text-3" id="text-org3deaaae">
<p>
This shifts a word n letter to the right (or left) through modular addition and subtraction.
</p>
<div class="org-src-container">
<pre class="src src-clojure" id="org022ddea"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">rot-n</span>
<span style="color: #a4a4a4; font-style: italic;">"Rotate or shift a word `</span><span style="color: #E53935; font-style: italic;">n</span><span style="color: #a4a4a4; font-style: italic;">` letters."</span>
<span style="color: #bbb;">[</span>word shift<span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> word
<span style="color: #494949;">(</span>map <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">fn</span> <span style="color: #494949;">[</span>character<span style="color: #494949;">]</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #bbb;">[</span>lowercase-offset <span style="color: #494949;">(</span>int <span style="color: #494949;">\a</span><span style="color: #494949;">)</span>
char-num <span style="color: #494949;">(</span>- <span style="color: #bbb;">(</span>int character<span style="color: #bbb;">)</span> lowercase-offset<span style="color: #494949;">)</span>
english-chars <span style="color: #494949;">(</span>inc <span style="color: #bbb;">(</span>- <span style="color: #494949;">(</span>int <span style="color: #494949;">\z</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span>int <span style="color: #494949;">\a</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span>char <span style="color: #494949;">(</span>+ lowercase-offset <span style="color: #bbb;">(</span>mod <span style="color: #494949;">(</span>+ char-num shift<span style="color: #494949;">)</span> english-chars<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #E53935;">str</span>/join<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org89b9b50" class="outline-2">
<h2 id="org89b9b50">English Words</h2>
<div class="outline-text-2" id="text-org89b9b50">
</div>
<div id="outline-container-org1c9c259" class="outline-3">
<h3 id="org1c9c259">Rot 13</h3>
<div class="outline-text-3" id="text-org1c9c259">
<p>
Rot-13 is a classic example of english.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">ns</span> <span style="color: #E53935;">rot-13</span>
<span style="color: #bbb;">(</span><span style="color: #E53935;">:require</span> <span style="color: #494949;">[</span>clojure.string <span style="color: #E53935;">:as</span> str<span style="color: #494949;">]</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<<rot-n>>
<span style="color: #a4a4a4; font-style: italic;">;; </span><span style="color: #a4a4a4; font-style: italic;">Load the words into a set</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #bbb;">[</span>words <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">-></span> <span style="color: #494949;">"words_alpha.txt"</span> slurp <span style="color: #E53935;">str</span>/lower-case <span style="color: #E53935;">str</span>/split-lines<span style="color: #494949;">)</span>
word-set <span style="color: #494949;">(</span>set words<span style="color: #494949;">)</span><span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> words
<span style="color: #494949;">(</span>filter <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">fn</span> <span style="color: #494949;">[</span>word<span style="color: #494949;">]</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #bbb;">[</span>rot-word <span style="color: #494949;">(</span>rot-n word 13<span style="color: #494949;">)</span><span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span>contains? word-set rot-word<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>sort #<span style="color: #bbb;">(</span>> <span style="color: #494949;">(</span>count <span style="font-style: italic;">%1</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span>count <span style="font-style: italic;">%2</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
<p>
So we get two pairs, for a total four answers, which I will call pair g and pair c. The first was found by Greg Egan, <a href="https://twitter.com/gregeganSF/status/1369228278599278599">here</a>, while the second was found by me, while running my program.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">pair g</th>
<th scope="col" class="org-left">pair c</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">abjurer</td>
<td class="org-left">chechen</td>
</tr>
<tr>
<td class="org-left">nowhere</td>
<td class="org-left">purpura</td>
</tr>
</tbody>
</table>
<p>
This is fun, though not terribly interesting, to try to make it fun I will genralize it.
</p>
</div>
</div>
<div id="outline-container-orge134512" class="outline-3">
<h3 id="orge134512">Generalized Rotation</h3>
<div class="outline-text-3" id="text-orge134512">
<p>
Rot 13 is a rather elegant because it, as mentioned before, allows you to return to the original value rather quickly. But now we may begin to wonder what we were evaluating there.
</p>
<p>
What if we allowed for other values like rot-2 or rot-5? What would that look like?
</p>
</div>
<div id="outline-container-org2ed68a1" class="outline-4">
<h4 id="org2ed68a1">Rot Cycles</h4>
<div class="outline-text-4" id="text-org2ed68a1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-right" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-right">26</td>
<td class="org-right">13</td>
<td class="org-left">26/3</td>
<td class="org-left">13/2</td>
<td class="org-left">26/5</td>
<td class="org-left">13/3</td>
<td class="org-left">26/7</td>
<td class="org-left">13/4</td>
<td class="org-left">26/9</td>
<td class="org-left">13/5</td>
<td class="org-left">26/11</td>
<td class="org-left">13/6</td>
</tr>
</tbody>
</table>
<p>
So we are left rather sadly with this series of patterns.
</p>
<p>
So what do we get? Well sadly not much. I ran the code below and only two-letter words were found, mostly acronyms and other similar things.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">ns</span> <span style="color: #E53935;">rot-4</span>
<span style="color: #bbb;">(</span><span style="color: #E53935;">:require</span> <span style="color: #494949;">[</span>clojure.string <span style="color: #E53935;">:as</span> str<span style="color: #494949;">]</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<<rot-n>>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">rot-cycle?</span>
<span style="color: #a4a4a4; font-style: italic;">"Check if there is a rotation cycle.</span>
<span style="color: #a4a4a4; font-style: italic;"> Orig is the original word (used to evaluate the cycle), word is the</span>
<span style="color: #a4a4a4; font-style: italic;"> last word, shift is the rotation applied, and words is a set of all</span>
<span style="color: #a4a4a4; font-style: italic;"> words being evaluated."</span>
<span style="color: #bbb;">[</span>shift words orig word<span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #494949;">[</span>rot-word <span style="color: #bbb;">(</span>rot-n word shift<span style="color: #bbb;">)</span><span style="color: #494949;">]</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">cond</span> <span style="color: #bbb;">(</span>= rot-word orig<span style="color: #bbb;">)</span> <span style="color: #E53935;">true</span>
<span style="color: #bbb;">(</span>not <span style="color: #494949;">(</span>contains? words rot-word<span style="color: #494949;">)</span><span style="color: #bbb;">)</span> <span style="color: #E53935;">false</span>
<span style="color: #E53935;">:else</span> <span style="color: #bbb;">(</span>rot-cycle? shift words orig rot-word<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def</span> <span style="font-style: italic;">word-set</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> <span style="color: #494949;">"words_alpha.txt"</span> slurp <span style="color: #E53935;">str</span>/lower-case <span style="color: #E53935;">str</span>/split-lines set<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #a4a4a4; font-style: italic;">;; </span><span style="color: #a4a4a4; font-style: italic;">Load the words into a set</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #bbb;">[</span>words <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">-></span> <span style="color: #494949;">"words_alpha.txt"</span> slurp <span style="color: #E53935;">str</span>/lower-case <span style="color: #E53935;">str</span>/split-lines<span style="color: #494949;">)</span>
word-set <span style="color: #494949;">(</span>set words<span style="color: #494949;">)</span><span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> words
<span style="color: #494949;">(</span>filter <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">fn</span> <span style="color: #494949;">[</span>word<span style="color: #494949;">]</span>
<span style="color: #494949;">(</span>rot-cycle? 13 word-set word word<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>sort #<span style="color: #bbb;">(</span>> <span style="color: #494949;">(</span>count <span style="font-style: italic;">%1</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span>count <span style="font-style: italic;">%2</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Last Modified: 2021-W48-3 17:56</p><p class="creator">Generated Using: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 27.2 (<a href="https://orgmode.org">Org</a> mode 9.4.6)</p><p class="license">Except where otherwise noted content on <a href="https://cons.dev">cons.dev</a> is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/" rel="license">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p>
</div>
</body>
</html>