-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1fba9b
commit 7f5df7b
Showing
4 changed files
with
61 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
OPTS := -Wall -pedantic -std=c11 | ||
|
||
all: enigma | ||
all: frontend | ||
|
||
build/%.o: %.c | ||
gcc $(OPTS) -c $< -g -o $@ | ||
gcc $(OPTS) -c $< -g -fpic -o $@ | ||
|
||
|
||
enigma: build/enigma.o build/readlines.o build/rotor.o | ||
gcc build/enigma.o build/readlines.o build/rotor.o -o build/enigma | ||
build/libenigma.so: build/enigma.o build/readlines.o build/rotor.o | ||
gcc build/enigma.o build/readlines.o build/rotor.o -shared -o build/libenigma.so | ||
|
||
frontend: build/libenigma.so | ||
gcc -Lbuild -Wl,-rpath=build -o build/enigma frontend.c -lenigma | ||
|
||
make clean: | ||
rm -f build/*.o build/*.so build/enigma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef enigma_h | ||
|
||
#define enigma_h | ||
|
||
#include "rotor.h" | ||
#include "readlines.h" | ||
#include <stdio.h> | ||
|
||
struct enigma_structure { | ||
rotor rotors[3]; | ||
rotor reflector; | ||
char plugboard[27]; // Used to perform substitution | ||
char pairs[30]; // Not needed for enigma functionality, but useful to output plugboard config | ||
}; | ||
|
||
typedef struct enigma_structure *enigma; | ||
|
||
void keypress_rotate(rotor rotors[3]); | ||
char *encode_message(char *message, rotor rotors[3], rotor reflector, char plugboard[26]); | ||
char p_sub(char c, char p[26]); | ||
void input(char *string,int length); | ||
enigma create_enigma_from_file(FILE *config_file, r_template templates[], int num_templates); | ||
void destroy_engima(enigma e); | ||
void display_config(enigma e); | ||
r_template *load_templates_from_file(FILE* f, int *num_rotors); | ||
enigma create_enigma(r_template rotors[3], r_template reflector, char positions[3], char ring_settings[3], char plugboard[27], char pairs[30]); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "enigma.h" | ||
|
||
int main() { | ||
FILE* file = fopen("rotors", "r"); | ||
int num_rotors = 0; | ||
r_template *templates = load_templates_from_file(file, &num_rotors); | ||
fclose(file); | ||
|
||
FILE *config_file = fopen("config", "r"); | ||
enigma e = create_enigma_from_file(config_file, templates, num_rotors); | ||
fclose(config_file); | ||
free(templates); | ||
|
||
display_config(e); | ||
|
||
printf("Enter message to be encoded: "); | ||
char buffer[BUFFER_SIZE]; | ||
input(buffer, BUFFER_SIZE); | ||
|
||
char *result = encode_message(buffer, e->rotors, e->reflector, e->plugboard); | ||
|
||
printf("Result: %s\n", result); | ||
destroy_engima(e); | ||
free(result); | ||
} |