Skip to content

Commit 8df7482

Browse files
authored
Merge pull request sympy#20259 from Soumi7/GSoD_crypto
Added required sections in sympy.crypto.
2 parents ab86496 + f2575df commit 8df7482

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed

sympy/crypto/crypto.py

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ def encipher_rot13(msg, symbols=None):
298298
"""
299299
Performs the ROT13 encryption on a given plaintext ``msg``.
300300
301-
Notes
302-
=====
301+
Explanation
302+
===========
303303
304304
ROT13 is a substitution cipher which substitutes each letter
305305
in the plaintext message for the letter furthest away from it
@@ -326,8 +326,8 @@ def decipher_rot13(msg, symbols=None):
326326
"""
327327
Performs the ROT13 decryption on a given plaintext ``msg``.
328328
329-
Notes
330-
=====
329+
Explanation
330+
============
331331
332332
``decipher_rot13`` is equivalent to ``encipher_rot13`` as both
333333
``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):
360360
Performs the affine cipher encryption on plaintext ``msg``, and
361361
returns the ciphertext.
362362
363+
Explanation
364+
===========
365+
363366
Encryption is based on the map `x \rightarrow ax+b` (mod `N`)
364367
where ``N`` is the number of characters in the alphabet.
365368
Decryption is based on the map `x \rightarrow cx+d` (mod `N`),
@@ -463,8 +466,8 @@ def encipher_atbash(msg, symbols=None):
463466
r"""
464467
Enciphers a given ``msg`` into its Atbash ciphertext and returns it.
465468
466-
Notes
467-
=====
469+
Explanation
470+
===========
468471
469472
Atbash is a substitution cipher originally used to encrypt the Hebrew
470473
alphabet. Atbash works on the principle of mapping each alphabet to its
@@ -486,8 +489,8 @@ def decipher_atbash(msg, symbols=None):
486489
r"""
487490
Deciphers a given ``msg`` using Atbash cipher and returns it.
488491
489-
Notes
490-
=====
492+
Explanation
493+
===========
491494
492495
``decipher_atbash`` is functionally equivalent to ``encipher_atbash``.
493496
However, it has still been added as a separate function to maintain
@@ -530,8 +533,8 @@ def encipher_substitution(msg, old, new=None):
530533
If ``old`` is a mapping, then new is ignored and the replacements
531534
defined by ``old`` are used.
532535
533-
Notes
534-
=====
536+
Explanation
537+
===========
535538
536539
This is a more general than the affine cipher in that the key can
537540
only be recovered by determining the mapping for each symbol.
@@ -612,8 +615,8 @@ def encipher_vigenere(msg, key, symbols=None):
612615
>>> decipher_vigenere(msg, key, alp)
613616
'BETWEENSUBTLESHADINGANDTHEABSENC'
614617
615-
Notes
616-
=====
618+
Explanation
619+
===========
617620
618621
The Vigenere cipher is named after Blaise de Vigenere, a sixteenth
619622
century diplomat and cryptographer, by a historical accident.
@@ -785,8 +788,8 @@ def encipher_hill(msg, key, symbols=None, pad="Q"):
785788
r"""
786789
Return the Hill cipher encryption of ``msg``.
787790
788-
Notes
789-
=====
791+
Explanation
792+
===========
790793
791794
The Hill cipher [1]_, invented by Lester S. Hill in the 1920's [2]_,
792795
was the first polygraphic cipher in which it was practical
@@ -1156,6 +1159,9 @@ def encipher_bifid5(msg, key):
11561159
Performs the Bifid cipher encryption on plaintext ``msg``, and
11571160
returns the ciphertext.
11581161
1162+
Explanation
1163+
===========
1164+
11591165
This is the version of the Bifid cipher that uses the `5 \times 5`
11601166
Polybius square. The letter "J" is ignored so it must be replaced
11611167
with something else (traditionally an "I") before encryption.
@@ -1259,6 +1265,9 @@ def decipher_bifid5(msg, key):
12591265
r"""
12601266
Return the Bifid cipher decryption of ``msg``.
12611267
1268+
Explanation
1269+
===========
1270+
12621271
This is the version of the Bifid cipher that uses the `5 \times 5`
12631272
Polybius square; the letter "J" is ignored unless a ``key`` of
12641273
length 25 is used.
@@ -1449,7 +1458,7 @@ def _decipher_rsa_crt(i, d, factors):
14491458
Ciphertext
14501459
14511460
d : integer
1452-
The exponent component
1461+
The exponent component.
14531462
14541463
factors : list of relatively-prime integers
14551464
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
14911500
==========
14921501
14931502
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.
14951504
14961505
totient : 'Euler' or 'Carmichael'
14971506
Different notation used for totient.
@@ -2041,6 +2050,11 @@ def decipher_rsa(i, key, factors=None):
20412050
20422051
>>> decipher_rsa(new_msg, prk, factors=[p, q])
20432052
12
2053+
2054+
See Also
2055+
========
2056+
2057+
encipher_rsa
20442058
"""
20452059
return _encipher_decipher_rsa(i, key, factors=factors)
20462060

@@ -2053,6 +2067,9 @@ def kid_rsa_public_key(a, b, A, B):
20532067
Kid RSA is a version of RSA useful to teach grade school children
20542068
since it does not involve exponentiation.
20552069
2070+
Explanation
2071+
===========
2072+
20562073
Alice wants to talk to Bob. Bob generates keys as follows.
20572074
Key generation:
20582075
@@ -2185,7 +2202,7 @@ def decipher_kid_rsa(msg, key):
21852202
def encode_morse(msg, sep='|', mapping=None):
21862203
"""
21872204
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``.
21892206
21902207
Examples
21912208
========
@@ -2231,7 +2248,7 @@ def encode_morse(msg, sep='|', mapping=None):
22312248

22322249
def decode_morse(msg, sep='|', mapping=None):
22332250
"""
2234-
Decodes a Morse Code with letters separated by `sep`
2251+
Decodes a Morse Code with letters separated by ``sep``
22352252
(default is '|') and words by `word_sep` (default is '||)
22362253
into plaintext.
22372254
@@ -2523,6 +2540,9 @@ def elgamal_private_key(digit=10, seed=None):
25232540
r"""
25242541
Return three number tuple as private key.
25252542
2543+
Explanation
2544+
===========
2545+
25262546
Elgamal encryption is based on the mathmatical problem
25272547
called the Discrete Logarithm Problem (DLP). For example,
25282548
@@ -2603,7 +2623,10 @@ def elgamal_public_key(key):
26032623

26042624
def encipher_elgamal(i, key, seed=None):
26052625
r"""
2606-
Encrypt message with public key
2626+
Encrypt message with public key.
2627+
2628+
Explanation
2629+
===========
26072630
26082631
``i`` is a plaintext message expressed as an integer.
26092632
``key`` is public key (p, r, e). In order to encrypt
@@ -2660,7 +2683,7 @@ def encipher_elgamal(i, key, seed=None):
26602683

26612684
def decipher_elgamal(msg, key):
26622685
r"""
2663-
Decrypt message with private key
2686+
Decrypt message with private key.
26642687
26652688
`msg = (c_{1}, c_{2})`
26662689
@@ -2703,6 +2726,9 @@ def dh_private_key(digit=10, seed=None):
27032726
r"""
27042727
Return three integer tuple as private key.
27052728
2729+
Explanation
2730+
===========
2731+
27062732
Diffie-Hellman key exchange is based on the mathematical problem
27072733
called the Discrete Logarithm Problem (see ElGamal).
27082734
@@ -2850,7 +2876,7 @@ def dh_shared_key(key, b):
28502876
def _legendre(a, p):
28512877
"""
28522878
Returns the legendre symbol of a and p
2853-
assuming that p is a prime
2879+
assuming that p is a prime.
28542880
28552881
i.e. 1 if a is a quadratic residue mod p
28562882
-1 if a is not a quadratic residue mod p
@@ -2895,6 +2921,9 @@ def gm_private_key(p, q, a=None):
28952921
the Goldwasser-Micali encryption. The method works
28962922
roughly as follows.
28972923
2924+
Explanation
2925+
===========
2926+
28982927
$\\cdot$ Pick two large primes $p$ and $q$.
28992928
29002929
$\\cdot$ Call their product $N$.
@@ -2963,7 +2992,7 @@ def gm_private_key(p, q, a=None):
29632992

29642993
def gm_public_key(p, q, a=None, seed=None):
29652994
"""
2966-
Compute public keys for p and q.
2995+
Compute public keys for ``p`` and ``q``.
29672996
Note that in Goldwasser-Micali Encryption,
29682997
public keys are randomly selected.
29692998
@@ -3143,6 +3172,9 @@ def bg_private_key(p, q):
31433172
Check if p and q can be used as private keys for
31443173
the Blum-Goldwasser cryptosystem.
31453174
3175+
Explanation
3176+
===========
3177+
31463178
The three necessary checks for p and q to pass
31473179
so that they can be used as private keys:
31483180
@@ -3185,6 +3217,9 @@ def bg_public_key(p, q):
31853217
"""
31863218
Calculates public keys from private keys.
31873219
3220+
Explanation
3221+
===========
3222+
31883223
The function first checks the validity of
31893224
private keys passed as arguments and
31903225
then returns their product.
@@ -3210,6 +3245,9 @@ def encipher_bg(i, key, seed=None):
32103245
"""
32113246
Encrypts the message using public key and seed.
32123247
3248+
Explanation
3249+
===========
3250+
32133251
ALGORITHM:
32143252
1. Encodes i as a string of L bits, m.
32153253
2. Select a random element r, where 1 < r < key, and computes
@@ -3272,6 +3310,9 @@ def decipher_bg(message, key):
32723310
"""
32733311
Decrypts the message using private keys.
32743312
3313+
Explanation
3314+
===========
3315+
32753316
ALGORITHM:
32763317
1. Let, c be the encrypted message, y the second number received,
32773318
and p and q be the private keys.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy