<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media = "http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>Basics of Cryptography on Michée Lengronne</title>
    <link>https://michee.io/en-us/series/basics-of-cryptography/</link>
    <image>
      <url>https://michee.io/logo.png</url>
      <title>Basics of Cryptography on Michée Lengronne</title>
      <link>https://michee.io/en-us/series/basics-of-cryptography/</link>
    </image>
    <description>Expertise in Platform, Big Data, DevOps, IT security (DevSecOps) and Opensource</description>
    <language>en-us</language>
    <lastBuildDate>Wed, 03 Dec 2025 16:00:00 +0000</lastBuildDate><atom:link href="https://michee.io/en-us/series/basics-of-cryptography/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The one-time pad</title>
      <link>https://michee.io/en-us/posts/the-one-time-pad/</link>
      <pubDate>Wed, 03 Dec 2025 16:00:00 +0000</pubDate>
      <guid>https://michee.io/en-us/posts/the-one-time-pad/</guid>
      <description>This encryption is theoretically impossible to break. However, it is essentially theoretical because it remains very complex to implement.</description>
      <content:encoded><![CDATA[<h2 id="a-bit-of-history">A bit of history</h2>
<p>The one-time pad is an encryption method invented by Gilbert Vernam, an American engineer at AT&amp;T Bell Labs, in 1917.</p>
<p>Note: This post was translated from french with the help of AI. The original post was written with the knowledge of a younger me.</p>
<p>It is based on a much older encryption technique called the &ldquo;
<a href="https://michee.io/en-us/posts/the-vigenere-cipher/">Vigenère cipher</a>&rdquo;.</p>
<p>The one-time pad was further perfected by the American general Joseph Mauborgne, who introduced the randomness of the encryption key.</p>
<p>It consists of encrypting a message with a key by adding the key to the message, element by element.
The key must be used only once (hence the &ldquo;one-time&rdquo; or disposable).
To decrypt, you subtract the key from the message.</p>
<p>Okay, history is nice but in practice, how does it work?</p>
<h2 id="how-it-works">How it works</h2>
<p>To understand the one-time pad, you first need to master (or at least understand) 
<a href="https://michee.io/en-us/posts/the-congruence-the-modulo/">congruence</a> (or modulo arithmetic).</p>
<h3 id="the-basics">The basics</h3>
<p>We&rsquo;ll start by using non-random texts for the keys. Note, this is just to start slowly because here security is zero.</p>
<p>We&rsquo;ll take a Bigflo&amp;Oli (french rappers) text as the message to encrypt and a Georges Brassens (french singer) text as the key.</p>
<p>The message is from &ldquo;Alors alors&rdquo;:</p>
<p>&ldquo;Alors alors, On devait faire le tour de la Terre&rdquo;</p>
<p>The key is from &ldquo;Bancs publics&rdquo;:</p>
<p>&ldquo;Les gens qui voient de travers pensent que les bancs verts&rdquo;</p>
<p>Got modulo in mind? Good, let&rsquo;s start by assigning a number to each letter of our alphabet:</p>
<pre><code>A=0, B=1, C=2, D=3, E=4, F=5, G=6, H=7, I=8, J=9, K=10, L=11, M=12, N=13, O=14, P=15, Q=16, R=17, S=18, T=19, U=20, V=21, W=22, X=23, Y=24, Z=25
</code></pre>
<p>So, for our 26-letter alphabet, we have numbers from 0 to 25.</p>
<h3 id="encryption">Encryption</h3>
<p>To encrypt, it&rsquo;s simple, we add letters face to face.
&ldquo;Add letters, are you crazy?&rdquo; you might say, but that&rsquo;s why we&rsquo;ve given them numerical equivalents, follow along.
Since we haven&rsquo;t assigned values to commas, we&rsquo;ll remove them.</p>
<p>Let&rsquo;s go:</p>
<pre><code>&quot;Alors alors On devait faire le tour de la Terre&quot;

+

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;
</code></pre>
<p>The &ldquo;A&rdquo; of &ldquo;Alors&rdquo; + the &ldquo;L&rdquo; of &ldquo;Les&rdquo; = A + L = 0 + 11 = 11 = L</p>
<p>Then &ldquo;l&rdquo; + &ldquo;e&rdquo; = l + e = 11 + 4 = 15 = p</p>
<p>So, little by little:</p>
<pre><code>&quot;Alors alors On devait faire le tour de la Terre&quot;

+ + +

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;

= = =

0 11 14

+ + +

11 4 18

= = =

11 15 32

= = =

L p ?
</code></pre>
<p>Indeed, for adding &ldquo;o&rdquo; and &ldquo;s&rdquo;, we get 14 + 18 = 32 and here is the problem, we don&rsquo;t have a letter with value 32.</p>
<p>But remember, congruence (modulo, all that).</p>
<p>Since we have only 26 letters, we&rsquo;ll use modulo 26 to stay in range.</p>
<p>Modulo 26 of 32 is:</p>
<p>$$
32 \pmod{26} \equiv 32 -26 \pmod{26} \equiv 6 \pmod{26}
$$</p>
<p>And 6 corresponds to letter G.</p>
<p>So, we can finish our calculation:</p>
<pre><code>&quot;Alors alors On devait faire le tour de la Terre&quot;

+ + + ...

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;

= = =

0 11 14

+ + +

11 4 18

= = =

11 15 32 mod(26)≡ 6 mod(26)

= = =

L p g …
</code></pre>
<p>In the end:</p>
<pre><code>&quot;Alors alors On devait faire le tour de la Terre&quot;

+

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;

=

&quot;Lpgxw ndela Jb liitlx yrimi cw ishj hr eq Nicvw&quot;
</code></pre>
<p>We have our encrypted message.</p>
<h3 id="decryption">Decryption</h3>
<p>To decrypt, we do the opposite: subtract the key from the encrypted message.</p>
<p>We have encrypted message &ldquo;Lpgxw ndela Jb liitlx yrimi cw ishj hr eq Nicvw&rdquo; and the key &ldquo;Les gens qui voient de travers pensent que les bancs verts&rdquo;.</p>
<p>So:</p>
<pre><code>&quot;Lpgxw ndela Jb liitlx yrimi cw ishj hr eq Nicvw&quot;

- - -

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;

= = =

11 15 6

- - -

11 4 18

= = =

0 11 -12

= = =

A l ?
</code></pre>
<p>Again, same problem as encryption, we have -12 with no corresponding letter.</p>
<p>We apply modulo 26:</p>
<p>$$
-12 \pmod{26} \equiv -12 + 26 \pmod{26} \equiv 14 \pmod{26} \equiv o
$$</p>
<p>We continue the calculation and recover:</p>
<pre><code>&quot;Lpgxw ndela Jb liitlx yrimi cw ishj hr eq Nicvw&quot;

- - - ...

&quot;Les gens qui voient de travers pensent que les bancs verts&quot;

=

&quot;Alors alors On devait faire le tour de la Terre&quot;
</code></pre>
<h3 id="mauborgne-in-da-house">Mauborgne in da house</h3>
<p>Okay, that&rsquo;s nice but not very secure. To improve security, let&rsquo;s listen to General Mauborgne and use a random key (or at least a more random one).</p>
<p>After putting a pseudo-random generator (yes, I know, an incomprehensible term, we&rsquo;ll come back to it in a future article) on my computer,
rolling my head on the keyboard, and letting the cat walk on it for entropy (yes, another incomprehensible term), I got this key:</p>
<pre><code>&quot;snchfzrhqjlnveivpyonrkudrpqtpxptfwrildof&quot;
</code></pre>
<p>We&rsquo;ll encrypt the following message, again by Bigflo&amp;Oli, from &ldquo;Dommage&rdquo;:</p>
<p>&ldquo;Il croisait cette même fille, avec son doux parfum&rdquo;</p>
<h3 id="encryption-1">Encryption</h3>
<p>Here we go again:</p>
<pre><code>&quot;Il croisait cette même fille, avec son doux parfum&quot;

+ +

&quot;snchfzrhqjlnveivpyonrkudrpqtpxptfwrildof&quot;

= =

8 11

+ +

18 13

≡ =

0 mod(26) 24

=

a y …
</code></pre>
<p>We get the encrypted message:</p>
<pre><code>&quot;Il croisait cette même fille, avec son doux parfum&quot;

+

&quot;snchfzrhqjlnveivpyonrkudrpqtpxptfwrildof&quot;

=

&quot;ayeythjhycnroxmhtksszvfhrkuvhlcwtqoxlutze&quot;
</code></pre>
<h3 id="decryption-1">Decryption</h3>
<p>I think by now you get it. One quick example.</p>
<p>Still with modulo(26), decrypt this message:</p>
<pre><code>&quot;irszlg k wiu ladw&quot;
</code></pre>
<p>with the key:</p>
<pre><code>&quot;xjgzpyisqbjmplcxhwfpijqrstghighnhylshqza&quot;
</code></pre>
<p>And tweet or post the result.</p>
<h3 id="the-che-level">The Che level</h3>
<p>So far we&rsquo;ve been cute, now we tackle the hard stuff.</p>
<p>Che Guevara and Fidel Castro communicated with a cryptographic technique based on the one-time pad.
However, there was an extra complexity.</p>
<p>They didn&rsquo;t use a sequence of numbers like we did, but assigned arbitrary numbers to letters of the alphabet.</p>
<p>Here is their substitution:</p>
<pre><code>A=6, B=38, C=32, D=4, E=8, F=30, G=36, H=34, I=39, J=31, K=78, L=72, M=70, N=76, O=9, P=79, Q=71, R=58, S=2, T=0, U=52, V=50, W=56, X=54, Y=1, Z=59
</code></pre>
<p>You might ask &ldquo;how do you do congruence with this?&rdquo;, hold on, it’s coming.</p>
<p>Actually, they transmitted numbers, not letters, and the key was itself composed of numbers. They used the most known modulo (the one we unknowingly use), modulo 10.</p>
<p>So, how did they do it? Let’s take an example.</p>
<h3 id="encryption-2">Encryption</h3>
<p>We want to encrypt the message:</p>
<p>&ldquo;J’aime pas les framboises&rdquo; (&ldquo;I don’t like raspberries&rdquo; in french, just an example, I do like raspberries)</p>
<p>We replace the letters with their numbers:</p>
<p>&ldquo;J A I M E P A S L E S F R A M B O I S E S&rdquo; becomes &ldquo;31 6 39 70 8 79 6 2 72 8 2 30 58 6 70 38 9 39 2 8 2&rdquo;</p>
<p>We encrypt this message with the key:</p>
<pre><code>&quot;4317892093088287991744997181628757157172&quot;
</code></pre>
<p>We add the numbers face to face and apply modulo 10. To ease things, they first grouped digits in packets of 5.</p>
<p>So, the message:</p>
<pre><code>&quot;31 6 39 70 8 79 6 2 72 8 2 30 58 6 70 38 9 39 2 8 2&quot;
</code></pre>
<p>becomes:</p>
<pre><code>&quot;31639 70879 62728 23058 67038 93928 2&quot;
</code></pre>
<p>We add with modulo 10:</p>
<pre><code>&quot;31639 70879 62728 23058 67038 93928 2&quot;

+

&quot;43178 92093 08828 79917 44997 18162 87571 57172&quot;

=

747 (7+3 ≡ 10 mod(10) ≡ 0) …

=

74707 62862 60546 92965 01925 01080 0
</code></pre>
<p>The encrypted message is therefore:</p>
<pre><code>&quot;74707 62862 60546 92965 01925 01080 0&quot;
</code></pre>
<h3 id="decryption-2">Decryption</h3>
<p>We subtract the key from the message using modulo 10:</p>
<pre><code>&quot;74707 62862 60546 92965 01925 01080 0&quot;

-

&quot;43178 92093 08828 79917 44997 18162 87571 57172&quot;

=

&quot;31639 70879 62728 23058 67038 93928 2&quot;
</code></pre>
<p>Then, we convert the numbers into their respective letters.
And now you’re thinking, “But how can they tell the difference between the letter with value 2 and the letter with value 23?
How can they know if it’s a one-digit or two-digit number?”</p>
<p>Very simple, the digits used for one-digit numbers are never used to start a two-digit number.</p>
<p>In fact, if you encounter 3, 7, or 5, you know it’s a two-digit number and so you must group the following digit with it.</p>
<p>In our case, we start with a 3, so we know it’s a two-digit number, we join the 1 to the 3.</p>
<pre><code>&quot;31 639 70879 62728 23058 67038  93928 2&quot;
</code></pre>
<p>Next, the 6 is not in (3,7,5), so it’s a one-digit number:</p>
<pre><code>&quot;31 6 39 70879 62728 23058 67038  93928 2&quot;
</code></pre>
<p>And so on:</p>
<pre><code>&quot;31 6 39 70 8 79 6 2 72 8 2 30 58 6 70 38 9 39 2 8 2&quot;
</code></pre>
<p>Finally, we replace the numbers with their corresponding letters:</p>
<pre><code>&quot;J A I M E P A S L E S F R A M B O I S E S&quot;
</code></pre>
<p>There you go!</p>
<h2 id="the-perfection-of-the-cipher">The Perfection of the Cipher</h2>
<p>Claude Shannon (more name-dropping, but this one is the flagship of cryptographers) mathematically proved
that the one-time pad is considered cryptographically secure, or unconditionally secure, during World War II.
That is to say, the system cannot be cracked even if the adversary has unlimited resources or unlimited time, as long as they do not know the secret key.</p>
<p>Claude Shannon proved that the one-time pad is “perfectly secret,” meaning that if you have a ciphertext encrypted with the one-time pad,
there is absolutely no way to guess anything about the original plaintext.</p>
<p>This means it is also resistant to brute-force attacks.
If you try every key in the universe, you will get every possible message in the universe, so you have no way to know which one is correct.</p>
<p>I won’t redo the mathematical proofs here. This article is meant for broad, easy-to-understand dissemination.</p>
<p>But to achieve this perfection, there are some challenges.</p>
<h2 id="the-difficulties">The Difficulties</h2>
<p>The difficulties to overcome to achieve a perfect one-time pad are as follows:</p>
<h3 id="key-size-and-quantity">Key Size and Quantity</h3>
<p>For every exchange, you need a new key. For every exchange, that is, each person you communicate with and each message you send to them.</p>
<p>So, if you exchange 2 messages with 2 people, that makes 4 keys. 3 messages with 3 people, 9 keys&hellip;</p>
<p>Moreover, the key must be longer than the message.</p>
<p>Because if it is shorter and repeated to complete the encryption,
you increase the probability of certain letters appearing and you can see patterns emerge giving clues about the message.
This problem is similar to the need for randomness in creating keys.</p>
<p>This poses problems for securely storing keys, as the cipher collapses if the key is recovered by the adversary.</p>
<h3 id="the-randomness-of-the-keys">The Randomness of the Keys</h3>
<p>In French, the letter &ldquo;e&rdquo; is the most commonly used letter, then &ldquo;a&rdquo;, then &ldquo;s&rdquo;…</p>
<p>And patterns like “le”, “les” are frequent. The key, when repeated, increases the chances of encrypting the same patterns in the same way.</p>
<p>The attacker can spot these patterns and deduce when the key is repeated.</p>
<p>Gradually, they can reconstruct the key or even manage without it.</p>
<p>An example:</p>
<p>Imagine the key “Wesh”, the attacker doesn’t know it but has found its length is 4 by analyzing the frequencies of recurring patterns.</p>
<p>They can cut the ciphertext into groups of 4 letters: “Uedl lsll ysfk wqfl myaz kvlp newu zsmj a” and subtract the groups from each other:</p>
<pre><code>Uedl - lsll = X? + “Wesh” - (Y? + “Wesh”) = X? - Y? + “Wesh” - “Wesh”

= X? - Y?
</code></pre>
<p>The key disappears and we have two texts which are no longer random subtracted from each other.
We analyze the letter frequency and form hypotheses.
The letters resulting from the subtraction, the most frequent ones, are more likely to correspond to an “e” in one of their base letters, etc.</p>
<p>Step by step, by multiplying hypotheses, possibilities reduce and one can find the key or decrypt messages without it.</p>
<p>In conclusion, if you do a frequency analysis running your computer for three days, you will get the following message:</p>
<p>“Y&rsquo;a le pote condamné qui sortira en douce,” always Bigflo &amp; Oli, excerpt from “Comme d’hab”</p>
<p>This seems obscure, incomprehensible. Don’t worry, a future article will clarify all this with examples.</p>
<p>So, to ensure every letter has the same probability of appearing, you need randomly generated keys.
But that is very hard to do. We can make pseudo-randomness but as its name indicates it’s not truly random,
the probabilities of letter appearances are not exactly equal.</p>
<h3 id="key-transmission">Key Transmission</h3>
<p>Key transmission is not a problem for very small keys (an article will soon explain how).</p>
<p>But it becomes very complicated once keys must exceed a certain size
(the current minimum size is 4096 bits or, in some crazy cases, 8192 bits, that is 1024 bytes, 1 KB for IT folks).</p>
<p>So, often, keys are exchanged physically beforehand.
This is not practical and becomes very complicated when sending many messages to many interlocutors.</p>
<h3 id="uniqueness-of-use">Uniqueness of Use</h3>
<p>We return to the same problem as with key size and randomness.</p>
<p>If you reuse a key, you lose the randomness and the ciphertext becomes again vulnerable to frequency analysis.</p>
<p>The problem is even more serious because uniqueness of use implies destroying the key after use
and there is no easy way to ensure that your correspondents do not keep the keys
in a corner at risk of being stolen later (in 5 years, 10 years…) or reuse them for other messages on their side.</p>
<h3 id="message-poisoning">Message Poisoning</h3>
<p>The last possible problem is key poisoning but this can be easily fixed (at least temporarily) in IT.</p>
<p>Since the one-time pad is immune to brute force (all keys in the universe produce all messages in the universe),
an attacker can mess with the ciphertext to give it a different meaning.</p>
<p>They can also modify the key without necessarily knowing it and thus alter the plaintext.</p>
<p>Example:</p>
<p>Let’s take our famous message again:</p>
<pre><code>“J’aime pas les framboises”
</code></pre>
<p>which we encrypt with the key:</p>
<pre><code>“nzhtjplgpggsefirksxohsbyhkazsb”
</code></pre>
<p>using modulo 26 (thus without the apostrophe), we get:</p>
<pre><code>“N zrry rrg yef eytvqzohky”
</code></pre>
<p>The attacker only knows this secret message but can modify the encryption key. They replace the key by:</p>
<pre><code>“ezjfuqjcltbmtcvihgdtgefirksxohsbyhkazsb”
</code></pre>
<p>And that gives the following plaintext:</p>
<pre><code>“Jaimebienlesfraisiers” (&quot;I like strawberry bushes&quot; in french)
</code></pre>
<p>So, not at all the original message.</p>
<p>To prevent this, in IT, you can sign and hash the message and keys
so a user can verify that the message they receive was indeed created by the correct key and that the key they use is still the correct one.</p>
<p>We will come back to how signing and hashing work in future articles.</p>
<p>I think we have already well exceeded 2000 words. Let’s stop here.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Vigenère cipher</title>
      <link>https://michee.io/en-us/posts/the-vigenere-cipher/</link>
      <pubDate>Wed, 26 Nov 2025 16:00:00 +0000</pubDate>
      <guid>https://michee.io/en-us/posts/the-vigenere-cipher/</guid>
      <description>The Vigenère cipher is an evolution of the Caesar cipher that introduces the concept of a key.</description>
      <content:encoded><![CDATA[<h2 id="a-bit-of-history">A Bit of History</h2>
<p>Contrary to what its name suggests, the Vigenère cipher seems to have been invented by Giovan Battista Bellaso, an Italian cryptographer from the 16th century.</p>
<p>Nevertheless, it is the Vigenère cipher that endured, not Bellaso’s.</p>
<p>Blaise de Vigenère introduced his cipher 20 years after Bellaso, with some improvements.</p>
<p>This encryption method began to be called the Vigenère cipher from the 19th century onwards, without regard to Bellaso. Moreover, Bellaso was quickly forgotten in favor of Porta.</p>
<p>Lots of names. Ah, history!</p>
<p>Of course, this cipher is not secure and was broken as early as the 19th century.</p>
<p>Note: This post was translated from french with the help of AI. The original post was written with the knowledge of a younger me.</p>
<h2 id="the-key-instead-of-the-shift">The Key Instead of the Shift</h2>
<p>The Vigenère cipher introduced a major innovation compared to the 
<a href="https://michee.io/en-us/posts/the-caesar-cipher/">Caesar cipher</a>: the concept of a key.</p>
<p>This difference classifies this cipher as polyalphabetic rather than monoalphabetic.
It is no longer &ldquo;one plaintext letter gives one and only one ciphertext letter,&rdquo; but a plaintext letter
can produce two different ciphertext letters, and a ciphertext letter can come from two different plaintext letters.</p>
<p>Therefore, multiple substitution alphabets are used (different letter shifts within the same message), unlike the Caesar cipher. Hence the term &ldquo;polyalphabetic.&rdquo;</p>
<p>The substitution rules (how you switch from one alphabet to another) are given by the letters of the key and a substitution table.</p>
<p>Don’t quite get it? We will illustrate this with examples in the following chapters, no worries.</p>
<p>Also, another article will cover the classification of ciphers.</p>
<h2 id="the-cipher-itself">The Cipher Itself</h2>
<p>Let’s get to the heart of the matter. There are two ways to represent the classic Vigenère cipher (with variants being another story).</p>
<h3 id="table-representation">Table Representation</h3>
<p>For the table representation, we need a table (yes, really), or rather a substitution matrix. Here it is:</p>

<figure class="figure text-center">
  <img src="https://michee.io/en-us/posts/the-vigenere-cipher/images/vigenere-table.png" class="figure-img img-fluid rounded" alt="Columns show the plaintext message, rows show the key">
  <figcaption class="figure-caption"><p>Vigenère Table</p>
    <small>Columns show the plaintext message, rows show the key</small>
  </figcaption>
</figure>

<p>It may look dense but it’s not so complicated.
If you look at the rows, you see the Latin alphabet shifted by one letter per row.
Similarly for the columns.</p>
<p>The cipher works by taking the letter at the intersection of the plaintext letter (columns) and the key letter (rows).
That intersection letter is the ciphertext letter.</p>
<p>Example:</p>
<h4 id="encryption">Encryption</h4>
<p>Take the message: &ldquo;J&rsquo;ai plaqué mon chêne&rdquo; (excerpt from &ldquo;Auprès de mon arbre&rdquo; by Georges Brassens)</p>
<p>And the key: &ldquo;Una mattina&rdquo; (excerpt from &ldquo;Bella Ciao&rdquo;)</p>
<p>Look at the intersection of each letter:</p>
<p>Column &ldquo;J&rdquo; and row &ldquo;U&rdquo; give &ldquo;D&rdquo;,
column &ldquo;a&rdquo; (ignoring the apostrophe for now) and row &ldquo;n&rdquo; give &ldquo;n&rdquo;,
column &ldquo;i&rdquo; and row &ldquo;a&rdquo; give &ldquo;i&rdquo;,
etc.</p>
<p>If the message is longer than the key, repeat the key. Consider &ldquo;ê&rdquo; and &ldquo;é&rdquo; as &ldquo;e&rdquo;.</p>
<p>We get:
&ldquo;D ni bltjcr mia ctegx&rdquo;</p>
<h4 id="decryption">Decryption</h4>
<p>For decryption, for each row corresponding to the key letter, find where the ciphertext letter is located and take the letter at the top of that column, which is the plaintext letter.</p>
<p>So, taking the key: &ldquo;Una mattina&rdquo;
And the ciphertext: &ldquo;D ni bltjcr mia ctegx&rdquo;</p>
<p>In row &ldquo;U&rdquo;, letter &ldquo;D&rdquo; is at the 10th position, so column &ldquo;J&rdquo;,
in row &ldquo;n&rdquo;, letter &ldquo;n&rdquo; is at the 1st position, column &ldquo;a&rdquo;,
etc.</p>
<p>We recover:
&ldquo;J ai plaque mon chene&rdquo;</p>
<h3 id="congruence-representation">Congruence Representation</h3>
<p>The second representation is mathematical: congruence. If you don’t know this word, check 
<a href="https://michee.io/en-us/posts/the-congruence-the-modulo/">this article</a>.</p>
<p>To use congruence, substitute letters with numbers using the rule:</p>
<pre><code>A=0, B=1, C=2, D=3, E=4, F=5, G=6, H=7, I=8, J=9, K=10, L=11, M=12, N=13, O=14, P=15, Q=16, R=17, S=18, T=19, U=20, V=21, W=22, X=23, Y=24, Z=25
</code></pre>
<p>To encrypt, add the key to the message. To decrypt, subtract the key from the message.</p>
<p>Example:</p>
<h4 id="encryption-1">Encryption</h4>
<p>Take the message: &ldquo;J’ai plaqué mon chêne&rdquo;
And the key: &ldquo;Una mattina&rdquo;</p>
<p>Align the message and key (removing apostrophes and accents) and repeat the key to cover the message:</p>
<pre><code>&quot;J ai plaque mon chene&quot;
+
&quot;Una mattina Una matti&quot;
=
9
+
20
=
29
</code></pre>
<p>There’s no letter with value 29 (max is 25), so we use congruence modulo 26 (numbers 0 to 25).</p>
<p>Thus,</p>
<p>$$
29 \equiv 29-26 \pmod{26} \equiv 3 \pmod{26} = D
$$</p>
<p>We continue calculating:</p>
<pre><code>&quot;J ai plaque mon chene&quot;
+
&quot;Una mattina Una matti&quot;
=
9
+
20
=
29
≡
3 mod(26)
=
D
</code></pre>
<p>And so on. We get the ciphertext: &ldquo;D ni bltjcr mia ctegx&rdquo;</p>
<h4 id="decryption-1">Decryption</h4>
<p>To decrypt, subtract the key from the ciphertext, again using congruence.</p>
<pre><code>&quot;D ni bltjcr mia ctegx&quot;
-
&quot;Una mattina Una matti&quot;
=
3
-
20
=
-17
≡
-17+26 mod(26)
≡
9 mod(26)
=
J
</code></pre>
<p>Step by step, we return to:
&ldquo;J ai plaque mon chene&rdquo;</p>
<h2 id="variants">Variants</h2>
<p>The Vigenère cipher has known many variations. Here are a few:</p>
<h3 id="the-bellaso-precursor">The Bellaso Precursor</h3>
<p>Before Vigenère, there was Bellaso.
But the poor man was overshadowed by another Italian, better known in his time, Giovanni Della Porta, and later by Vigenère.
So sometimes it’s called the Porta/Bellaso cipher.</p>
<p>This cipher uses the following table:</p>
<table>
  <thead>
      <tr>
          <th>Key</th>
          <th>Substitution</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>AB</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>N O P Q R S T U V W X Y Z</td>
      </tr>
      <tr>
          <td>CD</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>Z N O P Q R S T U V W X Y</td>
      </tr>
      <tr>
          <td>EF</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>Y Z N O P Q R S T U V W X</td>
      </tr>
      <tr>
          <td>GH</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>X Y Z N O P Q R S T U V W</td>
      </tr>
      <tr>
          <td>IJ</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>W X Y Z N O P Q R S T U V</td>
      </tr>
      <tr>
          <td>KL</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>V W X Y Z N O P Q R S T U</td>
      </tr>
      <tr>
          <td>MN</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>U V W X Y Z N O P Q R S T</td>
      </tr>
      <tr>
          <td>OP</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>T U V W X Y Z N O P Q R S</td>
      </tr>
      <tr>
          <td>QR</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>S T U V W X Y Z N O P Q R</td>
      </tr>
      <tr>
          <td>ST</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>R S T U V W X Y Z N O P Q</td>
      </tr>
      <tr>
          <td>UV</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>Q R S T U V W X Y Z N O P</td>
      </tr>
      <tr>
          <td>WX</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>P Q R S T U V W X Y Z N O</td>
      </tr>
      <tr>
          <td>YZ</td>
          <td>A B C D E F G H I J K L M</td>
      </tr>
      <tr>
          <td></td>
          <td>O P Q R S T U V W X Y Z N</td>
      </tr>
  </tbody>
</table>
<p>The left column contains the key letter, and the right column contains the substitution.</p>
<p>A quick example to show how it works:</p>
<h4 id="encryption-2">Encryption</h4>
<p>Take the message: &ldquo;Trois Anneaux pour les Rois Elfes&rdquo; (excerpt from Tolkien’s &ldquo;The Lord of the Rings&rdquo; in french)</p>
<p>With the key: &ldquo;La République Galactique&rdquo; (excerpt from Lucas’s &ldquo;Star Wars&rdquo; in french)</p>
<p>The first key letter is &ldquo;L&rdquo;.</p>
<p>Look for this letter in the first column; &ldquo;L&rdquo; is in the sixth row with &ldquo;K&rdquo;.</p>
<p>The first letter of the message is &ldquo;T&rdquo;. Find &ldquo;T&rdquo; in the second column on the sixth row.</p>
<p>You see that &ldquo;T&rdquo; is below &ldquo;L&rdquo; (in the two lines present in each second column row), so the ciphertext letter is &ldquo;L&rdquo;.</p>
<p>Next, the second key letter is &ldquo;a&rdquo; (to make sure you’re following).</p>
<p>It is in the first row of the first column. The second plaintext letter is &ldquo;r&rdquo;.</p>
<p>In the second column of the first row, &ldquo;r&rdquo; is below &ldquo;e&rdquo;, so the ciphertext letter is &ldquo;e&rdquo;.</p>
<p>Then:</p>
<ul>
<li>&ldquo;R&rdquo;: 9th row: &ldquo;o&rdquo; becomes &ldquo;j&rdquo;,</li>
<li>&ldquo;e&rdquo;: 3rd row: &ldquo;i&rdquo; becomes &ldquo;t&rdquo; (&ldquo;i&rdquo; is above &ldquo;t&rdquo;),</li>
<li>etc.</li>
</ul>
<p>The ciphertext is:
&ldquo;Lejtm qafnsem fbme xvb ijyh zyxpm&rdquo;</p>
<h4 id="decryption-2">Decryption</h4>
<p>Use the key to find the row and match. So:</p>
<p>With the key: &ldquo;La République Galactique&rdquo;
And ciphertext: &ldquo;Lejtm qafnsem fbme xvb ijyh zyxpm&rdquo;</p>
<ul>
<li>&ldquo;L&rdquo;: 6th row: &ldquo;L&rdquo; becomes &ldquo;T&rdquo;,</li>
<li>&ldquo;a&rdquo;: 1st row: &ldquo;e&rdquo; becomes &ldquo;r&rdquo;,</li>
<li>etc.</li>
</ul>
<p>You recover the message: &ldquo;Trois Anneaux pour les Rois Elfes&rdquo;</p>
<h3 id="beaufort">Beaufort</h3>
<p>We’ll quickly cover this and the next variant. The only difference from Vigenère is that instead of adding the key to the message to encrypt, you subtract the message from the key.</p>
<p>So to decrypt, subtract the ciphertext from the key:</p>
<p>Key – Message = Ciphertext ⇒ Message = Key – Ciphertext</p>
<p>Of course, this is in the congruence representation.</p>
<h3 id="german-variant-of-beaufort">German Variant of Beaufort</h3>
<p>For this variant, it’s the opposite. Subtract the key from the message to encrypt.</p>
<p>To decrypt, add the ciphertext to the key:</p>
<p>Message – Key = Ciphertext ⇒ Message = Key + Ciphertext</p>
<h3 id="disordered-alphabet">Disordered Alphabet</h3>
<p>You can shuffle the letters of the alphabet. If both correspondents have the same table, the system works.</p>
<p>Of course, each letter must appear only once per column and row.</p>
<p>Also, all letters must appear in every column and row.</p>
<p>For example, consider these values:</p>
<pre><code>C=0, E=1, A=2, Z=3, B=4, D=5, F=6, G=7, H=8, I=9, J=10, K=11, L=12, M=13, N=14, O=15, P=16, Q=17, R=18, S=19, U=20, T=21, V=22, W=23, X=24, Y=25
</code></pre>
<h3 id="expanded-or-different-alphabet">Expanded or Different Alphabet</h3>
<p>We worked with a 26-letter Latin alphabet but nothing stops you from expanding it to include extra symbols or using a different alphabet.</p>
<p>For example:</p>
<pre><code>A=0, B=1, C=2, D=3, E=4, F=5, G=6, H=7, I=8, J=9, K=10, L=11, M=12, N=13, O=14, P=15, Q=16, R=17, S=18, T=19, U=20, V=21, W=22, X=23, Y=24, Z=25,!=26,?=27
</code></pre>
<p>In this case, we have modulo 28 instead of 26.</p>
<h3 id="bellaso-variants">Bellaso Variants</h3>
<p>We used Bellaso’s original table but nothing prevents modifying it.</p>
<p>You could have three letters in the first column instead of two and reduce the number of rows accordingly.</p>
<p>Or have a different number of letters per row.</p>
<p>Or change the alphabet substitutions in the second column.</p>
<p>The only requirement is that your alphabet’s number of letters/symbols is even so each symbol has a match in the second column.</p>
<h2 id="weaknesses">Weaknesses</h2>
<h3 id="frequency-analysis-attack">Frequency Analysis Attack</h3>
<p>As mentioned in the historical preamble, this cipher and its variants were broken in the 19th century.</p>
<p>It suffers from the same weakness, though much more resilient, as the Caesar cipher.</p>
<p>Languages do not use letters with the same frequencies. For example, in French, the letter &ldquo;e&rdquo; is much more frequent than others.</p>
<p>An attacker can exploit these frequency differences to guess the message or the key.</p>
<p>But unlike Caesar’s cipher, there is a preliminary step.</p>
<p>The attacker must first try to guess the length of the key. This allows segmenting the ciphertext into equal-length segments.</p>
<p>To do this, they look for patterns in the ciphertext — groups of three letters or more that appear regularly.</p>
<p>Languages also have common patterns: for example, &ldquo;les&rdquo; appears frequently in French.</p>
<p>It’s more likely the same part of the key falls on the same plaintext pattern, encrypting it the same way, than by pure chance.</p>
<p>By spotting these patterns, the attacker estimates the key length and can segment the ciphertext.</p>
<p>Each plaintext letter in a segment is encrypted by the same key letter, allowing frequency analysis.</p>
<p>This might seem obscure or confusing. Don’t worry, a future article will clarify this with examples.</p>
<p>The Vigenère cipher is halfway between the Caesar cipher, from which it takes the substitution rule, and the one-time pad, which is the perfect algorithm, appearing only at the beginning of the 20th century.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Caesar cipher</title>
      <link>https://michee.io/en-us/posts/the-caesar-cipher/</link>
      <pubDate>Wed, 19 Nov 2025 16:00:00 +0000</pubDate>
      <guid>https://michee.io/en-us/posts/the-caesar-cipher/</guid>
      <description>One of the oldest encryptions in history. It is incorrectly attributed to Caesar and remains very poor.</description>
      <content:encoded><![CDATA[<h2 id="a-bit-of-history">A bit of history</h2>
<p>The Caesar cipher, despite its name, was apparently already used by the Spartans, so well before Julius Caesar.</p>
<p>It’s a variation of shift cipher, which is a substitution cipher. Complicated words for simple concepts, you’ll see.</p>
<p>Augustus used another variant of the Caesar cipher.</p>
<p>It’s very possible that it inspired the Vigenère cipher.</p>
<p>Note: This post was translated from french with the help of AI. The original post was written with the knowledge of a younger me.</p>
<h2 id="the-big-picture-substitution">The big picture: substitution</h2>
<p>Let’s start with the broadest concept. Substitution ciphering consists of replacing one letter with another. Plain and simple.</p>
<p>This technique is the most widespread in history and it is different from permutation, which consists of changing the order of the letters in a text.</p>
<p>Modern algorithms use both methods at once because substitution alone is not very secure cryptographically (except in the very specific case of a one-time pad).</p>
<h2 id="the-medium-picture-the-shift">The medium picture: the shift</h2>
<p>Among substitution cipher methods, the simplest is the shift method.</p>
<p>It’s a monoalphabetic ciphering method (another complicated term for a simple concept).
That means that one letter is associated (during encryption/decryption) with exactly one other letter.
Two different letters cannot result in the same letter after encryption/decryption, and likewise, one letter cannot produce two different letters after encryption/decryption.</p>
<p>For mathematicians, this is a bijective relation.</p>
<p>The shift method therefore consists in shifting a letter within the alphabet.</p>
<h2 id="the-small-picture-the-caesar-cipher">The small picture: the Caesar cipher</h2>
<p>Nowadays, the term “Caesar cipher” refers to all these shift cipher methods, but more precisely to a shift by 3.</p>
<p>Let’s take the Latin alphabet, the one used by Caesar (even though it seems he preferred the Greek alphabet for his secret messages), and assign values to the letters:</p>
<pre><code>A=0, B=1, C=2, D=3, E=4, F=5, G=6, H=7, I=8, J=9, K=10, L=11, M=12, N=13, O=14, P=15, Q=16, R=17, S=18, T=19, U=20, V=21, W=22, X=23, Y=24, Z=25
</code></pre>
<p>We apply a shift of 3:</p>
<pre><code>A=0+3=3=D

B=1+3=4=E

…
</code></pre>
<p>However, you can see that if we do:</p>
<pre><code>X=23+3=26
</code></pre>
<p>we don’t know what letter 26 is, unless we use congruence. If this word is unfamiliar, read 
<a href="https://michee.io/en-us/posts/the-congruence-the-modulo/">this article</a>.</p>
<p>We’ll consider the Latin alphabet in <em>modulo</em> 26. So, if we redo the calculation:</p>
<pre><code>X=23+3=26 ≡ 26-26 *mod*(26) ≡ 0 *mod*(26) ≡ A
</code></pre>
<p>So, in the Caesar cipher, A becomes D, B becomes E, X becomes A, Y becomes B, Z becomes C…</p>
<p>We’ve shifted the letters by 3 positions.</p>
<p>An example:</p>
<p>Consider the message: “CAVE CANEM” (“Beware of the dog”, in Latin)</p>
<p>We apply the Caesar cipher:</p>
<pre><code>“C A V E C A N E M”

=

2 0 21 4 2 0 13 4 12

+3

=

5 3 24 7 5 3 16 7 15

=

“F D Y H F D Q H P”
</code></pre>
<p>Here’s your encrypted message. And to decrypt it, we do the opposite: subtract 3 from the letters of the encrypted message.</p>
<p>It’s simple, isn’t it? And you can see we’re at cryptography level 0.</p>
<p>But at the time, it seemed good enough.</p>
<h2 id="variants">Variants</h2>
<p>Of course, variants of this cipher have been developed throughout history.</p>
<h3 id="rot13">ROT13</h3>
<p>This variant consists of shifting by 13 letters instead of 3. “ROT” is short for rotation, because a shift with a <em>modulo</em> can be seen as a rotation.</p>
<p>This shift is special because it’s symmetric for a 26-letter alphabet (13 being half of 26).
That means that if you encrypt a message twice with this shift, you get the original message back.</p>
<p>Example:</p>
<p>First encryption:</p>
<pre><code>“C A V E C A N E M”

=

2 0 21 4 2 0 13 4 12

+13

=

15 13 34-26 17 15 13 26-26 17 25

=

15 13 8 17 15 13 0 17 25

=

“P N I R P N A R Z”
</code></pre>
<p>Second encryption:</p>
<pre><code>“P N I R P N A R Z”

=

15 13 8 17 15 13 0 17 25

+13

=

28-26 26-26 21 30-26 28-26 26-26 13 30-26 38-26

=

2 0 21 4 2 0 13 4 12

=

“C A V E C A N E M”
</code></pre>
<p>Tadaa, we recover “Cave Canem”.</p>
<h3 id="augustus">Augustus</h3>
<p>I said earlier that the Caesar cipher was useless. Wait until you see this one. Forget about <em>modulo</em>, that’s too complicated, and counting to 3 is also too complicated—just count to 1, that’s fine.</p>
<p>Augustus (Caesar’s nephew) used a shift cipher of 1. Yes, you read that right—1. Oh, and what about “z”? Remember, no congruence. So “z” becomes “aa”—yes, two “a”s.</p>
<p>Do I really need to give you an example?</p>
<h3 id="7up-k9">7up, K9</h3>
<p>Of course, there are also ciphers based on wordplay, invented for children’s games.</p>
<p>“7up” is a shift of 7.</p>
<p>“K9” is a reference to the robot dog from Dr Who (and also a very good mail app for Android…).
It’s a pun on the word “canine” of course. It’s a shift of 1 backward (25 forward).</p>
<h3 id="extending-the-alphabet">Extending the alphabet</h3>
<p>You can, of course, use an alphabet other than the Latin alphabet, or even take an arbitrary order of symbols. All that’s required is that the symbols be ordered.</p>
<p>Example:</p>
<p>Let’s take this fictional alphabet:</p>
<pre><code>“: ; ! , t 2 5”
</code></pre>
<p>If we apply an increment of 3, we get:</p>
<pre><code>“, t 2 5 : ; !”
</code></pre>
<h2 id="how-bad-this-is">How bad this is</h2>
<p>By now you understand just how bad this system is. Let’s look at two methods to break a cipher made with this technique.</p>
<h3 id="frequency-analysis">Frequency analysis</h3>
<p>Every language has letters that appear more frequently than others. For example, in French “e” is (by far) the most frequent letter.
So, an attacker just needs to analyze the frequency of symbols in the message.
If the encrypted message contains a lot of “g”s and the parties are French, the attacker can hypothesize a shift of 2 and easily recover the original text.</p>
<h3 id="brute-force-attack">Brute-force attack</h3>
<p>For a 26-letter alphabet, there are 26 possible combinations. It’s really not hard to test them all.</p>
<p>Testing all combinations is called a brute-force attack.
It’s the dumbest (the most brute) approach: you test every possibility.
But it’s also the attack that requires the most resources, since you’re testing everything.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
