|
libenigma
Enigma machine utility library
|
#include "io.h"#include "common.h"#include "crack.h"#include "enigma.h"#include "ngram.h"#include <ctype.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Functions | |
| int | enigma_error_message (const char *func, const char *format,...) |
| Print an error message to stderr. | |
| int | enigma_load_config (Enigma *enigma, const char *s) |
| Load an Enigma machine configuration from a string. | |
| int | enigma_load_custom_reflector (EnigmaReflector *reflector, const char *alphabet, const char *name) |
| Load a custom reflector alphabet from the given alphabet and name. | |
| int | enigma_load_custom_rotor (EnigmaRotor *rotor, const char *alphabet, const char *name, int *notches, int numNotches) |
| Load a custom rotor alphabet from the given alphabet, name, and notches. | |
| int | enigma_load_ngrams (EnigmaCrackParams *cfg, const char *path) |
| Load ngrams from a file. | |
| int | enigma_load_plugboard_config (Enigma *enigma, const char *s) |
| Load plugboard configuration from a string. | |
| int | enigma_load_reflector_config (Enigma *enigma, const char *s) |
| Load reflector configuration from a string. | |
| int | enigma_load_rotor_config (Enigma *enigma, char *s) |
| Load rotor configuration from a string. | |
| int | enigma_load_rotor_positions (Enigma *enigma, const char *s) |
| Load rotor starting positions from a string. | |
| void | enigma_print_config (const Enigma *enigma, char *out) |
| Print the current Enigma machine configuration to out. | |
This file implements input/output functions.
| int enigma_error_message | ( | const char * | func, |
| const char * | format, | ||
| ... | |||
| ) |
Print an error message to stderr.
| func | Function name. |
| format | Format string. |
| ... | Arguments for the format string. |
| int enigma_load_config | ( | Enigma * | enigma, |
| const char * | s | ||
| ) |
Load an Enigma machine configuration from a string.
The configuration string should be in the format: "ROTORS|POSITIONS|REFLECTOR|PLUGBOARD", where ROTORS is a space-separated list of rotor names, POSITIONS is a string of starting positions for each rotor, REFLECTOR is the reflector name, and PLUGBOARD is a string representing plugboard connections. If there is no plugboard, use "None".
| enigma | Pointer to the Enigma machine instance. |
| s | String representing the Enigma configuration. |
| int enigma_load_custom_reflector | ( | EnigmaReflector * | reflector, |
| const char * | alphabet, | ||
| const char * | name | ||
| ) |
Load a custom reflector alphabet from the given alphabet and name.
| reflector | Pointer to the reflector structure to be populated. |
| alphabet | The custom reflector alphabet (must be 26 characters long). |
| name | The name of the custom reflector. |
| int enigma_load_custom_rotor | ( | EnigmaRotor * | rotor, |
| const char * | alphabet, | ||
| const char * | name, | ||
| int * | notches, | ||
| int | numNotches | ||
| ) |
Load a custom rotor alphabet from the given alphabet, name, and notches.
| rotor | Pointer to the rotor structure to be populated. |
| alphabet | The custom rotor alphabet (must be 26 characters long). |
| name | The name of the custom rotor. |
| notches | Array of notch positions (length must match numNotches). |
| numNotches | Number of notches. |
| int enigma_load_ngrams | ( | EnigmaCrackParams * | cfg, |
| const char * | path | ||
| ) |
Load ngrams from a file.
The file should have the following format: First line: n charCount Subsequent lines: count ngram
| cfg | Pointer to the cracking configuration structure. |
| path | Path to the ngram file. |
| int enigma_load_plugboard_config | ( | Enigma * | enigma, |
| const char * | s | ||
| ) |
Load plugboard configuration from a string.
The string should contain non-separated pairs of characters representing the plugboard connections, e.g., "ABCDEF" means A<->B, C<->D, E<->F.
| enigma | Pointer to the Enigma machine instance. |
| s | String representing plugboard configuration. |
| int enigma_load_reflector_config | ( | Enigma * | enigma, |
| const char * | s | ||
| ) |
Load reflector configuration from a string.
| enigma | Pointer to the Enigma machine instance. |
| s | String representing plugboard configuration. |
| int enigma_load_rotor_config | ( | Enigma * | enigma, |
| char * | s | ||
| ) |
Load rotor configuration from a string.
| enigma | Pointer to the Enigma machine instance. |
| s | String representing rotor configuration. |
| int enigma_load_rotor_positions | ( | Enigma * | enigma, |
| const char * | s | ||
| ) |
Load rotor starting positions from a string.
This function expects a string of characters representing the initial positions of the rotors, e.g., "ABC" for three rotors. It sets the idx field of each rotor in the Enigma structure.
| enigma | Pointer to the Enigma machine instance. |
| s | String representing rotor starting positions. |