libenigma
Enigma machine utility library
Loading...
Searching...
No Matches
io.h File Reference
#include "crack.h"
#include "enigma.h"

Go to the source code of this file.

Macros

#define ENIGMA_ERROR(fmt, ...)   enigma_error_message(__func__, fmt, __VA_ARGS__)
 Prints an error message to stderr with function name.
 

Functions

int enigma_error_message (const char *, const char *,...)
 Print an error message to stderr.
 
int enigma_load_config (Enigma *, const char *)
 Load an Enigma machine configuration from a string.
 
int enigma_load_custom_reflector (EnigmaReflector *, const char *, const char *)
 Load a custom reflector alphabet from the given alphabet and name.
 
int enigma_load_custom_rotor (EnigmaRotor *, const char *, const char *, int *, int)
 Load a custom rotor alphabet from the given alphabet, name, and notches.
 
int enigma_load_ngrams (EnigmaCrackParams *, const char *)
 Load ngrams from a file.
 
int enigma_load_plugboard_config (Enigma *, const char *)
 Load plugboard configuration from a string.
 
int enigma_load_reflector_config (Enigma *, const char *)
 Load reflector configuration from a string.
 
int enigma_load_rotor_config (Enigma *, char *)
 Load rotor configuration from a string.
 
int enigma_load_rotor_positions (Enigma *, const char *)
 Load rotor starting positions from a string.
 
void enigma_print_config (const Enigma *, char *)
 Print the current Enigma machine configuration to out.
 

Detailed Description

This file declares input/output functions.

Macro Definition Documentation

◆ ENIGMA_ERROR

#define ENIGMA_ERROR (   fmt,
  ... 
)    enigma_error_message(__func__, fmt, __VA_ARGS__)

Prints an error message to stderr with function name.

Function Documentation

◆ enigma_error_message()

int enigma_error_message ( const char *  func,
const char *  format,
  ... 
)

Print an error message to stderr.

Parameters
funcFunction name.
formatFormat string.
...Arguments for the format string.
Returns
ENIGMA_FAILURE.

◆ enigma_load_config()

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".

Parameters
enigmaPointer to the Enigma machine instance.
sString representing the Enigma configuration.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_custom_reflector()

int enigma_load_custom_reflector ( EnigmaReflector reflector,
const char *  alphabet,
const char *  name 
)

Load a custom reflector alphabet from the given alphabet and name.

Parameters
reflectorPointer to the reflector structure to be populated.
alphabetThe custom reflector alphabet (must be 26 characters long).
nameThe name of the custom reflector.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_custom_rotor()

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.

Parameters
rotorPointer to the rotor structure to be populated.
alphabetThe custom rotor alphabet (must be 26 characters long).
nameThe name of the custom rotor.
notchesArray of notch positions (length must match numNotches).
numNotchesNumber of notches.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_ngrams()

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

Parameters
cfgPointer to the cracking configuration structure.
pathPath to the ngram file.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_plugboard_config()

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.

Parameters
enigmaPointer to the Enigma machine instance.
sString representing plugboard configuration.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_reflector_config()

int enigma_load_reflector_config ( Enigma enigma,
const char *  s 
)

Load reflector configuration from a string.

Parameters
enigmaPointer to the Enigma machine instance.
sString representing plugboard configuration.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_rotor_config()

int enigma_load_rotor_config ( Enigma enigma,
char *  s 
)

Load rotor configuration from a string.

Parameters
enigmaPointer to the Enigma machine instance.
sString representing rotor configuration.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_load_rotor_positions()

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.

Parameters
enigmaPointer to the Enigma machine instance.
sString representing rotor starting positions.
Returns
ENIGMA_SUCCESS on success, ENIGMA_FAILURE on failure.

◆ enigma_print_config()

void enigma_print_config ( const Enigma enigma,
char *  out 
)

Print the current Enigma machine configuration to out.

Parameters
enigmaPointer to the Enigma machine instance.
outBuffer to store the configuration string.