public static void Main()
string[] reference = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
string[] rotor1 = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
string[] rotor1b = {"w", "k", "d", "t", "x", "q", "b", "v", "n", "g", "m", "z", "a", "j", "c", "s", "y", "r", "h", "e", "f", "u", "p", "i", "l", "o"};
string[] rotor2 = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
string[] rotor2b = {"e", "f", "a", "v", "p", "t", "h", "k", "n", "u", "d", "l", "r", "y", "o", "b", "s", "c", "g", "j", "x", "i", "q", "w", "z", "m"};
string[] rotor3 = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
string[] rotor3b = {"z", "m", "c", "w", "g", "s", "v", "b", "h", "t", "p", "y", "i", "l", "a", "j", "x", "f", "k", "d", "q", "r", "u", "o", "e", "n"};
char[] message = new char[100];
string[] key = {"a","b","c"};
Console.WriteLine($"Kod: {key[0]}{key[1]}{key[2]}\n\n");
while(rotor1[0] != key[0])
while(rotor2[0] != key[1])
while(rotor3[0] != key[2])
write(rotor1, rotor1b, 1);
write(rotor2, rotor2b, 2);
write(rotor3, rotor3b, 3);
read(ref message, out userInput);
cipher(userInput, message, reference, ref rotor1, ref rotor1b, ref rotations1, ref rotor2, ref rotor2b, ref rotations2, ref rotor3, ref rotor3b, ref rotations3);
static void rotateSetup(ref string[] rotor1)
string rotorFirst = rotor1[0];
for(int i = 0; i < rotor1.Length-1; i++)
rotor1[rotor1.Length-1] = rotorFirst;
static void rotate1(ref string[] rotor1, ref string[] rotor1b, ref int rotations1, ref string[] rotor2, ref string[] rotor2b, ref int rotations2, ref string[] rotor3, ref string[] rotor3b, ref int rotations3)
string rotorFirst = rotor1[0];
for(int i = 0; i < rotor1.Length-1; i++)
rotor1[rotor1.Length-1] = rotorFirst;
string rotorFirstb = rotor1b[0];
for(int i = 0; i < rotor1b.Length-1; i++)
rotor1b[i] = rotor1b[i+1];
rotor1b[rotor1b.Length-1] = rotorFirst;
if(rotations1 == rotor1.Length)
rotate2(ref rotor2, ref rotor2b, ref rotations2, ref rotor3, ref rotor3b, ref rotations3);
static void rotate2(ref string[] rotor2, ref string[] rotor2b, ref int rotations2, ref string[] rotor3, ref string[] rotor3b, ref int rotations3)
string rotorFirst = rotor2[0];
for(int i = 0; i < rotor2.Length-1; i++)
rotor2[rotor2.Length-1] = rotorFirst;
string rotorFirstb = rotor2b[0];
for(int i = 0; i < rotor2b.Length-1; i++)
rotor2b[i] = rotor2b[i+1];
rotor2b[rotor2b.Length-1] = rotorFirst;
if(rotations2 == rotor2.Length)
rotate3(ref rotor3, ref rotations3);
static void rotate3(ref string[] rotor1, ref int rotations)
string rotorFirst = rotor1[0];
for(int i = 0; i < rotor1.Length-1; i++)
rotor1[rotor1.Length-1] = rotorFirst;
static void write(string[] rotor, string[] rotorb, int num)
Console.WriteLine($"rotor {num}: ");
for(int i = 0; i < rotor.Length-1; i++)
Console.WriteLine($"Position {i}, värde a: {rotor[i]}, värde b: {rotorb[i]}");
Console.WriteLine($"Position {rotor.Length-1}, värde a: {rotor[rotor.Length-1]}, värde b: {rotorb[rotorb.Length-1]}\n\n");
static void read(ref char[] message, out string userInput)
userInput = Console.ReadLine();
for(int i = 0; i < userInput.Length; i++)
message[i] = userInput[i];
for(int j = 0; j < userInput.Length; j++)
Console.WriteLine(message[j]);
static string cipher (string userInput, char[] message, string[] reference, ref string[] rotor1, ref string[] rotor1b, ref int rotations1, ref string[] rotor2, ref string[] rotor2b, ref int rotations2, ref string[] rotor3, ref string[] rotor3b, ref int rotations3)
int[] indexReference = new int [userInput.Length];
int[] indexRotor1 = new int [userInput.Length];
int[] indexRotor1b = new int [userInput.Length];
int[] indexRotor2 = new int [userInput.Length];
int[] indexRotor2b = new int [userInput.Length];
int[] indexRotor3 = new int [userInput.Length];
int[] indexRotor3b = new int [userInput.Length];
for(int i = 0; i < userInput.Length; i++)
indexReference[i] = Array.IndexOf(reference, message[i]);
Console.WriteLine("Refernece properly indexed");
for(int i = 0; i < userInput.Length; i++)
indexRotor1[i] = indexReference[i];
Console.WriteLine("Rotor1 properly indexed");
for(int i = 0; i < userInput.Length; i++)
indexRotor1b[i] = Array.IndexOf(rotor1b, rotor1[indexRotor1[i]]);
Console.WriteLine("Rotor1b properly indexed");
for(int i = 0; i < userInput.Length; i++)
indexRotor2[i] = indexRotor1b[i];
Console.WriteLine("Rotor2 properly indexed");