> key = PublicKey(n=143, e=113) > key.encrypt(142) # n - 1 142 > key.encrypt(143) # n 0 Also encrypting (or decrypting) 0 or 1 always returns 0 or 1: > key.encrypt(0) 0 > key.encrypt(1) 1 Note that sometimes the original and the encrypted messages are the same, as shown in the following example: > for x in range(143): # n. For example, encrypting (or decrypting) the number ``n - 1`` does nothing, and encrypting (or decrypting) the number ``n`` always returns 0. It's worth noting that ``n - 2`` is the highest number that can be safely encrypted or decrypted. ``n`` has the bit length specified with ``make_key_pair`` and is shared between the two keys ``e`` is used by the public key encrypt ``d`` is used by the private key to decrypt. The public key can be used to encrypt a message (in this module, a message is simply a positive integer number): > message = 5 > encrypted_message = public_key.encrypt(message) The encrypted information can be retrieved only with the private key: > private_key.decrypt(encrypted_message) 5 Private and public keys are made of three numeric parameters: ``n``, ``d`` and ``e``. The higher this number, the stronger the encryption. First, create a random key pair: > public_key, private_key = make_key_pair(8) The number 8 is the _key length_. ![]() ![]() This module is meant to show a simple and clear implementation of the RSA algorithm: (cryptosystem). """Simple implementation of the RSA cryptosystem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |