@@ -298,8 +298,8 @@ def encipher_rot13(msg, symbols=None):
298
298
"""
299
299
Performs the ROT13 encryption on a given plaintext ``msg``.
300
300
301
- Notes
302
- =====
301
+ Explanation
302
+ ===========
303
303
304
304
ROT13 is a substitution cipher which substitutes each letter
305
305
in the plaintext message for the letter furthest away from it
@@ -326,8 +326,8 @@ def decipher_rot13(msg, symbols=None):
326
326
"""
327
327
Performs the ROT13 decryption on a given plaintext ``msg``.
328
328
329
- Notes
330
- =====
329
+ Explanation
330
+ ============
331
331
332
332
``decipher_rot13`` is equivalent to ``encipher_rot13`` as both
333
333
``decipher_shift`` with a key of 13 and ``encipher_shift`` key with a
@@ -360,6 +360,9 @@ def encipher_affine(msg, key, symbols=None, _inverse=False):
360
360
Performs the affine cipher encryption on plaintext ``msg``, and
361
361
returns the ciphertext.
362
362
363
+ Explanation
364
+ ===========
365
+
363
366
Encryption is based on the map `x \rightarrow ax+b` (mod `N`)
364
367
where ``N`` is the number of characters in the alphabet.
365
368
Decryption is based on the map `x \rightarrow cx+d` (mod `N`),
@@ -463,8 +466,8 @@ def encipher_atbash(msg, symbols=None):
463
466
r"""
464
467
Enciphers a given ``msg`` into its Atbash ciphertext and returns it.
465
468
466
- Notes
467
- =====
469
+ Explanation
470
+ ===========
468
471
469
472
Atbash is a substitution cipher originally used to encrypt the Hebrew
470
473
alphabet. Atbash works on the principle of mapping each alphabet to its
@@ -486,8 +489,8 @@ def decipher_atbash(msg, symbols=None):
486
489
r"""
487
490
Deciphers a given ``msg`` using Atbash cipher and returns it.
488
491
489
- Notes
490
- =====
492
+ Explanation
493
+ ===========
491
494
492
495
``decipher_atbash`` is functionally equivalent to ``encipher_atbash``.
493
496
However, it has still been added as a separate function to maintain
@@ -530,8 +533,8 @@ def encipher_substitution(msg, old, new=None):
530
533
If ``old`` is a mapping, then new is ignored and the replacements
531
534
defined by ``old`` are used.
532
535
533
- Notes
534
- =====
536
+ Explanation
537
+ ===========
535
538
536
539
This is a more general than the affine cipher in that the key can
537
540
only be recovered by determining the mapping for each symbol.
@@ -612,8 +615,8 @@ def encipher_vigenere(msg, key, symbols=None):
612
615
>>> decipher_vigenere(msg, key, alp)
613
616
'BETWEENSUBTLESHADINGANDTHEABSENC'
614
617
615
- Notes
616
- =====
618
+ Explanation
619
+ ===========
617
620
618
621
The Vigenere cipher is named after Blaise de Vigenere, a sixteenth
619
622
century diplomat and cryptographer, by a historical accident.
@@ -785,8 +788,8 @@ def encipher_hill(msg, key, symbols=None, pad="Q"):
785
788
r"""
786
789
Return the Hill cipher encryption of ``msg``.
787
790
788
- Notes
789
- =====
791
+ Explanation
792
+ ===========
790
793
791
794
The Hill cipher [1]_, invented by Lester S. Hill in the 1920's [2]_,
792
795
was the first polygraphic cipher in which it was practical
@@ -1156,6 +1159,9 @@ def encipher_bifid5(msg, key):
1156
1159
Performs the Bifid cipher encryption on plaintext ``msg``, and
1157
1160
returns the ciphertext.
1158
1161
1162
+ Explanation
1163
+ ===========
1164
+
1159
1165
This is the version of the Bifid cipher that uses the `5 \times 5`
1160
1166
Polybius square. The letter "J" is ignored so it must be replaced
1161
1167
with something else (traditionally an "I") before encryption.
@@ -1259,6 +1265,9 @@ def decipher_bifid5(msg, key):
1259
1265
r"""
1260
1266
Return the Bifid cipher decryption of ``msg``.
1261
1267
1268
+ Explanation
1269
+ ===========
1270
+
1262
1271
This is the version of the Bifid cipher that uses the `5 \times 5`
1263
1272
Polybius square; the letter "J" is ignored unless a ``key`` of
1264
1273
length 25 is used.
@@ -1449,7 +1458,7 @@ def _decipher_rsa_crt(i, d, factors):
1449
1458
Ciphertext
1450
1459
1451
1460
d : integer
1452
- The exponent component
1461
+ The exponent component.
1453
1462
1454
1463
factors : list of relatively-prime integers
1455
1464
The integers given must be coprime and the product must equal
@@ -1491,7 +1500,7 @@ def _rsa_key(*args, public=True, private=True, totient='Euler', index=None, mult
1491
1500
==========
1492
1501
1493
1502
public, private : bool, optional
1494
- Flag to generate either a public key, a private key
1503
+ Flag to generate either a public key, a private key.
1495
1504
1496
1505
totient : 'Euler' or 'Carmichael'
1497
1506
Different notation used for totient.
@@ -2041,6 +2050,11 @@ def decipher_rsa(i, key, factors=None):
2041
2050
2042
2051
>>> decipher_rsa(new_msg, prk, factors=[p, q])
2043
2052
12
2053
+
2054
+ See Also
2055
+ ========
2056
+
2057
+ encipher_rsa
2044
2058
"""
2045
2059
return _encipher_decipher_rsa (i , key , factors = factors )
2046
2060
@@ -2053,6 +2067,9 @@ def kid_rsa_public_key(a, b, A, B):
2053
2067
Kid RSA is a version of RSA useful to teach grade school children
2054
2068
since it does not involve exponentiation.
2055
2069
2070
+ Explanation
2071
+ ===========
2072
+
2056
2073
Alice wants to talk to Bob. Bob generates keys as follows.
2057
2074
Key generation:
2058
2075
@@ -2185,7 +2202,7 @@ def decipher_kid_rsa(msg, key):
2185
2202
def encode_morse (msg , sep = '|' , mapping = None ):
2186
2203
"""
2187
2204
Encodes a plaintext into popular Morse Code with letters
2188
- separated by `sep` and words by a double `sep`.
2205
+ separated by `` sep`` and words by a double `` sep` `.
2189
2206
2190
2207
Examples
2191
2208
========
@@ -2231,7 +2248,7 @@ def encode_morse(msg, sep='|', mapping=None):
2231
2248
2232
2249
def decode_morse (msg , sep = '|' , mapping = None ):
2233
2250
"""
2234
- Decodes a Morse Code with letters separated by `sep`
2251
+ Decodes a Morse Code with letters separated by `` sep` `
2235
2252
(default is '|') and words by `word_sep` (default is '||)
2236
2253
into plaintext.
2237
2254
@@ -2523,6 +2540,9 @@ def elgamal_private_key(digit=10, seed=None):
2523
2540
r"""
2524
2541
Return three number tuple as private key.
2525
2542
2543
+ Explanation
2544
+ ===========
2545
+
2526
2546
Elgamal encryption is based on the mathmatical problem
2527
2547
called the Discrete Logarithm Problem (DLP). For example,
2528
2548
@@ -2603,7 +2623,10 @@ def elgamal_public_key(key):
2603
2623
2604
2624
def encipher_elgamal (i , key , seed = None ):
2605
2625
r"""
2606
- Encrypt message with public key
2626
+ Encrypt message with public key.
2627
+
2628
+ Explanation
2629
+ ===========
2607
2630
2608
2631
``i`` is a plaintext message expressed as an integer.
2609
2632
``key`` is public key (p, r, e). In order to encrypt
@@ -2660,7 +2683,7 @@ def encipher_elgamal(i, key, seed=None):
2660
2683
2661
2684
def decipher_elgamal (msg , key ):
2662
2685
r"""
2663
- Decrypt message with private key
2686
+ Decrypt message with private key.
2664
2687
2665
2688
`msg = (c_{1}, c_{2})`
2666
2689
@@ -2703,6 +2726,9 @@ def dh_private_key(digit=10, seed=None):
2703
2726
r"""
2704
2727
Return three integer tuple as private key.
2705
2728
2729
+ Explanation
2730
+ ===========
2731
+
2706
2732
Diffie-Hellman key exchange is based on the mathematical problem
2707
2733
called the Discrete Logarithm Problem (see ElGamal).
2708
2734
@@ -2850,7 +2876,7 @@ def dh_shared_key(key, b):
2850
2876
def _legendre (a , p ):
2851
2877
"""
2852
2878
Returns the legendre symbol of a and p
2853
- assuming that p is a prime
2879
+ assuming that p is a prime.
2854
2880
2855
2881
i.e. 1 if a is a quadratic residue mod p
2856
2882
-1 if a is not a quadratic residue mod p
@@ -2895,6 +2921,9 @@ def gm_private_key(p, q, a=None):
2895
2921
the Goldwasser-Micali encryption. The method works
2896
2922
roughly as follows.
2897
2923
2924
+ Explanation
2925
+ ===========
2926
+
2898
2927
$\\ cdot$ Pick two large primes $p$ and $q$.
2899
2928
2900
2929
$\\ cdot$ Call their product $N$.
@@ -2963,7 +2992,7 @@ def gm_private_key(p, q, a=None):
2963
2992
2964
2993
def gm_public_key (p , q , a = None , seed = None ):
2965
2994
"""
2966
- Compute public keys for p and q .
2995
+ Compute public keys for ``p`` and ``q`` .
2967
2996
Note that in Goldwasser-Micali Encryption,
2968
2997
public keys are randomly selected.
2969
2998
@@ -3143,6 +3172,9 @@ def bg_private_key(p, q):
3143
3172
Check if p and q can be used as private keys for
3144
3173
the Blum-Goldwasser cryptosystem.
3145
3174
3175
+ Explanation
3176
+ ===========
3177
+
3146
3178
The three necessary checks for p and q to pass
3147
3179
so that they can be used as private keys:
3148
3180
@@ -3185,6 +3217,9 @@ def bg_public_key(p, q):
3185
3217
"""
3186
3218
Calculates public keys from private keys.
3187
3219
3220
+ Explanation
3221
+ ===========
3222
+
3188
3223
The function first checks the validity of
3189
3224
private keys passed as arguments and
3190
3225
then returns their product.
@@ -3210,6 +3245,9 @@ def encipher_bg(i, key, seed=None):
3210
3245
"""
3211
3246
Encrypts the message using public key and seed.
3212
3247
3248
+ Explanation
3249
+ ===========
3250
+
3213
3251
ALGORITHM:
3214
3252
1. Encodes i as a string of L bits, m.
3215
3253
2. Select a random element r, where 1 < r < key, and computes
@@ -3272,6 +3310,9 @@ def decipher_bg(message, key):
3272
3310
"""
3273
3311
Decrypts the message using private keys.
3274
3312
3313
+ Explanation
3314
+ ===========
3315
+
3275
3316
ALGORITHM:
3276
3317
1. Let, c be the encrypted message, y the second number received,
3277
3318
and p and q be the private keys.
0 commit comments