public static void Main(string[] args) { //TestMatrixG(); //TestMatrixH(); //TestDecodingOfCorruptedVectors(); // G = 1 0 1 1 0 // 0 1 0 1 1 var matrix = new int[2][]; matrix[0] = new int[5] { 1, 0, 1, 1, 0 }; matrix[1] = new int[5] { 0, 1, 0, 1, 1 }; var enigma = new Enigma( length: matrix[0].GetUpperBound(0) + 1, dimension: matrix.GetUpperBound(0) + 1, matrixG: matrix); var channel = new Channel(0.5); var messageToEncode = new int[2] { 0, 0 }; var encoded = enigma.Encode(messageToEncode); var corrupted = channel.SendVectorThrough(encoded); var positions = enigma.FindChangedPositions(encoded, corrupted); var result = enigma.Decode(corrupted); Console.ReadKey(); }
public void TestAccurate() { string message = "HELLO WORLD!"; Enigma enigma = new Enigma(PreMade.A, PreMade.I, PreMade.II, PreMade.III, "ABC", "AV BS CG DL FU HZ IN KM OW RX"); string encoded = enigma.Encode(message); Assert.AreEqual("QGQOP VWOXN!", encoded); }
public void TestUpperLower() { string message = "Hello world!"; Enigma enigma = new Enigma(PreMade.A, PreMade.I, PreMade.II, PreMade.III, "ABC", "AV BS CG DL FU HZ IN KM OW RX"); string encoded = enigma.Encode(message); Assert.AreEqual("Qgqop vwoxn!", encoded); }
public void TestDecodable() { string message = "HELLO WORLD"; Enigma enigma = new Enigma(PreMade.A, PreMade.I, PreMade.II, PreMade.III, "ABC", "AV BS CG DL FU HZ IN KM OW RX"); string encoded = enigma.Encode(message); enigma = new Enigma(PreMade.A, PreMade.I, PreMade.II, PreMade.III, "ABC", "AV BS CG DL FU HZ IN KM OW RX"); encoded = enigma.Encode(encoded); Assert.AreEqual(message, encoded); }
public void Simulate() { var operation = Console.ReadLine(); var seed = int.Parse(Console.ReadLine()); var enigma = new Enigma( new Enigma.Rotor(Console.ReadLine()), new Enigma.Rotor(Console.ReadLine()), new Enigma.Rotor(Console.ReadLine()) ); var message = Console.ReadLine(); var res = operation == "ENCODE" ? enigma.Encode(message, seed) : enigma.Decode(message, seed); Console.WriteLine(res); }