15#ifndef ENIGMA_FLAG_X_SEPARATED
19#define ENIGMA_FLAG_X_SEPARATED 16
22#ifndef ENIGMA_DICTIONARY_EXISTS
26#define ENIGMA_DICTIONARY_EXISTS 1
29#ifndef ENIGMA_N_GRAMS_EXIST
33#define ENIGMA_N_GRAMS_EXIST 2
36#ifndef ENIGMA_IOC_FREQS_EXIST
40#define ENIGMA_IOC_FREQS_EXIST 4
43#ifndef ENIGMA_CIPHERTEXT_EXISTS
47#define ENIGMA_CIPHERTEXT_EXISTS 8
50#ifndef ENIGMA_SCORE_BOUNDS_EXIST
54#define ENIGMA_SCORE_BOUNDS_EXIST 16
57#ifndef ENIGMA_ROTORS_DEFINED
62#define ENIGMA_ROTORS_DEFINED 32
65#ifndef ENIGMA_ROTOR_POSITIONS_DEFINED
70#define ENIGMA_ROTOR_POSITIONS_DEFINED 64
73#ifndef ENIGMA_REFLECTOR_DEFINED
78#define ENIGMA_REFLECTOR_DEFINED 128
81#ifndef ENIGMA_PLUGBOARD_DEFINED
86#define ENIGMA_PLUGBOARD_DEFINED 256
113 float frequency_targets[26];
#define ENIGMA_ALPHA_SIZE
Defines the size of the alphabet used in the Enigma machine.
Definition: common.h:18
int enigma_crack_rotor_position(EnigmaCrackParams *, int, float(*scoreFunc)(const EnigmaCrackParams *, const char *))
Crack a rotor's position using a scoring function.
Definition: crack.c:339
int enigma_crack_set_score_list(EnigmaCrackParams *, EnigmaScoreList *)
Set the score_list field in the given EnigmaCrackParams struct.
Definition: crack.c:939
EnigmaCrackParams * enigma_crack_params_new(void)
Create a new EnigmaCrackParams structure.
Definition: crack.c:37
float enigma_crack_get_target_score(const EnigmaCrackParams *)
Get the target_score field in the given EnigmaCrackParams struct.
Definition: crack.c:879
int enigma_crack_rotor(EnigmaCrackParams *, int, float(*)(const EnigmaCrackParams *, const char *))
Crack the rotor using a scoring function.
Definition: crack.c:233
int enigma_score_append(EnigmaCrackParams *, Enigma *, const char *, float)
Append a score to an EnigmaScoreList.
Definition: crack.c:626
const EnigmaScoreList * enigma_crack_get_score_list(const EnigmaCrackParams *)
Get the score_list field in the given EnigmaCrackParams struct.
Definition: crack.c:720
int enigma_find_potential_indices(const char *, const char *, int *)
Finds potential indices in the ciphertext where the known plaintext may exist.
Definition: crack.c:508
int enigma_letter_freq(const EnigmaCrackParams *, const char *)
Check if the letter frequencies in the plaintext match target frequencies within an offset.
Definition: crack.c:589
int enigma_crack_params_validate(const EnigmaCrackParams *)
Check what capabilities the EnigmaCrackParams structure has.
Definition: crack.c:60
int enigma_free_dict(EnigmaCrackParams *)
Free all dictionary nodes in cfg.
Definition: crack.c:537
int enigma_crack_set_max_score(EnigmaCrackParams *, float)
Set the maximum score field in the given EnigmaCrackParams struct.
Definition: crack.c:1078
int enigma_crack_set_n(EnigmaCrackParams *, int)
Set the n field in the given EnigmaCrackParams struct.
Definition: crack.c:994
struct EnigmaTrie_s EnigmaTrie
const float * enigma_crack_get_ngrams(const EnigmaCrackParams *)
Get the ngrams field in the given EnigmaCrackParams struct.
Definition: crack.c:750
int enigma_crack_plugboard(EnigmaCrackParams *, float(*)(const EnigmaCrackParams *, const char *))
Crack the plugboard using a scoring function.
Definition: crack.c:137
int enigma_crack_set_known_plaintext(EnigmaCrackParams *, const char *, size_t)
Set the known plaintext field in the given EnigmaCrackParams struct.
Definition: crack.c:1111
int enigma_crack_set_min_score(EnigmaCrackParams *, float)
Set the minimum score field in the given EnigmaCrackParams struct.
Definition: crack.c:1062
const Enigma * enigma_crack_get_enigma(const EnigmaCrackParams *)
Get the enigma field in the given EnigmaCrackParams struct.
Definition: crack.c:704
int enigma_score_flags(const EnigmaCrackParams *, const char *)
Get the flags for a given plaintext based on the crack configuration.
Definition: crack.c:658
int enigma_crack_set_enigma(EnigmaCrackParams *, Enigma *)
Set the enigma field in the given EnigmaCrackParams struct.
Definition: crack.c:923
size_t enigma_crack_get_known_plaintext_length(const EnigmaCrackParams *)
Get the known_plaintext_length field in the given EnigmaCrackParams struct.
Definition: crack.c:908
int enigma_crack_set_target_score(EnigmaCrackParams *, float)
Set the target score field in the given EnigmaCrackParams struct.
Definition: crack.c:1094
int enigma_crack_set_dictionary(EnigmaCrackParams *, EnigmaTrie *)
Set the dictionary field in the given EnigmaCrackParams struct.
Definition: crack.c:956
int enigma_dict_match(const EnigmaCrackParams *, const char *)
Checks if multiple words from the dictionary are present in the plaintext.
Definition: crack.c:437
int enigma_crack_set_ciphertext(EnigmaCrackParams *, const char *, size_t)
Set the ciphertext field in the given EnigmaCrackParams struct.
Definition: crack.c:1012
int enigma_crack_reflector(EnigmaCrackParams *, float(*)(const EnigmaCrackParams *, const char *))
Crack the reflector using a scoring function.
Definition: crack.c:195
size_t enigma_crack_get_ciphertext_length(const EnigmaCrackParams *)
Get the ciphertext_length field in the given EnigmaCrackParams struct.
Definition: crack.c:808
size_t enigma_crack_get_ngrams_length(const EnigmaCrackParams *)
Get the ngrams_length field in the given EnigmaCrackParams struct.
Definition: crack.c:779
int enigma_crack_rotors(EnigmaCrackParams *, float(*)(const EnigmaCrackParams *, const char *))
Crack the rotor order using a scoring function.
Definition: crack.c:270
const char * enigma_crack_get_ciphertext(const EnigmaCrackParams *)
Get the ciphertext field in the given EnigmaCrackParams struct.
Definition: crack.c:793
int enigma_crack_set_flags(EnigmaCrackParams *, int)
Set the flags field in the given EnigmaCrackParams struct.
Definition: crack.c:1029
const float * enigma_crack_get_frequency_targets(const EnigmaCrackParams *)
Get the frequency_targets field in the given EnigmaCrackParams struct.
Definition: crack.c:836
float enigma_freq(const char *, int)
Calculate the frequency of characters in the plaintext.
Definition: crack.c:554
int enigma_crack_get_n(const EnigmaCrackParams *)
Get the n field in the given EnigmaCrackParams struct.
Definition: crack.c:765
int enigma_crack_rotor_positions(EnigmaCrackParams *, float(*)(const EnigmaCrackParams *, const char *))
Crack the rotor positions using a scoring function.
Definition: crack.c:373
int enigma_crack_set_ngrams(EnigmaCrackParams *, float *, int, size_t)
Set the ngrams field in the given EnigmaCrackParams struct.
Definition: crack.c:976
int enigma_crack_get_flags(const EnigmaCrackParams *)
Get the flags field in the given EnigmaCrackParams struct.
Definition: crack.c:822
float enigma_crack_get_max_score(const EnigmaCrackParams *)
Get the max_score field in the given EnigmaCrackParams struct.
Definition: crack.c:865
const char * enigma_crack_get_known_plaintext(const EnigmaCrackParams *)
Get the known_plaintext field in the given EnigmaCrackParams struct.
Definition: crack.c:893
EnigmaTrie * enigma_crack_get_dictionary(const EnigmaCrackParams *)
Get the dictionary field in the given EnigmaCrackParams struct.
Definition: crack.c:735
int enigma_crack_set_frequency_targets(EnigmaCrackParams *, float *)
Set the frequency targets field in the given EnigmaCrackParams struct.
Definition: crack.c:1045
float enigma_crack_get_min_score(const EnigmaCrackParams *)
Get the min_score field in the given EnigmaCrackParams struct.
Definition: crack.c:851
A structure representing a configuration for cracking an Enigma cipher.
Definition: crack.h:103
Enigma enigma
The base enigma machine configuration.
Definition: crack.h:104
EnigmaTrie * dictionary
A trie containing the dictionary words to be used for scoring.
Definition: crack.h:106
int known_plaintext_length
The length of the known plaintext.
Definition: crack.h:122
float * ngrams
An array of n-gram frequencies.
Definition: crack.h:107
EnigmaScoreList * score_list
A list of scored configurations.
Definition: crack.h:105
const char * ciphertext
The ciphertext to be cracked.
Definition: crack.h:110
int n
The length of each n-gram.
Definition: crack.h:108
float min_score
The minimum score for a configuration to be considered.
Definition: crack.h:114
const char * known_plaintext
Known plaintext that must exist for a configuration to be considered.
Definition: crack.h:121
int flags
Flags indicating special conditions a scored configuration may meet.
Definition: crack.h:112
size_t ciphertext_length
The length of the ciphertext.
Definition: crack.h:111
float frequency_offset
The maximum offset from the target frequency that a scored configuration may have to be considered va...
Definition: crack.h:119
float target_frequency
The target frequency for a configuration to be considered.
Definition: crack.h:117
float max_score
The maximum score for a configuration to be considered.
Definition: crack.h:115
float target_score
The target score for a configuration to be considered.
Definition: crack.h:116
size_t ngrams_length
The number of n-grams in the array.
Definition: crack.h:109
A structure representing a list of scored Enigma configurations.
Definition: score.h:40
char value
1 if the node represents the end of a valid word, 0 otherwise.
Definition: crack.h:94
struct EnigmaTrie_s * children[26]
Pointers to child nodes for each letter of the alphabet (NULL if no child exists for that letter)
Definition: crack.h:95
A structure representing a trie for storing dictionary words, used in enigma_dict_match() for efficie...
Represents the state and configuration of an Enigma machine.
Definition: enigma.h:34