|
Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
An affine cipher is a letter substitution cipher that uses a linear transformation to substitute letters in a message. More...
#include <assert.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Data Structures | |
| struct | affine_key_t |
| a structure representing an affine cipher key More... | |
Macros | |
| #define | ALPHABET_SIZE 95 |
| for assertions | |
| #define | Z95_CONVERSION_CONSTANT 32 |
| used to convert a printable byte (32 to 126) to an element of the group Z_95 (0 to 94) | |
Functions | |
| int | modular_multiplicative_inverse (unsigned int a, unsigned int m) |
| finds the value x such that (a * x) % m = 1 | |
| affine_key_t | inverse_key (affine_key_t key) |
| Given a valid affine cipher key, this function will produce the inverse key. | |
| void | affine_encrypt (char *s, affine_key_t key) |
Encrypts character string s with key. | |
| void | affine_decrypt (char *s, affine_key_t key) |
| Decrypts an affine ciphertext. | |
| void | test_string (const char *s, const char *ciphertext, int a, int b) |
| Tests a given string. | |
| static void | tests () |
| Test multiple strings. | |
| int | main () |
| main function | |
An affine cipher is a letter substitution cipher that uses a linear transformation to substitute letters in a message.
Given an alphabet of length M with characters with numeric values 0-(M-1), an arbitrary character x can be transformed with the expression (ax
| #define ALPHABET_SIZE 95 |
for assertions
for IO for div function and div_t struct as well as malloc and free for strlen, strcpy, and strcmp
number of characters in our alphabet (printable ASCII characters)
| void affine_decrypt | ( | char * | s, |
| affine_key_t | key | ||
| ) |
Decrypts an affine ciphertext.
| s | string to be decrypted |
| key | Key used when s was encrypted |
| void affine_encrypt | ( | char * | s, |
| affine_key_t | key | ||
| ) |
Encrypts character string s with key.
| s | string to be encrypted |
| key | affine key used for encryption |
| affine_key_t inverse_key | ( | affine_key_t | key | ) |
Given a valid affine cipher key, this function will produce the inverse key.
| key | They key to be inverted |
| int main | ( | void | ) |
| int modular_multiplicative_inverse | ( | unsigned int | a, |
| unsigned int | m | ||
| ) |
finds the value x such that (a * x) % m = 1
| a | number we are finding the inverse for |
| m | the modulus the inversion is based on |
a mod m | void test_string | ( | const char * | s, |
| const char * | ciphertext, | ||
| int | a, | ||
| int | b | ||
| ) |
Tests a given string.
| s | string to be tested |
| a | value of key.a |
| b | value of key.b |
|
static |
Test multiple strings.