message_cipher.rsa_system module

RSA Crypto System module.

Provides a convenient class that simultaneously acts as both an RsaEncrypter and an RsaDecrypter.

class message_cipher.rsa_system.RSA

Bases: Cipher, RsaEncrypter, RsaDecrypter

RSA crypto-system constructor.

Performs calculations to encrypt strings into an array of integers, and then decrypt those arrays back into strings.

This implements a simplified version of the RSA encryption algorithm.

__init__(prime1: int = 0, prime2: int = 0, exponent: int = 0) None

Initialize a new RSA system with values prime1 and prime2.

Parameters:
  • prime1 (int) – First prime number for the RSA system.

  • prime2 (int) – Second prime number for the RSA system.

  • exponent (int) – The exponent used for encryption (optional).

Return type:

None

message_cipher.rsa_system.invertible_elements(number: int) list[int]

Calculate all numbers invertible modulo number.

Parameters:

number (int) – The modulo to find invertible numbers in.

Returns:

A list of all invertible elements.

Return type:

list[int]

message_cipher.rsa_system.is_prime(number: int) bool

Determine whether a number is prime.

Check all possible factors of number up to sqrt(number) to determine its primality.

Parameters:

number (int) – A number to check the primality of.

Returns:

True if number is prime, otherwise False.

Return type:

bool