|
libenigma
Enigma machine utility library
|
Go to the source code of this file.
Data Structures | |
| struct | Enigma |
| Represents the state and configuration of an Enigma machine. More... | |
Functions | |
| char | enigma_encode (Enigma *, int) |
| Encode a character using the Enigma machine. | |
| int | enigma_encode_string (Enigma *, const char *, char *, int) |
| Encode a string using the Enigma machine. | |
| int | enigma_init_rotors (Enigma *, const EnigmaRotor *, int) |
| Initialize the rotors of the Enigma machine. | |
| int | enigma_init_default_config (Enigma *) |
| Load the default configuration for the Enigma machine. | |
| int | enigma_init_random_config (Enigma *) |
| Load a random configuration for the Enigma machine. | |
| Enigma * | enigma_new (void) |
| Create a new Enigma machine. | |
| const char * | enigma_version (void) |
| Get the version of the Enigma library. | |
| const char * | enigma_get_plugboard (const Enigma *) |
| Get the plugboard configuration. | |
| const EnigmaReflector * | enigma_get_reflector (const Enigma *) |
| Get the reflector configuration. | |
| const EnigmaRotor * | enigma_get_rotor (const Enigma *, int) |
| Get the rotor configuration. | |
| int | enigma_get_rotor_count (const Enigma *) |
| Get the number of rotors. | |
| int | enigma_get_rotor_flag (const Enigma *) |
| Get the rotor flag. | |
| int | enigma_get_rotor_index (const Enigma *, int) |
| Get the index of a rotor. | |
| int | enigma_set_plugboard (Enigma *, const char *) |
| Set the plugboard configuration. | |
| int | enigma_set_reflector (Enigma *, int) |
| int | enigma_set_rotor (Enigma *, int, int) |
| Set the rotor. | |
| int | enigma_set_rotor_count (Enigma *, int) |
| Set the number of rotors. | |
| int | enigma_set_rotor_flag (Enigma *, int) |
| Set the rotor flag status. | |
| int | enigma_set_rotor_index (Enigma *, int, int) |
| Set the index of a rotor. | |
This file defines the core structures and functions for the Enigma machine, including the main Enigma structure, encoding functions, and initialization routines for default and random configurations.
| char enigma_encode | ( | Enigma * | enigma, |
| int | c | ||
| ) |
Encode a character using the Enigma machine.
This function takes an input character, processes it through the Enigma machine's rotors and reflector, and returns the encoded character. It handles both uppercase and lowercase characters.
Assumes the input character is an uppercase ASCII letter.
| enigma | Pointer to the Enigma machine structure. |
| c | The character to encode. |
| int enigma_encode_string | ( | Enigma * | enigma, |
| const char * | input, | ||
| char * | output, | ||
| int | length | ||
| ) |
Encode a string using the Enigma machine.
This function encodes a string of characters using the Enigma machine. It processes each character through the machine and stores the result in the output string. Assumes the input string is uppercase and null-terminated.
| enigma | Pointer to the Enigma machine structure. |
| input | The input string to encode. |
| output | The output string to store the encoded result. |
| length | The length of the input string (the output buffer should be at least the same length). |
| const char * enigma_get_plugboard | ( | const Enigma * | enigma | ) |
Get the plugboard configuration.
This function returns the current plugboard configuration as a string.
| enigma | Pointer to the Enigma machine. |
| const EnigmaReflector * enigma_get_reflector | ( | const Enigma * | enigma | ) |
Get the reflector configuration.
This function returns the current reflector.
| enigma | Pointer to the Enigma machine. |
| const EnigmaRotor * enigma_get_rotor | ( | const Enigma * | enigma, |
| int | rotorIndex | ||
| ) |
Get the rotor configuration.
This function returns the rotor at the specified index.
| enigma | Pointer to the Enigma machine. |
| rotorIndex | Index of the rotor to retrieve. |
| int enigma_get_rotor_count | ( | const Enigma * | enigma | ) |
| int enigma_get_rotor_flag | ( | const Enigma * | enigma | ) |
| int enigma_get_rotor_index | ( | const Enigma * | enigma, |
| int | rotor | ||
| ) |
| int enigma_init_default_config | ( | Enigma * | enigma | ) |
| int enigma_init_random_config | ( | Enigma * | enigma | ) |
| int enigma_init_rotors | ( | Enigma * | enigma, |
| const EnigmaRotor * | rotors, | ||
| int | count | ||
| ) |
Initialize the rotors of the Enigma machine.
This populates the rotors array in the specified Enigma by copying the provided array of rotors. It also sets the rotor flag and count.
| enigma | Pointer to the Enigma. |
| rotors | Array of EnigmaRotors to copy to the Enigma. |
| count | Number of rotors to copy. |
| Enigma * enigma_new | ( | void | ) |
| int enigma_set_plugboard | ( | Enigma * | enigma, |
| const char * | s | ||
| ) |
Set the plugboard configuration.
This function sets the plugboard configuration based on the provided string. The string should contain pairs of uppercase letters representing the connections between the letters. For example, "ABCDEF" would connect A to B, C to D, and E to F.
| enigma | Pointer to the Enigma machine. |
| s | Pointer to the string containing the plugboard configuration. |
| int enigma_set_reflector | ( | Enigma * | enigma, |
| int | reflector | ||
| ) |
Set the reflector configuration.
This function sets the reflector configuration based on the provided enigma_reflectors index.
| enigma | Pointer to the Enigma machine. |
| reflector | Index of the reflector to be set. |
| int enigma_set_rotor | ( | Enigma * | enigma, |
| int | rotor, | ||
| int | index | ||
| ) |
Set the rotor.
This function sets the rotor configuration based on the provided enigma_rotors index.
| enigma | Pointer to the Enigma machine. |
| rotor | Index of the rotor in enigma_rotors. |
| index | Index to place the rotor in enigma |
| int enigma_set_rotor_count | ( | Enigma * | enigma, |
| int | count | ||
| ) |
| int enigma_set_rotor_flag | ( | Enigma * | enigma, |
| int | flag | ||
| ) |
| int enigma_set_rotor_index | ( | Enigma * | enigma, |
| int | rotor, | ||
| int | index | ||
| ) |