![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Hill Cipher algorithm. More...
Static Public Member Functions | |
| static matrix< int > | generate_encryption_key (size_t size, int limit1=0, int limit2=10) |
| Generate encryption matrix of a given size. Larger size matrices are difficult to generate but provide more security. Important conditions are: | |
| static matrix< int > | generate_decryption_key (matrix< int > const &encrypt_key) |
| Generate decryption matrix from an encryption matrix key. | |
| static std::pair< matrix< int >, matrix< int > > | generate_keys (size_t size, int limit1=0, int limit2=10) |
| Generate encryption and decryption key pair. | |
| static const std::string | encrypt_text (const std::string &text, const matrix< int > &encrypt_key) |
| Encrypt a given text using a given key. | |
| static const std::string | decrypt_text (const std::string &text, const matrix< int > &decrypt_key) |
| Decrypt a given text using a given key. | |
Static Private Member Functions | |
| template<typename T1, typename T2> | |
| static const T2 | rand_range (T1 a, T1 b) |
| Function to generate a random integer in a given interval. | |
| template<typename T1, typename T2> | |
| static double | rand_range (matrix< T2 > *M, T1 a, T1 b) |
| Function overload to fill a matrix with random integers in a given interval. | |
| template<typename T> | |
| static const T | gcd (T a, T b) |
| Compute GCD of two integers using Euler's algorithm. | |
| static const std::valarray< uint8_t > | mat_mul (const std::valarray< uint8_t > &vector, const matrix< int > &key) |
| helper function to perform vector multiplication with encryption or decryption matrix | |
| static char | get_idx_char (const uint8_t idx) |
| Get the character at a given index in the STRKEY. | |
| static uint8_t | get_char_idx (const char ch) |
| Get the index of a character in the STRKEY. | |
| static const std::string | codec (const std::string &text, const matrix< int > &key) |
| Convenience function to perform block cipher operations. The operations are identical for both encryption and decryption. | |
| template<typename T> | |
| static matrix< double > | get_inverse (matrix< T > const &A) |
| static int | modulo (int a, int b) |
Implementation of Hill Cipher algorithm.
Definition at line 82 of file hill_cipher.cpp.
|
inlinestaticprivate |
Convenience function to perform block cipher operations. The operations are identical for both encryption and decryption.
| text | input text to encrypt or decrypt |
| key | key for encryption or decryption |
Definition at line 211 of file hill_cipher.cpp.
|
inlinestatic |
Decrypt a given text using a given key.
| text | string to decrypt |
| decrypt_key | key for decryption |
Definition at line 457 of file hill_cipher.cpp.
|
inlinestatic |
Encrypt a given text using a given key.
| text | string to encrypt |
| encrypt_key | key for encryption |
Definition at line 445 of file hill_cipher.cpp.
|
inlinestaticprivate |
Compute GCD of two integers using Euler's algorithm.
| a | first number |
| b | second number |
Definition at line 139 of file hill_cipher.cpp.
|
inlinestatic |
Generate decryption matrix from an encryption matrix key.
| encrypt_key | encryption key for which to create a decrypt key |
Definition at line 372 of file hill_cipher.cpp.
|
inlinestatic |
Generate encryption matrix of a given size. Larger size matrices are difficult to generate but provide more security. Important conditions are:
| size | size of matrix (typically \(\text{size}\le10\)) |
| limit1 | lower limit of range of random elements (default=0) |
| limit2 | upper limit of range of random elements (default=10) |
Definition at line 340 of file hill_cipher.cpp.
|
inlinestatic |
Generate encryption and decryption key pair.
| size | size of matrix key (typically \(\text{size}\le10\)) |
| limit1 | lower limit of range of random elements (default=0) |
| limit2 | upper limit of range of random elements (default=10) |
Definition at line 424 of file hill_cipher.cpp.
|
inlinestaticprivate |
Get the index of a character in the STRKEY.
| ch | character to search |
Definition at line 191 of file hill_cipher.cpp.
|
inlinestaticprivate |
Get the character at a given index in the STRKEY.
| idx | index value |
Definition at line 183 of file hill_cipher.cpp.
|
inlinestaticprivate |
Get matrix inverse using Row-transformations. Given matrix must be a square and non-singular.
Definition at line 251 of file hill_cipher.cpp.
|
inlinestaticprivate |
helper function to perform vector multiplication with encryption or decryption matrix
| vector | vector to multiply |
| key | encryption or decryption key matrix |
Definition at line 160 of file hill_cipher.cpp.
|
inlinestaticprivate |
Definition at line 315 of file hill_cipher.cpp.
|
inlinestaticprivate |
Function overload to fill a matrix with random integers in a given interval.
| M | pointer to matrix to be filled with random numbers |
| a | lower limit of interval |
| b | upper limit of interval |
| T1 | type of input range |
| T2 | type of matrix |
Definition at line 119 of file hill_cipher.cpp.
|
inlinestaticprivate |
Function to generate a random integer in a given interval.
| a | lower limit of interval |
| b | upper limit of interval |
| T | type of output |
Definition at line 93 of file hill_cipher.cpp.