@@ -7,51 +7,58 @@ def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
77 """
88 encrypt
99 =======
10+
1011 Encodes a given string with the caesar cipher and returns the encoded
1112 message
1213
1314 Parameters:
1415 -----------
15- * input_string: the plain-text that needs to be encoded
16- * key: the number of letters to shift the message by
16+
17+ * `input_string`: the plain-text that needs to be encoded
18+ * `key`: the number of letters to shift the message by
1719
1820 Optional:
19- * alphabet (None): the alphabet used to encode the cipher, if not
21+
22+ * `alphabet` (``None``): the alphabet used to encode the cipher, if not
2023 specified, the standard english alphabet with upper and lowercase
2124 letters is used
2225
2326 Returns:
27+
2428 * A string containing the encoded cipher-text
2529
2630 More on the caesar cipher
2731 =========================
32+
2833 The caesar cipher is named after Julius Caesar who used it when sending
2934 secret military messages to his troops. This is a simple substitution cipher
3035 where every character in the plain-text is shifted by a certain number known
3136 as the "key" or "shift".
3237
3338 Example:
3439 Say we have the following message:
35- " Hello, captain"
40+ `` Hello, captain``
3641
3742 And our alphabet is made up of lower and uppercase letters:
38- " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
43+ `` abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ``
3944
40- And our shift is "2"
45+ And our shift is ``2``
4146
42- We can then encode the message, one letter at a time. "H" would become "J" ,
43- since "J" is two letters away, and so on. If the shift is ever two large, or
47+ We can then encode the message, one letter at a time. ``H`` would become ``J`` ,
48+ since ``J`` is two letters away, and so on. If the shift is ever two large, or
4449 our letter is at the end of the alphabet, we just start at the beginning
45- ("Z" would shift to "a" then "b" and so on).
50+ (``Z`` would shift to ``a`` then ``b`` and so on).
4651
47- Our final message would be " Jgnnq, ecrvckp"
52+ Our final message would be `` Jgnnq, ecrvckp``
4853
4954 Further reading
5055 ===============
56+
5157 * https://en.m.wikipedia.org/wiki/Caesar_cipher
5258
5359 Doctests
5460 ========
61+
5562 >>> encrypt('The quick brown fox jumps over the lazy dog', 8)
5663 'bpm yCqks jzwEv nwF rCuxA wDmz Bpm tiHG lwo'
5764
@@ -85,23 +92,28 @@ def decrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
8592 """
8693 decrypt
8794 =======
95+
8896 Decodes a given string of cipher-text and returns the decoded plain-text
8997
9098 Parameters:
9199 -----------
92- * input_string: the cipher-text that needs to be decoded
93- * key: the number of letters to shift the message backwards by to decode
100+
101+ * `input_string`: the cipher-text that needs to be decoded
102+ * `key`: the number of letters to shift the message backwards by to decode
94103
95104 Optional:
96- * alphabet (None): the alphabet used to decode the cipher, if not
105+
106+ * `alphabet` (``None``): the alphabet used to decode the cipher, if not
97107 specified, the standard english alphabet with upper and lowercase
98108 letters is used
99109
100110 Returns:
111+
101112 * A string containing the decoded plain-text
102113
103114 More on the caesar cipher
104115 =========================
116+
105117 The caesar cipher is named after Julius Caesar who used it when sending
106118 secret military messages to his troops. This is a simple substitution cipher
107119 where very character in the plain-text is shifted by a certain number known
@@ -110,27 +122,29 @@ def decrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
110122
111123 Example:
112124 Say we have the following cipher-text:
113- " Jgnnq, ecrvckp"
125+ `` Jgnnq, ecrvckp``
114126
115127 And our alphabet is made up of lower and uppercase letters:
116- " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
128+ `` abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ``
117129
118- And our shift is "2"
130+ And our shift is ``2``
119131
120132 To decode the message, we would do the same thing as encoding, but in
121- reverse. The first letter, "J" would become "H" (remember: we are decoding)
122- because "H" is two letters in reverse (to the left) of "J" . We would
123- continue doing this. A letter like "a" would shift back to the end of
124- the alphabet, and would become "Z" or "Y" and so on.
133+ reverse. The first letter, ``J`` would become ``H`` (remember: we are decoding)
134+ because ``H`` is two letters in reverse (to the left) of ``J`` . We would
135+ continue doing this. A letter like ``a`` would shift back to the end of
136+ the alphabet, and would become ``Z`` or ``Y`` and so on.
125137
126- Our final message would be " Hello, captain"
138+ Our final message would be `` Hello, captain``
127139
128140 Further reading
129141 ===============
142+
130143 * https://en.m.wikipedia.org/wiki/Caesar_cipher
131144
132145 Doctests
133146 ========
147+
134148 >>> decrypt('bpm yCqks jzwEv nwF rCuxA wDmz Bpm tiHG lwo', 8)
135149 'The quick brown fox jumps over the lazy dog'
136150
@@ -150,41 +164,44 @@ def brute_force(input_string: str, alphabet: str | None = None) -> dict[int, str
150164 """
151165 brute_force
152166 ===========
167+
153168 Returns all the possible combinations of keys and the decoded strings in the
154169 form of a dictionary
155170
156171 Parameters:
157172 -----------
158- * input_string: the cipher-text that needs to be used during brute-force
173+
174+ * `input_string`: the cipher-text that needs to be used during brute-force
159175
160176 Optional:
161- * alphabet: (None): the alphabet used to decode the cipher, if not
177+
178+ * `alphabet` (``None``): the alphabet used to decode the cipher, if not
162179 specified, the standard english alphabet with upper and lowercase
163180 letters is used
164181
165182 More about brute force
166183 ======================
184+
167185 Brute force is when a person intercepts a message or password, not knowing
168186 the key and tries every single combination. This is easy with the caesar
169187 cipher since there are only all the letters in the alphabet. The more
170188 complex the cipher, the larger amount of time it will take to do brute force
171189
172190 Ex:
173- Say we have a 5 letter alphabet (abcde), for simplicity and we intercepted the
174- following message:
175-
176- "dbc"
177-
191+ Say we have a ``5`` letter alphabet (``abcde``), for simplicity and we intercepted the
192+ following message: ``dbc``,
178193 we could then just write out every combination:
179- ecd... and so on, until we reach a combination that makes sense:
180- " cab"
194+ `` ecd`` ... and so on, until we reach a combination that makes sense:
195+ `` cab``
181196
182197 Further reading
183198 ===============
199+
184200 * https://en.wikipedia.org/wiki/Brute_force
185201
186202 Doctests
187203 ========
204+
188205 >>> brute_force("jFyuMy xIH'N vLONy zILwy Gy!")[20]
189206 "Please don't brute force me!"
190207
0 commit comments