You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
an ancient encryption system created in the Middle East.
3
+
Create an implementation of the affine cipher, an ancient encryption system created in the Middle East.
5
4
6
-
The affine cipher is a type of mono-alphabetic substitution cipher.
7
-
Each character is mapped to its numeric equivalent, encrypted with
8
-
a mathematical function and then converted to the letter relating to
9
-
its new numeric value. Although all mono-alphabetic ciphers are weak,
10
-
the affine cipher is much stronger than the atbash cipher,
11
-
because it has many more keys.
5
+
The affine cipher is a type of monoalphabetic substitution cipher.
6
+
Each character is mapped to its numeric equivalent, encrypted with a mathematical function and then converted to the letter relating to its new numeric value.
7
+
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the atbash cipher, because it has many more keys.
8
+
9
+
[comment]: #( monoalphabetic as spelled by Merriam-Webster, compare to polyalphabetic )
12
10
13
11
## Encryption
14
12
@@ -18,20 +16,21 @@ The encryption function is:
18
16
E(x) = (ai + b) mod m
19
17
```
20
18
21
-
- where `i` is the letter's index from `0` to the length of the alphabet - 1
22
-
-`m` is the length of the alphabet. For the Roman alphabet `m` is `26`.
19
+
Where:
20
+
21
+
-`i` is the letter's index from `0` to the length of the alphabet - 1
22
+
-`m` is the length of the alphabet.
23
+
For the Roman alphabet `m` is `26`.
23
24
-`a` and `b` are integers which make the encryption key
24
25
25
-
Values `a` and `m` must be *coprime* (or, *relatively prime*) for automatic decryption to succeed,
26
-
ie. they have number `1` as their only common factor (more information can be found in the
27
-
[Wikipedia article about coprime integers](https://en.wikipedia.org/wiki/Coprime_integers)). In case `a` is
28
-
not coprime to `m`, your program should indicate that this is an error. Otherwise it should
29
-
encrypt or decrypt with the provided key.
26
+
Values `a` and `m` must be *coprime* (or, *relatively prime*) for automatic decryption to succeed, i.e., they have number `1` as their only common factor (more information can be found in the [Wikipedia article about coprime integers][coprime-integers]).
27
+
In case `a` is not coprime to `m`, your program should indicate that this is an error.
28
+
Otherwise it should encrypt or decrypt with the provided key.
30
29
31
-
For the purpose of this exercise, digits are valid input but they are not encrypted. Spaces and punctuation
32
-
characters are excluded. Ciphertext is written out in groups of fixed length separated by space,
33
-
the traditional group size being `5` letters. This is to make it harder to guess encrypted text based
34
-
on word boundaries.
30
+
For the purpose of this exercise, digits are valid input but they are not encrypted.
31
+
Spaces and punctuation characters are excluded.
32
+
Ciphertext is written out in groups of fixed length separated by space, the traditional group size being `5` letters.
33
+
This is to make it harder to guess encrypted text based on word boundaries.
35
34
36
35
## Decryption
37
36
@@ -41,9 +40,10 @@ The decryption function is:
41
40
D(y) = (a^-1)(y - b) mod m
42
41
```
43
42
44
-
- where `y` is the numeric value of an encrypted letter, ie. `y = E(x)`
45
-
- it is important to note that `a^-1` is the modular multiplicative inverse (MMI)
46
-
of `a mod m`
43
+
Where:
44
+
45
+
-`y` is the numeric value of an encrypted letter, i.e., `y = E(x)`
46
+
- it is important to note that `a^-1` is the modular multiplicative inverse (MMI) of `a mod m`
47
47
- the modular multiplicative inverse only exists if `a` and `m` are coprime.
48
48
49
49
The MMI of `a` is `x` such that the remainder after dividing `ax` by `m` is `1`:
@@ -52,8 +52,7 @@ The MMI of `a` is `x` such that the remainder after dividing `ax` by `m` is `1`:
52
52
ax mod m = 1
53
53
```
54
54
55
-
More information regarding how to find a Modular Multiplicative Inverse
56
-
and what it means can be found in the [related Wikipedia article](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse).
55
+
More information regarding how to find a Modular Multiplicative Inverse and what it means can be found in the [related Wikipedia article][MMI].
0 commit comments