wip on configuration
This commit is contained in:
		
							
								
								
									
										107
									
								
								enigma.ino
									
									
									
									
									
								
							
							
						
						
									
										107
									
								
								enigma.ino
									
									
									
									
									
								
							@@ -34,21 +34,52 @@ Rotor rotors [] = {
 | 
			
		||||
  // id            name          wiring                        notch
 | 
			
		||||
  // ==            ====          ======                        =====
 | 
			
		||||
  {  "ABC",        "ABC",        "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ""   },  //  0 alphabet
 | 
			
		||||
 | 
			
		||||
  // 
 | 
			
		||||
  {  "I",          "I",          "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q"  },  //  1 
 | 
			
		||||
  {  "II",         "II",         "AJDKSIRUXBLHWTMCQGZNPYFVOE", "E"  },  //  2
 | 
			
		||||
  {  "III",        "III",        "BDFHJLCPRTXVZNYEIWGAKMUSQO", "V"  },  //  3
 | 
			
		||||
  {  "IV",         "IV",         "ESOVPZJAYQUIRHXLNFTGKDCMWB", "J"  },  //  4
 | 
			
		||||
  {  "V",          "V",          "VZBRGITYUPSDNHLXAWMJQOFECK", "Z"  },  //  5
 | 
			
		||||
 | 
			
		||||
  // 
 | 
			
		||||
  {  "VI",         "VI",         "JPGVOUMFYQBENHZRDKASXLICTW", "ZM" },  //  6
 | 
			
		||||
  {  "VII",        "VII",        "NZJHGRCXMYSWBOUFAIVLPEKQDT", "ZM" },  //  7
 | 
			
		||||
  {  "VIII",       "VIII",       "FKQHTLXOCBJSPDZRAMEWNIUYGV", "ZM" },  //  8
 | 
			
		||||
  {  "beta",       "Beta",       "LEYJVCNIXWPBQMDRTAKZGFUHOS", ""   },  //  9
 | 
			
		||||
  {  "gamma",      "Gamma",      "FSOKANUERHMBTIYCWLQPZXVGJD", ""   },  // 10
 | 
			
		||||
  {  "UKW-A",      "UKW A",      "EJMZALYXVBWFCRQUONTSPIKHGD", ""   },  // 11 reflectors
 | 
			
		||||
  {  "beta",       "Beta",       "LEYJVCNIXWPBQMDRTAKZGFUHOS", ""   },  //  9  M4 only
 | 
			
		||||
  {  "gamma",      "Gamma",      "FSOKANUERHMBTIYCWLQPZXVGJD", ""   },  // 10  M4 only
 | 
			
		||||
 | 
			
		||||
  // reflectors
 | 
			
		||||
  {  "UKW-A",      "UKW A",      "EJMZALYXVBWFCRQUONTSPIKHGD", ""   },  // 11
 | 
			
		||||
  {  "UKW-B",      "UKW B",      "YRUHQSLDPXNGOKMIEBFZCWVJAT", ""   },  // 12
 | 
			
		||||
  {  "UKW-C",      "UKW C",      "FVPJIAOYEDRZXWGCTKUQSBNMHL", ""   },  // 13
 | 
			
		||||
  {  "UKW-B-thin", "UKW B thin", "ENKQAUYWJICOPBLMDXZVFTHRGS", ""   },  // 14
 | 
			
		||||
  {  "UKW-C-thin", "UKW C thin", "RDOBJNTKVEHMLFCWZAXGYIPSUQ", ""   }   // 15
 | 
			
		||||
  {  "UKW-B-thin", "UKW B thin", "ENKQAUYWJICOPBLMDXZVFTHRGS", ""   },  // 14  M4 only
 | 
			
		||||
  {  "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"
 | 
			
		||||
@@ -166,7 +197,8 @@ char encode (char c) {
 | 
			
		||||
  }
 | 
			
		||||
  pin = stridx(AZ, rotors[reflector_type].wiring[pin]);
 | 
			
		||||
  if (debug_mode) {
 | 
			
		||||
    Serial.print("->"); Serial.print(AZ[pin]);
 | 
			
		||||
    Serial.print("->");
 | 
			
		||||
    Serial.print(AZ[pin]);
 | 
			
		||||
    Serial.print("  "); 
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
@@ -248,8 +280,6 @@ void init_buf (char *buf) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 01234
 | 
			
		||||
 | 
			
		||||
void add_to_buf (char *buf, char c) {
 | 
			
		||||
  for (int i=0; i<BUF_SIZE-1; ++i) {
 | 
			
		||||
    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 () {
 | 
			
		||||
//  Serial.begin(115200);
 | 
			
		||||
  kbd.begin();
 | 
			
		||||
  lcd.begin(LCD_COLS, LCD_ROWS);
 | 
			
		||||
 | 
			
		||||
  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(encoded_buf);
 | 
			
		||||
  disp_rotors();
 | 
			
		||||
@@ -312,7 +355,10 @@ void setup () {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void loop () {
 | 
			
		||||
bool demo_mode = false;
 | 
			
		||||
bool config_mode = true;
 | 
			
		||||
 | 
			
		||||
void enigma () {
 | 
			
		||||
  kbd.tick();
 | 
			
		||||
 | 
			
		||||
  while (kbd.available()) {
 | 
			
		||||
@@ -332,3 +378,42 @@ void loop () {
 | 
			
		||||
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
  */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user