├── README.md └── enigmaSim ├── EndThing.pde ├── Enigma.pde ├── Light.pde ├── Plug.pde ├── PlugBoard.pde ├── PlugPoint.pde ├── Rotor.pde ├── data ├── blacktexture.jpg └── light.png └── enigmaSim.pde /README.md: -------------------------------------------------------------------------------- 1 | # Enigma-Simulator 2 | 3 | So I wanted to upload the application but there was an upload limit on github so I just uploaded the code 4 | 5 | To run it you are going to need processing, don't worry its free. 6 | https://processing.org/download/ 7 | 8 | Then download and open the code in processing, and finally press the play button. 9 | -------------------------------------------------------------------------------- /enigmaSim/EndThing.pde: -------------------------------------------------------------------------------- 1 | class EndThing { 2 | int[][] wiring; 3 | 4 | 5 | EndThing() { 6 | wiring = new int[][] {{0, 21}, {1, 10}, {2, 22}, {3, 17}, {4, 6}, {5, 8}, {6, 4}, {7, 19}, {8, 5}, {9, 25}, {10, 1}, {11, 20}, {12, 18}, {13, 15}, {14, 16}, {15, 13}, {16, 14}, {17, 3}, {18, 12}, {19, 7}, {20, 11}, {21, 0}, {22, 2}, {23, 24}, {24, 23}, {25, 9}}; 7 | } 8 | 9 | 10 | int runThrough(int input, boolean forward) { 11 | 12 | input = (input) % 26; 13 | if (forward) { 14 | return wiring[input][1]; 15 | } else { 16 | return wiring[input][0]; 17 | } 18 | 19 | 20 | 21 | 22 | // for (int i = 0; i< 26; i++) { 23 | // if (forward) { 24 | // if (input == wiring[i][0]) { 25 | // return wiring[i][1]; 26 | // } 27 | // } else { 28 | // if (input == wiring[i][1]) { 29 | // return wiring[i][0]; 30 | // } 31 | // } 32 | // } 33 | 34 | // return -1; 35 | } 36 | } -------------------------------------------------------------------------------- /enigmaSim/Enigma.pde: -------------------------------------------------------------------------------- 1 | class Enigma { 2 | Rotor rotor1; 3 | Rotor rotor2; 4 | Rotor rotor3; 5 | EndThing end; 6 | PlugBoard plugBoard; 7 | boolean showPlugs = false; 8 | 9 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 10 | Enigma() { 11 | end = new EndThing(); 12 | plugBoard = new PlugBoard(); 13 | } 14 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 15 | void setRotors(int first, int second, int third) { 16 | 17 | if (first != second && first != third && second != third) { 18 | rotor1 = new Rotor(first, 1); 19 | rotor2 = new Rotor(second, 2); 20 | rotor3 = new Rotor(third, 3); 21 | } 22 | } 23 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 24 | 25 | 26 | void setRotorPositions(int first, int second, int third) { 27 | rotor1.position = first; 28 | rotor2.position = second; 29 | rotor3.position = third; 30 | } 31 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 32 | 33 | char runMachine(char inputChar) { 34 | if (rotor1.rotorNo == rotor2.rotorNo || rotor3.rotorNo == rotor2.rotorNo || rotor1.rotorNo == rotor3.rotorNo ) { 35 | println("Error rotors cannot have the same number"); 36 | return '1'; 37 | } 38 | int inputNo = letterOrderLowerCase.indexOf(inputChar); 39 | 40 | int currentNo = inputNo; 41 | currentNo = plugBoard.runThrough(currentNo); 42 | currentNo = rotor1.runThrough(currentNo, true); 43 | currentNo = rotor2.runThrough(currentNo, true); 44 | currentNo = rotor3.runThrough(currentNo, true); 45 | currentNo = end.runThrough(currentNo, true); 46 | currentNo = rotor3.runThrough(currentNo, false); 47 | currentNo = rotor2.runThrough(currentNo, false); 48 | currentNo = rotor1.runThrough(currentNo, false); 49 | currentNo = plugBoard.runThrough(currentNo); 50 | if (currentNo == -1) { 51 | println(rotor1.position, rotor2.position, rotor3.position); 52 | } 53 | 54 | if (currentNo == inputNo) { 55 | println(inputNo, rotor1.position, rotor2.position, rotor3.position); 56 | } 57 | moveRotors(); 58 | 59 | return letterOrderLowerCase.charAt(currentNo); 60 | } 61 | 62 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 63 | 64 | 65 | void moveRotors() { 66 | rotor1.position +=1; 67 | if (rotor1.position == 26) { 68 | rotor1.position = 0; 69 | rotor2.position+=1; 70 | if (rotor2.position == 26) { 71 | rotor2.position = 0; 72 | rotor3.position+=1; 73 | if (rotor3.position == 26) { 74 | rotor3.position = 0; 75 | } 76 | } 77 | } 78 | } 79 | 80 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 | void show() { 82 | if (!showPlugs) { 83 | stroke(0); 84 | for (int i = 0; i< letters.length; i++) { 85 | letters[i].show(); 86 | } 87 | rotor1.show(); 88 | rotor2.show(); 89 | rotor3.show(); 90 | if (rotor1.rotorNo == rotor2.rotorNo || rotor3.rotorNo == rotor2.rotorNo || rotor1.rotorNo == rotor3.rotorNo ) { 91 | fill(255,0,0); 92 | text("Cannot use the same rotor twice", width/2,50); 93 | } 94 | } else { 95 | plugBoard.show(); 96 | } 97 | } 98 | 99 | //----------------------------------------------------------------------------------------------------------------------------------------------------------------- 100 | void randomRotors() { 101 | int rand1 = floor(random(5)); 102 | int rand2 = floor(random(5)); 103 | while (rand1 == rand2) { 104 | rand2 = floor(random(5)); 105 | } 106 | 107 | int rand3 = floor(random(5)); 108 | while (rand1 == rand3 || rand2 == rand3) { 109 | rand3 = floor(random(5)); 110 | } 111 | setRotors(rand1, rand2, rand3); 112 | } 113 | 114 | 115 | void randomPositions() { 116 | setRotorPositions(floor(random(26)), floor(random(26)), floor(random(26))); 117 | } 118 | 119 | //-------------------------------------------------------------------------------------------------------------------------------------------------- 120 | 121 | void click(int x, int y) { 122 | if (y > height*(9.0/10.0) && !enigma.plugBoard.movingPlug) {//if clicking the bottom of the screen then switch between plugs anad lamps 123 | enigma.showPlugs = !enigma.showPlugs; 124 | } else { 125 | 126 | enigma.rotor1.click(x, y); 127 | enigma.rotor2.click(x, y); 128 | enigma.rotor3.click(x, y); 129 | enigma.plugBoard.click(x, y); 130 | } 131 | } 132 | 133 | 134 | 135 | //------------------------------------------------------------------------------------------------------------ 136 | 137 | char[] processWord(char[] input){ 138 | char[] output = new char[input.length]; 139 | for(int i = 0 ; i< input.length; i++){ 140 | output[i] = runMachine(input[i]); 141 | } 142 | return output; 143 | } 144 | } -------------------------------------------------------------------------------- /enigmaSim/Light.pde: -------------------------------------------------------------------------------- 1 | class Light { 2 | char letter; 3 | int number; 4 | PVector pos; 5 | boolean lightUp = false; 6 | 7 | Light(char let, int numb) { 8 | letter = let; 9 | number = numb; 10 | int level; 11 | int rowPos; 12 | float x; 13 | float y; 14 | if (numb < 10) { 15 | level = 1; 16 | rowPos = numb; 17 | x = (rowPos+1.0)*width/11; 18 | } else if (numb < 19) { 19 | level = 2; 20 | rowPos = numb - 10; 21 | x = (rowPos+1.5)*width/11; 22 | } else { 23 | 24 | level = 3; 25 | rowPos = numb - 19; 26 | x = (rowPos+2.0)*width/11; 27 | } 28 | y = height/3 + level*(height*2/3)/4; 29 | pos = new PVector(x, y); 30 | } 31 | 32 | 33 | 34 | 35 | 36 | void show() { 37 | if (lightUp) { 38 | imageMode(CENTER); 39 | image(lightOnSprite, pos.x, pos.y); 40 | fill(200,100,0); 41 | } else { 42 | strokeWeight(5); 43 | fill(150); 44 | ellipse(pos.x, pos.y, 80, 80); 45 | fill(50); 46 | } 47 | textAlign(CENTER, CENTER); 48 | textSize(20); 49 | text(letter, pos.x, pos.y); 50 | } 51 | } -------------------------------------------------------------------------------- /enigmaSim/Plug.pde: -------------------------------------------------------------------------------- 1 | class Plug { 2 | int connection1; 3 | int connection2; 4 | PlugPoint point1; 5 | PlugPoint point2; 6 | boolean move1 = false; 7 | boolean move2 = false; 8 | 9 | Plug(int c1, int c2, PlugPoint p1, PlugPoint p2 ) { 10 | connection1 = c1; 11 | connection2 = c2; 12 | point1 = p1; 13 | point2 = p2; 14 | } 15 | 16 | 17 | 18 | void showLines() { 19 | 20 | stroke(100, 100, 200, 150); 21 | strokeWeight(3); 22 | 23 | if (move1) { 24 | line(mouseX, mouseY, point2.pos.x, point2.pos.y +15); 25 | } else if (move2) { 26 | line(point1.pos.x, point1.pos.y +15, mouseX, mouseY); 27 | } else { 28 | line(point1.pos.x, point1.pos.y +15, point2.pos.x, point2.pos.y +15); 29 | } 30 | } 31 | 32 | 33 | void showPlugs() { 34 | stroke(200); 35 | fill(40); 36 | rectMode(CENTER); 37 | 38 | if (move1) { 39 | rect(mouseX, mouseY, 30, 70); 40 | 41 | rect(point2.pos.x, point2.pos.y + 15, 30, 70); 42 | } else if (move2) { 43 | rect(point1.pos.x, point1.pos.y + 15, 30, 70); 44 | rect(mouseX, mouseY, 30, 70); 45 | } else { 46 | rect(point1.pos.x, point1.pos.y + 15, 30, 70); 47 | 48 | rect(point2.pos.x, point2.pos.y + 15, 30, 70); 49 | fill(255); 50 | textSize(10); 51 | text(point2.letter, point1.pos.x, point1.pos.y + 15); 52 | text(point1.letter, point2.pos.x, point2.pos.y + 15); 53 | } 54 | } 55 | 56 | 57 | boolean click(int x, int y) { 58 | if (x < point1.pos.x +15 && x > point1.pos.x - 15 && y < point1.pos.y +50 && y > point1.pos.y - 20) { 59 | move1 = true; 60 | point1.occupied = false; 61 | return true; 62 | } else if (x < point2.pos.x +15 && x > point2.pos.x - 15 && y < point2.pos.y +50 && y > point2.pos.y - 20) { 63 | move2 = true; 64 | point2.occupied = false; 65 | 66 | return true; 67 | } 68 | return false; 69 | } 70 | 71 | void setPlugPoint(int plugPointNo, PlugPoint newPoint, int connectionNo) { 72 | newPoint.occupied = true; 73 | switch(connectionNo) { 74 | case(1): 75 | point1 = newPoint; 76 | connection1 = plugPointNo; 77 | break; 78 | case(2): 79 | point2 = newPoint; 80 | connection2 = plugPointNo; 81 | break; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /enigmaSim/PlugBoard.pde: -------------------------------------------------------------------------------- 1 | class PlugBoard { 2 | Plug[] plugs = new Plug[10]; 3 | PlugPoint[] plugPoints = new PlugPoint[26]; 4 | boolean showing = false; 5 | boolean movingPlug = false; 6 | int movingPlugNo =0; 7 | 8 | PlugBoard() { 9 | for (int i = 0; i< plugPoints.length; i++) { 10 | plugPoints[i] = new PlugPoint(i); 11 | } 12 | randomisePlugs(); 13 | } 14 | 15 | 16 | void randomisePlugs() { 17 | ArrayList chosen = new ArrayList(); 18 | for (int i = 0; i< 10; i++) { 19 | int rand1 = floor(random(26)); 20 | while (chosen.contains(rand1)) { 21 | rand1 = floor(random(26)); 22 | } 23 | chosen.add(rand1); 24 | int rand2 = floor(random(26)); 25 | while (chosen.contains(rand2)) { 26 | rand2 = floor(random(26)); 27 | } 28 | chosen.add(rand2); 29 | plugs[i] = new Plug(rand1, rand2, plugPoints[rand1], plugPoints[rand2] ); 30 | plugPoints[rand1].occupied = true; 31 | plugPoints[rand2].occupied = true; 32 | } 33 | } 34 | 35 | void show() { 36 | for (int i = 0; i< 26; i++) { 37 | plugPoints[i].show(); 38 | } 39 | 40 | for (int i= 0; i< plugs.length; i++) { 41 | plugs[i].showPlugs(); 42 | } 43 | 44 | for (int i= 0; i< plugs.length; i++) { 45 | plugs[i].showLines(); 46 | } 47 | } 48 | 49 | int runThrough(int input) { 50 | for (int i = 0; i< plugs.length; i++) { 51 | if (plugs[i].connection1 == input) { 52 | return plugs[i].connection2; 53 | } else if (plugs[i].connection2 == input) { 54 | return plugs[i].connection1; 55 | } 56 | } 57 | 58 | return input;//if no plugs on that letter then just return the input 59 | } 60 | 61 | 62 | 63 | void click(int x, int y) { 64 | if (!movingPlug) { 65 | for (int i = 0; i< plugs.length; i++) { 66 | if (plugs[i].click(x, y)) { 67 | movingPlug = true; 68 | movingPlugNo = i; 69 | return; 70 | } 71 | } 72 | } else { 73 | for (int i = 0; i< plugPoints.length; i++) { 74 | if (plugPoints[i].click(x, y)) { 75 | if (!plugPoints[i].occupied) { 76 | movingPlug = false; 77 | if (plugs[movingPlugNo].move1) { 78 | plugs[movingPlugNo].setPlugPoint(i, plugPoints[i], 1); 79 | plugs[movingPlugNo].move1 = false; 80 | } else { 81 | plugs[movingPlugNo].setPlugPoint(i, plugPoints[i], 2); 82 | plugs[movingPlugNo].move2 = false; 83 | } 84 | } 85 | return; 86 | } 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /enigmaSim/PlugPoint.pde: -------------------------------------------------------------------------------- 1 | class PlugPoint { 2 | PVector pos = new PVector(); 3 | char letter; 4 | int letterNo; 5 | boolean occupied = false; 6 | PlugPoint(int no) { 7 | letterNo = no; 8 | letter = letterOrder.charAt(no); 9 | int level; 10 | int rowPos; 11 | float x; 12 | float y; 13 | if (no < 10) { 14 | level = 1; 15 | rowPos = no; 16 | x = (rowPos+1.0)*width/11; 17 | } else if (no < 19) { 18 | level = 2; 19 | rowPos = no - 10; 20 | x = (rowPos+1.5)*width/11; 21 | } else { 22 | 23 | level = 3; 24 | rowPos = no - 19; 25 | x = (rowPos+2.0)*width/11; 26 | } 27 | y = height/3 + level*(height*2/3)/4; 28 | if(no%3 ==0){ 29 | y += 15; 30 | 31 | } 32 | pos = new PVector(x, y); 33 | } 34 | 35 | 36 | void show() { 37 | textAlign(CENTER,CENTER); 38 | textSize(20); 39 | fill(255); 40 | text(letter, pos.x, pos.y-40); 41 | fill(20); 42 | stroke(255); 43 | 44 | ellipse(pos.x, pos.y, 20, 20); 45 | ellipse(pos.x, pos.y+30, 20, 20); 46 | } 47 | 48 | boolean click(int x, int y){ 49 | if (x < pos.x +15 && x > pos.x - 15 && y < pos.y +35 && y > pos.y - 35) { 50 | return true; 51 | } 52 | return false; 53 | } 54 | } -------------------------------------------------------------------------------- /enigmaSim/Rotor.pde: -------------------------------------------------------------------------------- 1 | class Rotor { 2 | int[][] wiring; 3 | int position = 0; 4 | int rotorNo; 5 | int rotorPos; 6 | 7 | Rotor(int rotorNumber, int rotorPosition) { 8 | rotorNo = rotorNumber; 9 | rotorPos = rotorPosition; 10 | switch(rotorNo) { 11 | case 0: 12 | wiring = new int[][] {{0, 15 }, {1, 4 }, {2, 25 }, {3, 20 }, {4, 14 }, {5, 7 }, {6, 23 }, {7, 18 }, {8, 2 }, {9, 21 }, {10, 5 }, {11, 12 }, {12, 19 }, {13, 1 }, {14, 6 }, {15, 11 }, {16, 17 }, {17, 8 }, {18, 13 }, {19, 16 }, {20, 9 }, {21, 22 }, {22, 0 }, {23, 24 }, {24, 3 }, {25, 10 }}; 13 | break; 14 | case 1: 15 | wiring = new int[][] {{0, 25 }, {1, 14 }, {2, 20 }, {3, 4 }, {4, 18 }, {5, 24 }, {6, 3 }, {7, 10 }, {8, 5 }, {9, 22 }, {10, 15 }, {11, 2 }, {12, 8 }, {13, 16 }, {14, 23 }, {15, 7 }, {16, 12 }, {17, 21 }, {18, 1 }, {19, 11 }, {20, 6 }, {21, 13 }, {22, 9 }, {23, 17 }, {24, 0 }, {25, 19 }}; 16 | break; 17 | case 2: 18 | wiring = new int[][] {{0, 4 }, {1, 7 }, {2, 17 }, {3, 21 }, {4, 23 }, {5, 6 }, {6, 0 }, {7, 14 }, {8, 1 }, {9, 16 }, {10, 20 }, {11, 18 }, {12, 8 }, {13, 12 }, {14, 25 }, {15, 5 }, {16, 11 }, {17, 24 }, {18, 13 }, {19, 22 }, {20, 10 }, {21, 19 }, {22, 15 }, {23, 3 }, {24, 9 }, {25, 2 }}; 19 | break; 20 | case 3: 21 | wiring = new int[][] {{0, 8 }, {1, 12 }, {2, 4 }, {3, 19 }, {4, 2 }, {5, 6 }, {6, 5 }, {7, 17 }, {8, 0 }, {9, 24 }, {10, 18 }, {11, 16 }, {12, 1 }, {13, 25 }, {14, 23 }, {15, 22 }, {16, 11 }, {17, 7 }, {18, 10 }, {19, 3 }, {20, 21 }, {21, 20 }, {22, 15 }, {23, 14 }, {24, 9 }, {25, 13 }}; 22 | break; 23 | case 4: 24 | wiring = new int[][] {{0, 16 }, {1, 22 }, {2, 4 }, {3, 17 }, {4, 19 }, {5, 25 }, {6, 20 }, {7, 8 }, {8, 14 }, {9, 0 }, {10, 18 }, {11, 3 }, {12, 5 }, {13, 6 }, {14, 7 }, {15, 9 }, {16, 10 }, {17, 15 }, {18, 24 }, {19, 23 }, {20, 2 }, {21, 21 }, {22, 1 }, {23, 13 }, {24, 12 }, {25, 11 }}; 25 | break; 26 | } 27 | } 28 | 29 | int runThrough(int input, boolean forward) { 30 | 31 | if (forward) { 32 | input = (input+position) % 26; 33 | 34 | return wiring[input][1]; 35 | } else { 36 | for (int i = 0; i< 26; i++) { 37 | if (input == wiring[i][1]) { 38 | int output = (wiring[i][0]-position); 39 | while (output<0) { 40 | output = 26+output; 41 | } 42 | output = output % 26; 43 | 44 | return output; 45 | } 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | //for (int i = 0; i< 26; i++) { 53 | // if (forward) { 54 | // if (input == wiring[i][0]) { 55 | // return wiring[i][1]; 56 | // } 57 | // } else { 58 | // if (input == wiring[i][1]) { 59 | // return wiring[i][0]; 60 | // } 61 | // } 62 | //} 63 | 64 | return -1; 65 | } 66 | 67 | 68 | void show() { 69 | int x = width/2 - ((rotorPos-2)*200); 70 | rectMode(CENTER); 71 | fill(255); 72 | rect(x, 200, 50, 120); 73 | fill(230); 74 | rect(x, 160, 50, 40); 75 | rect(x, 240, 50, 40); 76 | fill(0); 77 | textSize(20); 78 | if (position == 0) { 79 | text(1, x, 160); 80 | text(26, x, 200); 81 | text(25, x, 240); 82 | } else if (position == 1) { 83 | text(position+1, x, 160); 84 | text(position, x, 200); 85 | text((26), x, 240); 86 | } else { 87 | text(position+1, x, 160); 88 | text(position, x, 200); 89 | text((position-1), x, 240); 90 | } 91 | fill(255); 92 | textSize(30); 93 | text(rotorNo+1, x, 100); 94 | } 95 | 96 | void click(int x, int y) { 97 | int posX = width/2 - ((rotorPos-2)*200); 98 | if (x < posX + 25 && x > posX - 25 && y >160 && y < 240) { 99 | position +=1; 100 | position = position % 26; 101 | } else if (x < posX + 25 && x > posX - 25 && y >70 && y < 130) { 102 | nextRotor(); 103 | } 104 | } 105 | 106 | void nextRotor() { 107 | rotorNo = (rotorNo + 1)%5; 108 | switch(rotorNo) { 109 | case 0: 110 | wiring = new int[][] {{0, 15 }, {1, 4 }, {2, 25 }, {3, 20 }, {4, 14 }, {5, 7 }, {6, 23 }, {7, 18 }, {8, 2 }, {9, 21 }, {10, 5 }, {11, 12 }, {12, 19 }, {13, 1 }, {14, 6 }, {15, 11 }, {16, 17 }, {17, 8 }, {18, 13 }, {19, 16 }, {20, 9 }, {21, 22 }, {22, 0 }, {23, 24 }, {24, 3 }, {25, 10 }}; 111 | break; 112 | case 1: 113 | wiring = new int[][] {{0, 25 }, {1, 14 }, {2, 20 }, {3, 4 }, {4, 18 }, {5, 24 }, {6, 3 }, {7, 10 }, {8, 5 }, {9, 22 }, {10, 15 }, {11, 2 }, {12, 8 }, {13, 16 }, {14, 23 }, {15, 7 }, {16, 12 }, {17, 21 }, {18, 1 }, {19, 11 }, {20, 6 }, {21, 13 }, {22, 9 }, {23, 17 }, {24, 0 }, {25, 19 }}; 114 | break; 115 | case 2: 116 | wiring = new int[][] {{0, 4 }, {1, 7 }, {2, 17 }, {3, 21 }, {4, 23 }, {5, 6 }, {6, 0 }, {7, 14 }, {8, 1 }, {9, 16 }, {10, 20 }, {11, 18 }, {12, 8 }, {13, 12 }, {14, 25 }, {15, 5 }, {16, 11 }, {17, 24 }, {18, 13 }, {19, 22 }, {20, 10 }, {21, 19 }, {22, 15 }, {23, 3 }, {24, 9 }, {25, 2 }}; 117 | break; 118 | case 3: 119 | wiring = new int[][] {{0, 8 }, {1, 12 }, {2, 4 }, {3, 19 }, {4, 2 }, {5, 6 }, {6, 5 }, {7, 17 }, {8, 0 }, {9, 24 }, {10, 18 }, {11, 16 }, {12, 1 }, {13, 25 }, {14, 23 }, {15, 22 }, {16, 11 }, {17, 7 }, {18, 10 }, {19, 3 }, {20, 21 }, {21, 20 }, {22, 15 }, {23, 14 }, {24, 9 }, {25, 13 }}; 120 | break; 121 | case 4: 122 | wiring = new int[][] {{0, 16 }, {1, 22 }, {2, 4 }, {3, 17 }, {4, 19 }, {5, 25 }, {6, 20 }, {7, 8 }, {8, 14 }, {9, 0 }, {10, 18 }, {11, 3 }, {12, 5 }, {13, 6 }, {14, 7 }, {15, 9 }, {16, 10 }, {17, 15 }, {18, 24 }, {19, 23 }, {20, 2 }, {21, 21 }, {22, 1 }, {23, 13 }, {24, 12 }, {25, 11 }}; 123 | break; 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /enigmaSim/data/blacktexture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Bullet/Enigma-Simulator/11ef0af3037d5b41ef9cfaf8cb1988bfd316dd3d/enigmaSim/data/blacktexture.jpg -------------------------------------------------------------------------------- /enigmaSim/data/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Bullet/Enigma-Simulator/11ef0af3037d5b41ef9cfaf8cb1988bfd316dd3d/enigmaSim/data/light.png -------------------------------------------------------------------------------- /enigmaSim/enigmaSim.pde: -------------------------------------------------------------------------------- 1 | Light[] letters = new Light[26]; 2 | String letterOrder = "QWERTYUIOPASDFGHJKLZXCVBNM"; 3 | String letterOrderLowerCase = "qwertyuiopasdfghjklzxcvbnm"; 4 | PImage lightOnSprite; 5 | boolean keyIsDown = false; 6 | char keyDown; 7 | char keyLight; 8 | PImage blackground; 9 | 10 | Enigma enigma; 11 | void setup() { 12 | frameRate(30); 13 | fullScreen(); 14 | blackground = loadImage("blacktexture.jpg"); 15 | for (int i = 0; i< letters.length; i++) { 16 | letters[i] = new Light(letterOrder.charAt(i), i); 17 | } 18 | lightOnSprite = loadImage("light.png"); 19 | 20 | enigma = new Enigma(); 21 | enigma.randomRotors(); 22 | enigma.randomPositions(); 23 | } 24 | 25 | 26 | 27 | void draw() { 28 | background(0); 29 | imageMode(CORNER); 30 | image(blackground,0,0, width,height); 31 | enigma.show(); 32 | } 33 | 34 | void mousePressed() { 35 | enigma.click(mouseX,mouseY); 36 | } 37 | 38 | 39 | void keyPressed() { 40 | if (letterOrderLowerCase.indexOf(key) != -1 && !keyIsDown && !enigma.showPlugs) { 41 | char output = enigma.runMachine(key); 42 | if(output == '1'){ 43 | return; 44 | 45 | } 46 | keyLight = output; 47 | letters[letterOrderLowerCase.indexOf(output)].lightUp = true; 48 | keyIsDown = true; 49 | keyDown = key; 50 | } 51 | } 52 | 53 | 54 | void keyReleased() { 55 | if (letterOrderLowerCase.indexOf(key) != -1 && key == keyDown) { 56 | letters[letterOrderLowerCase.indexOf(keyLight)].lightUp = false; 57 | keyIsDown = false; 58 | } 59 | } --------------------------------------------------------------------------------