wip on configuration

This commit is contained in:
rzen 2020-09-27 11:43:58 -04:00
parent 7e2dcc4512
commit a19568b8a8

View File

@ -34,21 +34,52 @@ Rotor rotors [] = {
// id name wiring notch // id name wiring notch
// == ==== ====== ===== // == ==== ====== =====
{ "ABC", "ABC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" }, // 0 alphabet { "ABC", "ABC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" }, // 0 alphabet
//
{ "I", "I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q" }, // 1 { "I", "I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q" }, // 1
{ "II", "II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", "E" }, // 2 { "II", "II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", "E" }, // 2
{ "III", "III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", "V" }, // 3 { "III", "III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", "V" }, // 3
{ "IV", "IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", "J" }, // 4 { "IV", "IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", "J" }, // 4
{ "V", "V", "VZBRGITYUPSDNHLXAWMJQOFECK", "Z" }, // 5 { "V", "V", "VZBRGITYUPSDNHLXAWMJQOFECK", "Z" }, // 5
//
{ "VI", "VI", "JPGVOUMFYQBENHZRDKASXLICTW", "ZM" }, // 6 { "VI", "VI", "JPGVOUMFYQBENHZRDKASXLICTW", "ZM" }, // 6
{ "VII", "VII", "NZJHGRCXMYSWBOUFAIVLPEKQDT", "ZM" }, // 7 { "VII", "VII", "NZJHGRCXMYSWBOUFAIVLPEKQDT", "ZM" }, // 7
{ "VIII", "VIII", "FKQHTLXOCBJSPDZRAMEWNIUYGV", "ZM" }, // 8 { "VIII", "VIII", "FKQHTLXOCBJSPDZRAMEWNIUYGV", "ZM" }, // 8
{ "beta", "Beta", "LEYJVCNIXWPBQMDRTAKZGFUHOS", "" }, // 9 { "beta", "Beta", "LEYJVCNIXWPBQMDRTAKZGFUHOS", "" }, // 9 M4 only
{ "gamma", "Gamma", "FSOKANUERHMBTIYCWLQPZXVGJD", "" }, // 10 { "gamma", "Gamma", "FSOKANUERHMBTIYCWLQPZXVGJD", "" }, // 10 M4 only
{ "UKW-A", "UKW A", "EJMZALYXVBWFCRQUONTSPIKHGD", "" }, // 11 reflectors
// reflectors
{ "UKW-A", "UKW A", "EJMZALYXVBWFCRQUONTSPIKHGD", "" }, // 11
{ "UKW-B", "UKW B", "YRUHQSLDPXNGOKMIEBFZCWVJAT", "" }, // 12 { "UKW-B", "UKW B", "YRUHQSLDPXNGOKMIEBFZCWVJAT", "" }, // 12
{ "UKW-C", "UKW C", "FVPJIAOYEDRZXWGCTKUQSBNMHL", "" }, // 13 { "UKW-C", "UKW C", "FVPJIAOYEDRZXWGCTKUQSBNMHL", "" }, // 13
{ "UKW-B-thin", "UKW B thin", "ENKQAUYWJICOPBLMDXZVFTHRGS", "" }, // 14 { "UKW-B-thin", "UKW B thin", "ENKQAUYWJICOPBLMDXZVFTHRGS", "" }, // 14 M4 only
{ "UKW-C-thin", "UKW C thin", "RDOBJNTKVEHMLFCWZAXGYIPSUQ", "" } // 15 { "UKW-C-thin", "UKW C thin", "RDOBJNTKVEHMLFCWZAXGYIPSUQ", "" } // 15 M4 only
};
typedef struct {
char *name;
char *description;
Rotor rotor_types[];
Rotor reflector_types[];
} EnigmaType;
EnigmaType enigma_types[] = {
{
"M3",
"Army",
{ rotors[1], rotors[2], rotors[3], rotors[4], rotors[5] },
{ rotors[11], rotors[12] }
},
{
"M4",
"Navy",
// work out thin rotors
{ rotors[1], rotors[2], rotors[3], rotors[4], rotors[5], rotors[6], rotors[7], rotors[8] },
{ rotors[11], rotors[12] }
}
}; };
// entry wheel "EintrittswalzeEintrittswalze" // entry wheel "EintrittswalzeEintrittswalze"
@ -166,7 +197,8 @@ char encode (char c) {
} }
pin = stridx(AZ, rotors[reflector_type].wiring[pin]); pin = stridx(AZ, rotors[reflector_type].wiring[pin]);
if (debug_mode) { if (debug_mode) {
Serial.print("->"); Serial.print(AZ[pin]); Serial.print("->");
Serial.print(AZ[pin]);
Serial.print(" "); Serial.print(" ");
} }
@ -248,8 +280,6 @@ void init_buf (char *buf) {
} }
} }
// 01234
void add_to_buf (char *buf, char c) { void add_to_buf (char *buf, char c) {
for (int i=0; i<BUF_SIZE-1; ++i) { for (int i=0; i<BUF_SIZE-1; ++i) {
buf[i] = buf[i+1]; buf[i] = buf[i+1];
@ -296,15 +326,28 @@ void disp_plugboard () {
} }
} }
// config:
// reset
// enigma type
// for each rotor
// - ringsetting
// - rotor selection
// plugboard
// - clear
// - set pair
void setup () { void setup () {
// Serial.begin(115200); // Serial.begin(115200);
kbd.begin(); kbd.begin();
lcd.begin(LCD_COLS, LCD_ROWS); lcd.begin(LCD_COLS, LCD_ROWS);
lcd.setCursor(0,1); lcd.setCursor(0,1);
lcd.print("Enigma M3"); lcd.print("Enigma");
lcd.setCursor(0,2);
lcd.print("M3");
// test(); test();
init_buf(input_buf); init_buf(input_buf);
init_buf(encoded_buf); init_buf(encoded_buf);
disp_rotors(); disp_rotors();
@ -312,7 +355,10 @@ void setup () {
} }
void loop () { bool demo_mode = false;
bool config_mode = true;
void enigma () {
kbd.tick(); kbd.tick();
while (kbd.available()) { while (kbd.available()) {
@ -332,3 +378,42 @@ void loop () {
delay(10); delay(10);
} }
void demo () {
}
void config () {
// demo? y/n -> demo_mode
// enigma type? menu -> enigma_type
// rotor[
}
void loop () {
if (config_mode) {
config();
} else if (demo_mode) {
demo();
} else {
enigma();
}
}
/*
Eintrittwalze entry wheel (stator)
Greek wheels Beta and Gamma [for obvious reasons] used in the M4
Grundstellung ground setting
Ringstellung ring setting
Stecker plug
Steckerbrett plugboard [sometimes referred to as "Stecker board"]
Umkehrwalze reflector
Walzen wheels
Walzenlage wheel order
*/
/*
https://cryptocellar.org/Enigma/index.html
http://www.mlb.co.jp/linux/science/genigma/enigma-referat/node4.html#SECTION00043000000000000000
*/