2f40c00113d8556cee8adb5d5fbb57704b55134c
[szyfrow.git] / docs / szyfrow / caesar.html
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
6 <meta name="generator" content="pdoc 0.9.2" />
7 <title>szyfrow.caesar API documentation</title>
8 <meta name="description" content="Enciphering and deciphering using the [Caesar cipher](https://en.wikipedia.org/wiki/Caesar_cipher).
9 Also attempts to break messages that use a Caesar …" />
10 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
11 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
12 <link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
13 <style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
14 <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
15 <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
16 <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
17 <script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
18 </head>
19 <body>
20 <main>
21 <article id="content">
22 <header>
23 <h1 class="title">Module <code>szyfrow.caesar</code></h1>
24 </header>
25 <section id="section-intro">
26 <p>Enciphering and deciphering using the <a href="https://en.wikipedia.org/wiki/Caesar_cipher">Caesar cipher</a>.
27 Also attempts to break messages that use a Caesar cipher.</p>
28 <p>The Caesar cipher operates one letter at a time. It converts each letter to a
29 number, then enciphers that number by adding the key. The result is taken mod
30 26 and converted back into a letter.</p>
31 <details class="source">
32 <summary>
33 <span>Expand source code</span>
34 </summary>
35 <pre><code class="python">&#34;&#34;&#34;Enciphering and deciphering using the [Caesar cipher](https://en.wikipedia.org/wiki/Caesar_cipher).
36 Also attempts to break messages that use a Caesar cipher.
37
38 The Caesar cipher operates one letter at a time. It converts each letter to a
39 number, then enciphers that number by adding the key. The result is taken mod
40 26 and converted back into a letter.
41
42 &#34;&#34;&#34;
43
44 from szyfrow.support.utilities import *
45 from szyfrow.support.language_models import *
46
47 def caesar_encipher_letter(accented_letter, shift):
48 &#34;&#34;&#34;Encipher a letter, given a shift amount.
49
50 Accented version of latin letters (such as é and ö) are converted to their
51 non-accented versions before encryption.
52
53 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, 1)
54 &#39;b&#39;
55 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, 2)
56 &#39;c&#39;
57 &gt;&gt;&gt; caesar_encipher_letter(&#39;b&#39;, 2)
58 &#39;d&#39;
59 &gt;&gt;&gt; caesar_encipher_letter(&#39;x&#39;, 2)
60 &#39;z&#39;
61 &gt;&gt;&gt; caesar_encipher_letter(&#39;y&#39;, 2)
62 &#39;a&#39;
63 &gt;&gt;&gt; caesar_encipher_letter(&#39;z&#39;, 2)
64 &#39;b&#39;
65 &gt;&gt;&gt; caesar_encipher_letter(&#39;z&#39;, -1)
66 &#39;y&#39;
67 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, -1)
68 &#39;z&#39;
69 &gt;&gt;&gt; caesar_encipher_letter(&#39;A&#39;, 1)
70 &#39;B&#39;
71 &gt;&gt;&gt; caesar_encipher_letter(&#39;é&#39;, 1)
72 &#39;f&#39;
73 &#34;&#34;&#34;
74 # letter = unaccent(accented_letter)
75 # if letter in string.ascii_letters:
76 # if letter in string.ascii_uppercase:
77 # alphabet_start = ord(&#39;A&#39;)
78 # else:
79 # alphabet_start = ord(&#39;a&#39;)
80 # return chr(((ord(letter) - alphabet_start + shift) % 26) +
81 # alphabet_start)
82 # else:
83 # return letter
84
85 letter = unaccent(accented_letter)
86 if letter in string.ascii_letters:
87 cipherletter = unpos(pos(letter) + shift)
88 if letter in string.ascii_uppercase:
89 return cipherletter.upper()
90 else:
91 return cipherletter
92 else:
93 return letter
94
95 def caesar_decipher_letter(letter, shift):
96 &#34;&#34;&#34;Decipher a letter, given a shift amount
97
98 &gt;&gt;&gt; caesar_decipher_letter(&#39;b&#39;, 1)
99 &#39;a&#39;
100 &gt;&gt;&gt; caesar_decipher_letter(&#39;b&#39;, 2)
101 &#39;z&#39;
102 &#34;&#34;&#34;
103 return caesar_encipher_letter(letter, -shift)
104
105 def caesar_encipher(message, shift):
106 &#34;&#34;&#34;Encipher a message with the Caesar cipher of given shift
107
108 &gt;&gt;&gt; caesar_encipher(&#39;abc&#39;, 1)
109 &#39;bcd&#39;
110 &gt;&gt;&gt; caesar_encipher(&#39;abc&#39;, 2)
111 &#39;cde&#39;
112 &gt;&gt;&gt; caesar_encipher(&#39;abcxyz&#39;, 2)
113 &#39;cdezab&#39;
114 &gt;&gt;&gt; caesar_encipher(&#39;ab cx yz&#39;, 2)
115 &#39;cd ez ab&#39;
116 &gt;&gt;&gt; caesar_encipher(&#39;Héllo World!&#39;, 2)
117 &#39;Jgnnq Yqtnf!&#39;
118 &#34;&#34;&#34;
119 enciphered = [caesar_encipher_letter(l, shift) for l in message]
120 return cat(enciphered)
121
122 def caesar_decipher(message, shift):
123 &#34;&#34;&#34;Decipher a message with the Caesar cipher of given shift
124
125 &gt;&gt;&gt; caesar_decipher(&#39;bcd&#39;, 1)
126 &#39;abc&#39;
127 &gt;&gt;&gt; caesar_decipher(&#39;cde&#39;, 2)
128 &#39;abc&#39;
129 &gt;&gt;&gt; caesar_decipher(&#39;cd ez ab&#39;, 2)
130 &#39;ab cx yz&#39;
131 &gt;&gt;&gt; caesar_decipher(&#39;Jgnnq Yqtnf!&#39;, 2)
132 &#39;Hello World!&#39;
133 &#34;&#34;&#34;
134 return caesar_encipher(message, -shift)
135
136
137 def caesar_break(message, fitness=Pletters):
138 &#34;&#34;&#34;Breaks a Caesar cipher using frequency analysis
139
140 It tries all possible keys, scores the fitness of the text decipherd with
141 each key, and returns the key that produces the most fit deciphered text.
142
143 &gt;&gt;&gt; caesar_break(&#39;ibxcsyorsaqcheyklxivoexlevmrimwxsfiqevvmihrsasrxliwyrh&#39; \
144 &#39;ecjsppsamrkwleppfmergefifvmhixscsymjcsyqeoixlm&#39;) # doctest: +ELLIPSIS
145 (4, -130.849989015...)
146 &gt;&gt;&gt; caesar_break(&#39;wxwmaxdgheetgwuxztgptedbgznitgwwhpguxyhkxbmhvvtlbhgtee&#39; \
147 &#39;raxlmhiixweblmxgxwmhmaxybkbgztgwztsxwbgmxgmert&#39;) # doctest: +ELLIPSIS
148 (19, -128.82410410...)
149 &gt;&gt;&gt; caesar_break(&#39;yltbbqnqnzvguvaxurorgenafsbezqvagbnornfgsbevpnaabjurer&#39; \
150 &#39;svaquvzyvxrnznazlybequrvfohgriraabjtbaruraprur&#39;) # doctest: +ELLIPSIS
151 (13, -126.25403935...)
152 &#34;&#34;&#34;
153 sanitised_message = sanitise(message)
154 best_shift = 0
155 best_fit = float(&#39;-inf&#39;)
156 for shift in range(26):
157 plaintext = caesar_decipher(sanitised_message, shift)
158 fit = fitness(plaintext)
159
160 if fit &gt; best_fit:
161 best_fit = fit
162 best_shift = shift
163
164 return best_shift, best_fit</code></pre>
165 </details>
166 </section>
167 <section>
168 </section>
169 <section>
170 </section>
171 <section>
172 <h2 class="section-title" id="header-functions">Functions</h2>
173 <dl>
174 <dt id="szyfrow.caesar.caesar_break"><code class="name flex">
175 <span>def <span class="ident">caesar_break</span></span>(<span>message, fitness=&lt;function Pletters&gt;)</span>
176 </code></dt>
177 <dd>
178 <div class="desc"><p>Breaks a Caesar cipher using frequency analysis</p>
179 <p>It tries all possible keys, scores the fitness of the text decipherd with
180 each key, and returns the key that produces the most fit deciphered text.</p>
181 <pre><code class="language-python-repl">&gt;&gt;&gt; caesar_break('ibxcsyorsaqcheyklxivoexlevmrimwxsfiqevvmihrsasrxliwyrh' 'ecjsppsamrkwleppfmergefifvmhixscsymjcsyqeoixlm') # doctest: +ELLIPSIS
182 (4, -130.849989015...)
183 &gt;&gt;&gt; caesar_break('wxwmaxdgheetgwuxztgptedbgznitgwwhpguxyhkxbmhvvtlbhgtee' 'raxlmhiixweblmxgxwmhmaxybkbgztgwztsxwbgmxgmert') # doctest: +ELLIPSIS
184 (19, -128.82410410...)
185 &gt;&gt;&gt; caesar_break('yltbbqnqnzvguvaxurorgenafsbezqvagbnornfgsbevpnaabjurer' 'svaquvzyvxrnznazlybequrvfohgriraabjtbaruraprur') # doctest: +ELLIPSIS
186 (13, -126.25403935...)
187 </code></pre></div>
188 <details class="source">
189 <summary>
190 <span>Expand source code</span>
191 </summary>
192 <pre><code class="python">def caesar_break(message, fitness=Pletters):
193 &#34;&#34;&#34;Breaks a Caesar cipher using frequency analysis
194
195 It tries all possible keys, scores the fitness of the text decipherd with
196 each key, and returns the key that produces the most fit deciphered text.
197
198 &gt;&gt;&gt; caesar_break(&#39;ibxcsyorsaqcheyklxivoexlevmrimwxsfiqevvmihrsasrxliwyrh&#39; \
199 &#39;ecjsppsamrkwleppfmergefifvmhixscsymjcsyqeoixlm&#39;) # doctest: +ELLIPSIS
200 (4, -130.849989015...)
201 &gt;&gt;&gt; caesar_break(&#39;wxwmaxdgheetgwuxztgptedbgznitgwwhpguxyhkxbmhvvtlbhgtee&#39; \
202 &#39;raxlmhiixweblmxgxwmhmaxybkbgztgwztsxwbgmxgmert&#39;) # doctest: +ELLIPSIS
203 (19, -128.82410410...)
204 &gt;&gt;&gt; caesar_break(&#39;yltbbqnqnzvguvaxurorgenafsbezqvagbnornfgsbevpnaabjurer&#39; \
205 &#39;svaquvzyvxrnznazlybequrvfohgriraabjtbaruraprur&#39;) # doctest: +ELLIPSIS
206 (13, -126.25403935...)
207 &#34;&#34;&#34;
208 sanitised_message = sanitise(message)
209 best_shift = 0
210 best_fit = float(&#39;-inf&#39;)
211 for shift in range(26):
212 plaintext = caesar_decipher(sanitised_message, shift)
213 fit = fitness(plaintext)
214
215 if fit &gt; best_fit:
216 best_fit = fit
217 best_shift = shift
218
219 return best_shift, best_fit</code></pre>
220 </details>
221 </dd>
222 <dt id="szyfrow.caesar.caesar_decipher"><code class="name flex">
223 <span>def <span class="ident">caesar_decipher</span></span>(<span>message, shift)</span>
224 </code></dt>
225 <dd>
226 <div class="desc"><p>Decipher a message with the Caesar cipher of given shift</p>
227 <pre><code class="language-python-repl">&gt;&gt;&gt; caesar_decipher('bcd', 1)
228 'abc'
229 &gt;&gt;&gt; caesar_decipher('cde', 2)
230 'abc'
231 &gt;&gt;&gt; caesar_decipher('cd ez ab', 2)
232 'ab cx yz'
233 &gt;&gt;&gt; caesar_decipher('Jgnnq Yqtnf!', 2)
234 'Hello World!'
235 </code></pre></div>
236 <details class="source">
237 <summary>
238 <span>Expand source code</span>
239 </summary>
240 <pre><code class="python">def caesar_decipher(message, shift):
241 &#34;&#34;&#34;Decipher a message with the Caesar cipher of given shift
242
243 &gt;&gt;&gt; caesar_decipher(&#39;bcd&#39;, 1)
244 &#39;abc&#39;
245 &gt;&gt;&gt; caesar_decipher(&#39;cde&#39;, 2)
246 &#39;abc&#39;
247 &gt;&gt;&gt; caesar_decipher(&#39;cd ez ab&#39;, 2)
248 &#39;ab cx yz&#39;
249 &gt;&gt;&gt; caesar_decipher(&#39;Jgnnq Yqtnf!&#39;, 2)
250 &#39;Hello World!&#39;
251 &#34;&#34;&#34;
252 return caesar_encipher(message, -shift)</code></pre>
253 </details>
254 </dd>
255 <dt id="szyfrow.caesar.caesar_decipher_letter"><code class="name flex">
256 <span>def <span class="ident">caesar_decipher_letter</span></span>(<span>letter, shift)</span>
257 </code></dt>
258 <dd>
259 <div class="desc"><p>Decipher a letter, given a shift amount</p>
260 <pre><code class="language-python-repl">&gt;&gt;&gt; caesar_decipher_letter('b', 1)
261 'a'
262 &gt;&gt;&gt; caesar_decipher_letter('b', 2)
263 'z'
264 </code></pre></div>
265 <details class="source">
266 <summary>
267 <span>Expand source code</span>
268 </summary>
269 <pre><code class="python">def caesar_decipher_letter(letter, shift):
270 &#34;&#34;&#34;Decipher a letter, given a shift amount
271
272 &gt;&gt;&gt; caesar_decipher_letter(&#39;b&#39;, 1)
273 &#39;a&#39;
274 &gt;&gt;&gt; caesar_decipher_letter(&#39;b&#39;, 2)
275 &#39;z&#39;
276 &#34;&#34;&#34;
277 return caesar_encipher_letter(letter, -shift)</code></pre>
278 </details>
279 </dd>
280 <dt id="szyfrow.caesar.caesar_encipher"><code class="name flex">
281 <span>def <span class="ident">caesar_encipher</span></span>(<span>message, shift)</span>
282 </code></dt>
283 <dd>
284 <div class="desc"><p>Encipher a message with the Caesar cipher of given shift</p>
285 <pre><code class="language-python-repl">&gt;&gt;&gt; caesar_encipher('abc', 1)
286 'bcd'
287 &gt;&gt;&gt; caesar_encipher('abc', 2)
288 'cde'
289 &gt;&gt;&gt; caesar_encipher('abcxyz', 2)
290 'cdezab'
291 &gt;&gt;&gt; caesar_encipher('ab cx yz', 2)
292 'cd ez ab'
293 &gt;&gt;&gt; caesar_encipher('Héllo World!', 2)
294 'Jgnnq Yqtnf!'
295 </code></pre></div>
296 <details class="source">
297 <summary>
298 <span>Expand source code</span>
299 </summary>
300 <pre><code class="python">def caesar_encipher(message, shift):
301 &#34;&#34;&#34;Encipher a message with the Caesar cipher of given shift
302
303 &gt;&gt;&gt; caesar_encipher(&#39;abc&#39;, 1)
304 &#39;bcd&#39;
305 &gt;&gt;&gt; caesar_encipher(&#39;abc&#39;, 2)
306 &#39;cde&#39;
307 &gt;&gt;&gt; caesar_encipher(&#39;abcxyz&#39;, 2)
308 &#39;cdezab&#39;
309 &gt;&gt;&gt; caesar_encipher(&#39;ab cx yz&#39;, 2)
310 &#39;cd ez ab&#39;
311 &gt;&gt;&gt; caesar_encipher(&#39;Héllo World!&#39;, 2)
312 &#39;Jgnnq Yqtnf!&#39;
313 &#34;&#34;&#34;
314 enciphered = [caesar_encipher_letter(l, shift) for l in message]
315 return cat(enciphered)</code></pre>
316 </details>
317 </dd>
318 <dt id="szyfrow.caesar.caesar_encipher_letter"><code class="name flex">
319 <span>def <span class="ident">caesar_encipher_letter</span></span>(<span>accented_letter, shift)</span>
320 </code></dt>
321 <dd>
322 <div class="desc"><p>Encipher a letter, given a shift amount.</p>
323 <p>Accented version of latin letters (such as é and ö) are converted to their
324 non-accented versions before encryption.</p>
325 <pre><code class="language-python-repl">&gt;&gt;&gt; caesar_encipher_letter('a', 1)
326 'b'
327 &gt;&gt;&gt; caesar_encipher_letter('a', 2)
328 'c'
329 &gt;&gt;&gt; caesar_encipher_letter('b', 2)
330 'd'
331 &gt;&gt;&gt; caesar_encipher_letter('x', 2)
332 'z'
333 &gt;&gt;&gt; caesar_encipher_letter('y', 2)
334 'a'
335 &gt;&gt;&gt; caesar_encipher_letter('z', 2)
336 'b'
337 &gt;&gt;&gt; caesar_encipher_letter('z', -1)
338 'y'
339 &gt;&gt;&gt; caesar_encipher_letter('a', -1)
340 'z'
341 &gt;&gt;&gt; caesar_encipher_letter('A', 1)
342 'B'
343 &gt;&gt;&gt; caesar_encipher_letter('é', 1)
344 'f'
345 </code></pre></div>
346 <details class="source">
347 <summary>
348 <span>Expand source code</span>
349 </summary>
350 <pre><code class="python">def caesar_encipher_letter(accented_letter, shift):
351 &#34;&#34;&#34;Encipher a letter, given a shift amount.
352
353 Accented version of latin letters (such as é and ö) are converted to their
354 non-accented versions before encryption.
355
356 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, 1)
357 &#39;b&#39;
358 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, 2)
359 &#39;c&#39;
360 &gt;&gt;&gt; caesar_encipher_letter(&#39;b&#39;, 2)
361 &#39;d&#39;
362 &gt;&gt;&gt; caesar_encipher_letter(&#39;x&#39;, 2)
363 &#39;z&#39;
364 &gt;&gt;&gt; caesar_encipher_letter(&#39;y&#39;, 2)
365 &#39;a&#39;
366 &gt;&gt;&gt; caesar_encipher_letter(&#39;z&#39;, 2)
367 &#39;b&#39;
368 &gt;&gt;&gt; caesar_encipher_letter(&#39;z&#39;, -1)
369 &#39;y&#39;
370 &gt;&gt;&gt; caesar_encipher_letter(&#39;a&#39;, -1)
371 &#39;z&#39;
372 &gt;&gt;&gt; caesar_encipher_letter(&#39;A&#39;, 1)
373 &#39;B&#39;
374 &gt;&gt;&gt; caesar_encipher_letter(&#39;é&#39;, 1)
375 &#39;f&#39;
376 &#34;&#34;&#34;
377 # letter = unaccent(accented_letter)
378 # if letter in string.ascii_letters:
379 # if letter in string.ascii_uppercase:
380 # alphabet_start = ord(&#39;A&#39;)
381 # else:
382 # alphabet_start = ord(&#39;a&#39;)
383 # return chr(((ord(letter) - alphabet_start + shift) % 26) +
384 # alphabet_start)
385 # else:
386 # return letter
387
388 letter = unaccent(accented_letter)
389 if letter in string.ascii_letters:
390 cipherletter = unpos(pos(letter) + shift)
391 if letter in string.ascii_uppercase:
392 return cipherletter.upper()
393 else:
394 return cipherletter
395 else:
396 return letter</code></pre>
397 </details>
398 </dd>
399 <dt id="szyfrow.caesar.cat"><code class="name flex">
400 <span>def <span class="ident">cat</span></span>(<span>iterable, /)</span>
401 </code></dt>
402 <dd>
403 <div class="desc"><p>Concatenate any number of strings.</p>
404 <p>The string whose method is called is inserted in between each given string.
405 The result is returned as a new string.</p>
406 <p>Example: '.'.join(['ab', 'pq', 'rs']) -&gt; 'ab.pq.rs'</p></div>
407 </dd>
408 <dt id="szyfrow.caesar.lcat"><code class="name flex">
409 <span>def <span class="ident">lcat</span></span>(<span>iterable, /)</span>
410 </code></dt>
411 <dd>
412 <div class="desc"><p>Concatenate any number of strings.</p>
413 <p>The string whose method is called is inserted in between each given string.
414 The result is returned as a new string.</p>
415 <p>Example: '.'.join(['ab', 'pq', 'rs']) -&gt; 'ab.pq.rs'</p></div>
416 </dd>
417 <dt id="szyfrow.caesar.wcat"><code class="name flex">
418 <span>def <span class="ident">wcat</span></span>(<span>iterable, /)</span>
419 </code></dt>
420 <dd>
421 <div class="desc"><p>Concatenate any number of strings.</p>
422 <p>The string whose method is called is inserted in between each given string.
423 The result is returned as a new string.</p>
424 <p>Example: '.'.join(['ab', 'pq', 'rs']) -&gt; 'ab.pq.rs'</p></div>
425 </dd>
426 </dl>
427 </section>
428 <section>
429 </section>
430 </article>
431 <nav id="sidebar">
432 <h1>Index</h1>
433 <div class="toc">
434 <ul></ul>
435 </div>
436 <ul id="index">
437 <li><h3>Super-module</h3>
438 <ul>
439 <li><code><a title="szyfrow" href="index.html">szyfrow</a></code></li>
440 </ul>
441 </li>
442 <li><h3><a href="#header-functions">Functions</a></h3>
443 <ul class="">
444 <li><code><a title="szyfrow.caesar.caesar_break" href="#szyfrow.caesar.caesar_break">caesar_break</a></code></li>
445 <li><code><a title="szyfrow.caesar.caesar_decipher" href="#szyfrow.caesar.caesar_decipher">caesar_decipher</a></code></li>
446 <li><code><a title="szyfrow.caesar.caesar_decipher_letter" href="#szyfrow.caesar.caesar_decipher_letter">caesar_decipher_letter</a></code></li>
447 <li><code><a title="szyfrow.caesar.caesar_encipher" href="#szyfrow.caesar.caesar_encipher">caesar_encipher</a></code></li>
448 <li><code><a title="szyfrow.caesar.caesar_encipher_letter" href="#szyfrow.caesar.caesar_encipher_letter">caesar_encipher_letter</a></code></li>
449 <li><code><a title="szyfrow.caesar.cat" href="#szyfrow.caesar.cat">cat</a></code></li>
450 <li><code><a title="szyfrow.caesar.lcat" href="#szyfrow.caesar.lcat">lcat</a></code></li>
451 <li><code><a title="szyfrow.caesar.wcat" href="#szyfrow.caesar.wcat">wcat</a></code></li>
452 </ul>
453 </li>
454 </ul>
455 </nav>
456 </main>
457 <footer id="footer">
458 <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.9.2</a>.</p>
459 </footer>
460 </body>
461 </html>