Exemplo n.º 1
14
        static void Main(string[] args)
        {
            Random myRand = new Random();
            Enigma myCode = new Enigma(myRand);
            int userChoice;
            string userMessage;

            do
            {
                Console.Write("Enter '1' to Encrypt a message, '2' to Decrypt a message, or '0' to Exit: ");
                userChoice = Int32.Parse(Console.ReadLine());

                switch (userChoice)
                {
                    case 1:
                        Console.WriteLine("\nWhat message would you like to encrypt?\n");
                        userMessage = Console.ReadLine().ToUpper();
                        Console.WriteLine(myCode.Encrypt(userMessage));
                        Console.WriteLine();
                        break;
                    case 2:
                        Console.WriteLine("\nWhat message would you like to decrypt?\n");
                        userMessage = Console.ReadLine().ToUpper();
                        Console.WriteLine(myCode.Decrypt(userMessage));
                        Console.WriteLine();
                        break;
                    default:
                        break;
                }
            } while (userChoice != 0);
        }
Exemplo n.º 2
2
        public SceneSnoNavData(Enigma.D3.Assets.Scene sno_scene)
        {
            scene_sno_id = sno_scene.x000_Header.x00_SnoId;

            Enigma.D3.Assets.Scene.NavCell[] nav_cells = sno_scene.x180_NavZoneDefinition.x08_NavCells;

            if (nav_cells == null)
                return;

            foreach (Enigma.D3.Assets.Scene.NavCell nav_cell in nav_cells)
            {
                MovementFlag flags = MovementFlag.None;

                if ((nav_cell.x18 & (short)NavCellFlags.AllowWalk) != 0)
                    flags |= MovementFlag.Walk;
                if ((nav_cell.x18 & (short)NavCellFlags.AllowFlier) != 0)
                    flags |= MovementFlag.Fly;

                // skip not walkable/flyable
                if (flags == MovementFlag.None)
                    continue;

                float min_x = nav_cell.x00.X;
                float min_y = nav_cell.x00.Y;
                float min_z = nav_cell.x00.Z;

                float max_x = nav_cell.x0C.X;
                float max_y = nav_cell.x0C.Y;
                float max_z = nav_cell.x0C.Z;

                cells.Add(new Nav.Cell(min_x, min_y, min_z, max_x, max_y, max_z, flags));
            }
        }
Exemplo n.º 3
1
        public SceneData(Enigma.D3.Scene scene)
        {
            scene_id = scene.x000_Id;
            scene_sno_id = scene.x0E8_SceneSnoId;
            area_sno_id = scene.x018_LevelAreaSnoId;

            min = new Vec3(scene.x0FC_MeshMinX, scene.x100_MeshMinY, scene.x104_MeshMinZ);
            max = new Vec3(scene.x174_MeshMaxX, scene.x178_MeshMaxY, scene.x104_MeshMinZ); //there is no max z, so consider all grid cells flat
        }
Exemplo n.º 4
1
 protected override void OnModelCreating(Enigma.Modelling.ModelBuilder builder)
 {
     builder.Entity<Car>()
         .Key(c => c.RegistrationNumber)
         .Index(c => c.Nationality)
         .Index(c => c.EstimatedValue)
         .Index(c => c.EstimatedAt)
         .Index(c => c.Engine.HorsePower);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds given script as invoker of "Key Encoded" event
 /// </summary>
 /// <param name="invoker">new invoker of event</param>
 public static void AddKeyEncodedInvoker(Enigma invoker)
 {
     // add invoker to list and add all listeners to this invoker
     keyEncodedInvokers.Add(invoker);
     foreach (UnityAction <char> listener in keyEncodedListeners)
     {
         invoker.AddKeyEncodedListener(listener);
     }
 }
Exemplo n.º 6
0
        public void TestDecryption(string message, string encrypt)
        {
            // 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
            // ! ) " ( £ * % & > < @ a b c d e f g h i j k l m n o

            var secret = Enigma.Decrypt(encrypt);

            Assert.AreEqual(message, secret);
        }
Exemplo n.º 7
0
        public void TestEncryption(string message, string encrypt)
        {
            // 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
            // ! ) " ( £ * % & > < @ a b c d e f g h i j k l m n o

            var encrypted = Enigma.Encrypt(message);

            Assert.AreEqual(encrypt, encrypted);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Adds given script as invoker of "Advance Rotor" event
 /// </summary>
 /// <param name="invoker">new invoker of event</param>
 public static void AddAdvanceRotorInvoker(Enigma invoker)
 {
     // add invoker to list and add all listeners to this invoker
     advanceRotorInvokers.Add(invoker);
     foreach (UnityAction <int> listener in advanceRotorListeners)
     {
         invoker.AddAdvanceRotorListener(listener);
     }
 }
Exemplo n.º 9
0
        public void EncryptTest()
        {
            var text      = "test text";
            var password  = "******";
            var cipher    = new Enigma(password.Length).Encrypt(text, password);
            var plainText = new Enigma(password.Length).Encrypt(cipher, password);

            Assert.AreNotEqual(cipher, text);
            Assert.AreEqual(plainText, text);
        }
Exemplo n.º 10
0
        public int Clean([FromBody] string password)
        {
            if (key != null)
            {
                string check  = "passWord";
                Enigma enigma = new Enigma(key);

                string dec = enigma.PermString(password);

                int length = dec[^ 1] - 33;
Exemplo n.º 11
0
        public void NullListArgumentConstructor()
        {
            Rotor[] rotors = new Rotor[3];

            rotors[0] = null;
            rotors[1] = new Rotor();
            rotors[2] = new Rotor();

            Enigma enigma = new Enigma(rotors);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        public static byte[] Decompress(string file, CompressionType cmp)
        {
            byte[] ret = new byte[0];
            try
            {
                switch (cmp)
                {
                case CompressionType.Uncompressed:
                    ret = File.ReadAllBytes(file);
                    break;

                case CompressionType.Kosinski:
                    ret = Kosinski.Decompress(file);
                    break;

                case CompressionType.KosinskiM:
                    ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.Nemesis:
                    ret = Nemesis.Decompress(file);
                    break;

                case CompressionType.Enigma:
                    ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.SZDD:
                    ret = SZDDComp.SZDDComp.Decompress(file);
                    break;

                case CompressionType.Comper:
                    ret = Comper.Decompress(file);
                    break;

                case CompressionType.KosinskiPlus:
                    ret = KosinskiPlus.Decompress(file);
                    break;

                case CompressionType.KosinskiPlusM:
                    ret = ModuledKosinskiPlus.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!");
                }
            }
            catch
            {
                LevelData.Log("Unable to read file \"" + file + "\" with compression " + cmp.ToString() + ":");
                throw;
            }
            return(ret);
        }
Exemplo n.º 15
0
 public EnigmaApp(WheelType[] wTypes, ReflectorType rType, List <Tuple <char, char> > pSets, List <string> rotorPos)
 {
     InitializeComponent();
     wheels              = wTypes;
     reflector           = rType;
     plugboardSets       = pSets;
     enigma              = new Enigma(wheels, reflector, plugboardSets);
     loadedCharPositions = new char[] { rotorPos[0][0], rotorPos[1][0], rotorPos[2][0] };
     enigma.SetWheelPositions(loadedCharPositions);
     isLoadedFromWindow = true;
     LoadFromWindow();
 }
Exemplo n.º 16
0
        /// <summary>
        /// Verify button click
        /// </summary>
        private void btnVerify_Click(object sender, EventArgs e)
        {
            txtResult.Clear();
            int from   = (int)numFrom.Value;
            int to     = (int)numTo.Value;
            int length = to - from;

            byte[] range = GetBytes(from, length, _data);
            try { byte[] result = Nemesis.Decompress(range); txtResult.Text = "Nemesis (" + length + " bytes)"; return; } catch { }
            try  { byte[] result = Enigma.Decompress(range, Endianness.BigEndian); txtResult.Text = "Enigma (" + length + " bytes)"; return; } catch {  }
            try { byte[] result = Kosinski.Decompress(range); txtResult.Text = "Kosinski (" + length + " bytes)"; return; } catch { }
            txtResult.Text = "Not Compressed (" + length + " bytes)";
        }
Exemplo n.º 17
0
        public void ConstructorReturnsCorrectRotorCount()
        {
            Rotor[] rotors = new Rotor[4];

            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[1] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[2] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[3] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[3].IsReflector = true;

            Enigma enigma = new Enigma(rotors);
            Assert.AreEqual(4, enigma.Rotors.Count);
        }
Exemplo n.º 18
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Debug.LogError(this + " in " + gameObject.name + " has be destroyed because another " + this + " already exists");
         Destroy(gameObject);
         return;
     }
     selectedEnigma = enigmaRegistry[0];
 }
Exemplo n.º 19
0
 public void LaunchEnigma(int selectedEnigmaID)
 {
     if (isCompleted || isTimedOut)
     {
         isCompleted    = false;
         isTimedOut     = false;
         selectedEnigma = enigmaRegistry[selectedEnigmaID - 1];
         StartCoroutine(Enigma(Player.currentPhase));
     }
     else
     {
         Debug.Log("You are trying to start an enigma while the previous one is still active");
     }
 }
Exemplo n.º 20
0
        private void runEncrypt()
        {
            Enigma enigma = makeEnigma();

            if (enigma != null)
            {
                inputTextBox.Text  = CaesarAndVigenere.stripText(inputTextBox.Text).ToUpper();
                outputTextBox.Text = enigma.encrypt(inputTextBox.Text);
            }
            else
            {
                outputTextBox.Text = "";
            }
        }
Exemplo n.º 21
0
        public GameContext()
        {
            _player = new Player("Fx");
            Enigma enigma = new Enigma();

            enigma.Question = "You just passed the border of your country. What do you do ?";
            Answer answer1 = new AnswerRemoveFiveSocial();

            answer1.Action      = "You ask the nearest border gard where you are exactly, just to be sure.";
            answer1.Consequence = "You are put in custody and lose 5 social points.";
            enigma.Answers      = new List <Answer>();
            enigma.Answers.Add(answer1);

            _currentEnigma = enigma;
        }
Exemplo n.º 22
0
        public void SetEncryptionKeyReturnsCorrectTextForOneRotor()
        {
            const string plaintext = "HELLO";

            Rotor[] rotors = new Rotor[1];

            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("A");
            Assert.AreEqual(AlphabetUtils.AlphabetString, enigma.SubmitString(AlphabetUtils.AlphabetString));
            Assert.AreEqual(AlphabetUtils.ReverseAlphabetString, enigma.SubmitString(AlphabetUtils.ReverseAlphabetString));
            Assert.AreEqual(plaintext, enigma.SubmitString(plaintext));
        }
Exemplo n.º 23
0
        public void PressKeyWithOneRotorReturnsCorrectLetter()
        {
            Rotor[] rotors = new Rotor[1];

            rotors[0] = new Rotor();

            Enigma enigma = new Enigma(rotors);

            Assert.AreEqual('Z', enigma.PressKey('A'));
            Assert.AreEqual('Y', enigma.PressKey('B'));
            Assert.AreEqual('X', enigma.PressKey('C'));
            Assert.AreEqual('W', enigma.PressKey('D'));
            Assert.AreEqual('V', enigma.PressKey('E'));
            Assert.AreEqual('U', enigma.PressKey('F'));
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        Enigma _create(Char rotor1, Char rotor2, Char rotor3, Char? rotor4 = null)
        {
            var machine = new Enigma();
            machine.Reflector = Enigma.Reflector_B();
            machine.Rotor_1 = Enigma.Rotor_III();
            machine.Rotor_2 = Enigma.Rotor_I();
            machine.Rotor_3 = Enigma.Rotor_IV();

            machine.Rotor_1.InitialPosition = rotor1;
            machine.Rotor_2.InitialPosition = rotor2;
            machine.Rotor_3.InitialPosition = rotor3;
            if (rotor4 != null)
            {
                machine.Rotor_4.InitialPosition = rotor4.Value;
            }
            machine.Initialize();
            return machine;
        }
Exemplo n.º 26
0
        public static void SolvePassWord(string password, string encryptedPassWordFromUser)
        {
            if (password.Length <= 20 && password.Length >= 3)
            {
                Enigma enigma = new Enigma(new char[] { password[0], password[password.Length - 1], password[password.Length / 2] });

                string decryptedPassWord = enigma.PermString(encryptedPassWordFromUser);

                Console.WriteLine("What the raw decrypted value is, the last character is the length of the actual user password stored as a char:");
                Console.WriteLine(decryptedPassWord);

                char endCipher = decryptedPassWord[decryptedPassWord.Length - 1];

                string actualPassword = decryptedPassWord.Substring(0, endCipher - 33);

                Console.WriteLine("The actual user password is extracted from the decrypted string and is matched against the typed password:"******" : " + actualPassword);
            }
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        private void letterInputBox_TextChanged(object sender, EventArgs e)
        {
            if (letterInputBox.Text == null)
            {
                letterInputBox.Text = "";
            }
            if (letterInputBox.Text.Length != 0)
            {
                if (Char.IsLetter(letterInputBox.Text[0]))
                {
                    string input = letterInputBox.Text.ToUpper();
                    oldInputLetterBox.Text += input;

                    if (lockCheckBox.Checked)
                    {
                        Enigma enigma = makeEnigma();
                        if (enigma != null)
                        {
                            outputtedLettersBox.Text += enigma.encrypt(input);
                        }
                    }
                    else
                    {
                        Enigma enigma = makeEnigma();
                        if (enigma != null)
                        {
                            outputtedLettersBox.Text += enigma.encrypt(input);
                            int[]    newRotorPositions = enigma.stepRotors();
                            string[] newRotorStrings   = newRotorPositions.Select(x => (char)(x + 65)).Select(Char.ToString).ToArray();

                            leftPositionTB.Text  = newRotorStrings[0];
                            midPositionTB.Text   = newRotorStrings[1];
                            rightPositionTB.Text = newRotorStrings[2];
                        }
                    }
                }

                letterInputBox.Text = "";
            }

            letterInputBox.Focus();
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            string coding   = ".txt";
            string filename = "hm";

            // Создаем новую энигму
            Enigma e1 = new Enigma(4);

            // Сохраняем ее состояние
            e1.SaveEnigmaState("e1state");

            // Шифруем файл
            e1.ProcessFile(filename + coding, filename + "_coded" + coding);

            // Создаем новую энигму из файла конфигурации первой
            Enigma e2 = new Enigma("e1state");

            // Дешифруем файл
            e2.ProcessFile(filename + "_coded" + coding, filename + "_decoded" + coding);
        }
        /*private void fixedReflectorCheckBox_CheckedChanged(object sender, EventArgs e)
         * {
         *  if (fixedReflectorCheckBox.Checked)
         *      reflectorCB.Enabled = true;
         *  else
         *      reflectorCB.Enabled = false;
         * }*/

        private void findSolutionsButton_Click(object sender, EventArgs e)
        {
            rotorCount = rotorCountCB.SelectedIndex;
            holdSize   = Int32.Parse(initHoldSizeTB.Text);
            plugCount  = Int32.Parse(plugNumberTB.Text);
            finalSize  = holdSize / 2;
            if (finalSize == 0)
            {
                finalSize = 1;
            }

            numOfEncryptions = Enigma.numOfEncryptionsToBreak(rotorCount + 3, holdSize, plugCount, finalSize);

            if (!invalidHoldLabel.Visible && !invalidPlugNumberLabel.Visible)
            {
                progressBar1.Maximum = numOfEncryptions;
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                backgroundWorker1.RunWorkerAsync();
            }
        }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;

                WriteColored("Welcome to Enigma Encryption\n\n", ConsoleColor.Green);
                WriteColored("Please enter your password: "******"Enter your input text: ");
                Console.ForegroundColor = ConsoleColor.Blue;
                var plainText = Console.ReadLine();
                var enigma    = new Enigma(pass?.Length ?? 3);

                var cipher = enigma.Encrypt(plainText, pass);
                WriteColored(cipher, ConsoleColor.DarkMagenta);

                Console.ReadLine();
            }
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            char[] settings = new char[] { 'a', 'b' };
            Enigma test     = new Enigma(settings);

            //string encodedString = test.PermString("Awesome_Job!");
            //Console.WriteLine("Encode: Awesome_Job! -> " + encodedString);
            //string saveEncodedString = encodedString;

            //Just some branch Code...

            //test = new Enigma(settings);
            //encodedString = test.PermString(encodedString);
            //Console.WriteLine("Decode: " + saveEncodedString + " -> " + encodedString);

            SolvePassWord("PassWord123", PassWordExample("PassWord123"));

            //SolvePassWord("PassWord123", "a\\v;\\w\\@>.kTn\"VD0GG5w"); //From database

            //test.ContinuousType();
            Console.ReadLine();
        } //E>b9k_-x#xoO
Exemplo n.º 33
0
        public void PermString_DoubleWheelTurnOver_NonRepeatedPermutation()
        {
            enigma = new Enigma(new[] { '!', 'a' });

            string Permutation = "";

            for (int i = 0; i < 90; i++)
            {
                Permutation += 'a';
            }

            string expected = enigma.PermString(Permutation);

            Permutation = "";
            for (int i = 0; i < 90; i++)
            {
                Permutation += 'a';
            }

            string actual = enigma.PermString(Permutation);

            Assert.AreNotEqual(expected, actual);
        }
Exemplo n.º 34
0
        public async void Encrypt_ShouldReturnCharacter(char input, char expected)
        {
            // Arrange
            var eventAggregator  = new EventAggregator();
            var utilityFactory   = new UtilityFactory();
            var componentFactory = new ComponentFactory(utilityFactory);
            var settings         = new EnigmaSettingsStub(eventAggregator, componentFactory);
            var savedSettings    = new EnigmaSettings.SavedSettings()
            {
                ReflectorType        = ReflectorType.B,
                PlugboardConnections = new Dictionary <char, char>(),
                Slot1 = new EnigmaSettings.SavedSettings.Slot()
                {
                    Position  = 6,
                    RotorType = RotorType.II,
                },
                Slot2 = new EnigmaSettings.SavedSettings.Slot()
                {
                    Position  = 11,
                    RotorType = RotorType.I,
                },
                Slot3 = new EnigmaSettings.SavedSettings.Slot()
                {
                    Position  = 5,
                    RotorType = RotorType.III,
                },
            };

            settings.LoadSettings(savedSettings);
            var enigma = new Enigma(settings, utilityFactory);

            // Act
            var result = await enigma.Encrypt(input);

            // Assert
            Assert.Equal(expected, result);
        }
Exemplo n.º 35
0
 public void NullArgumentConstructor()
 {
     Enigma enigma = new Enigma(null);
 }
Exemplo n.º 36
0
        public void SetEncryptionKeyReturnsCorrectTextForOneRotorAndOneDeflectorAndOneLetterInput()
        {
            const string plaintext = "A";

            Rotor[] rotors = new Rotor[2];

            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[1] = new Rotor(AlphabetUtils.ReverseAlphabetString, "reflector");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("BB");

            string ciphertext = enigma.SubmitString(plaintext);

            Assert.AreEqual(plaintext, enigma.SubmitString(ciphertext), "Encryption symmetry is not ensured.");
        }
Exemplo n.º 37
0
        static void Main(string[] args)
        {
            SetLoggerSettings("App.config");
            logger.Info("Start");

            Session session = null;
            IDoc    app     = null;

            //Result exception in TryConvert.
            try
            {
                var config = new EnigmaConfigurations()
                {
                    Url = $"ws://127.0.0.1:4848/app/engineData/identity/{Guid.NewGuid()}",
                    //Url = $"wss://127.0.0.1/app/engineData/identity/{Guid.NewGuid()}",

                    // if you want to create your own Connection with for example header / cookies, just inject this in line
                    CreateSocket = async(url) =>
                    {
                        var ws = new ClientWebSocket();
#if NETCOREAPP2_1
                        var ck = new CookieContainer();
                        ck.Add(new Uri(url), new Cookie("X-Qlik-Session", "xxxxxxxxx"));
                        ws.Options.Cookies = ck;
                        ws.Options.RemoteCertificateValidationCallback
                            += new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return(true); });
#endif
                        //!!!!!!!!!here you can inject your cookie, header authentification,...
                        await ws.ConnectAsync(new Uri(url), CancellationToken.None);

                        return(ws);
                    }
                };

                session = Enigma.Create(config);
                // connect to the engine
                var globalTask = session.OpenAsync();
                globalTask.Wait();

                IGlobal global  = Impromptu.ActLike <IGlobal>(globalTask.Result);
                var     appName = SenseUtilities.GetFullAppName("Executive Dashboard");
                app         = global.OpenDocAsync(appName).Result;
                app.Closed += App_Closed;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            var mytasks = new List <Task>();
            var ce1     = new CalculationExample(app);

            ce1.CalcRandom(120);

            Task.WaitAll(mytasks.ToArray());

            var count = mytasks.Count;

            //global.EngineVersionAsync()
            //    .ContinueWith((engVer) =>
            //    {
            //        Console.WriteLine("CastedEngineVer:" + engVer.Result.qComponentVersion);
            //    });

            //global.OpenDocAsync(appName)
            //    .ContinueWith((newApp) =>
            //    {

            //        Console.WriteLine("Object " + (newApp.Result).ToString());

            //        var app = newApp.Result;

            //        // test the changed notification of the opend app
            //        app.Changed += App_Changed;

            //        // just a normal get script
            //        app.GetScriptAsync()
            //            .ContinueWith((script) =>
            //            {
            //                Console.WriteLine("Script" + script.Result.ToString().Substring(1, 100));
            //            });

            //        // change the script, so that the app changed is triggered
            //        app.SetScriptAsync("HALLO")
            //            .ContinueWith((res) =>
            //            {
            //                // read the changed script
            //                app.GetScriptAsync()
            //                    .ContinueWith((script) =>
            //                    {
            //                        Console.WriteLine("Script2" + script.Result.ToString());
            //                    });
            //            });

            //    });

            //Thread.Sleep(3000);
            var example = new ChangeEventsExample(app);

            example.RunExample();

            var tasks = new List <Task>();
            //Set bookmark test
            var bookmark = app.GetBookmarkAsync("demobookmark").Result;

            //evaluate request
            var request = JObject.FromObject(new
            {
                qExpression = "'$(vCurrentYear)'"
            });

            //Use this Overload from EvaluateExAsync it works fine.
            var result = app.EvaluateExAsync(request).Result;

            //Use this Overload it crashes!!!
            result = app.EvaluateExAsync("'$(vCurrentYear)'").Result;

            //Caluculation Test
            var calc = new CalculationExample(app);

            calc.CalcRandom(1);

            //find the bookmark with type
            var bookmarkExample = new BookmarkExample(app);

            tasks.Add(bookmarkExample.ListBookmarksAsync());

            //find dimensions
            var dimensionExample = new DimensionExample(app);

            tasks.Add(dimensionExample.ListDimensionsAsync());

            //find current selections
            var selectionExample = new SelectionExample(app);

            tasks.Add(selectionExample.ListCurrentSelectionsAsync());

            ////find list object data
            var listObjectExample = new ListObjectExample(app);

            tasks.Add(listObjectExample.ListListObjectDataAsync());

            ////Fire Multiple Requests
            var multipleRequestsExample = new MultipleRequests(app);

            tasks.Add(multipleRequestsExample.FireMultipleRequestsAsync());

            Task.WaitAll(tasks.ToArray());

            var task5 = listObjectExample.GetGenericObjectAsync("Region");

            var task6 = listObjectExample.GetListObjectDataAsync(task5.Result);

            dynamic jsonObject = task6.Result;

            foreach (var item in jsonObject[0].qMatrix)
            {
                Console.WriteLine(item[0]?.qText + "");
            }

            Console.WriteLine("Finish");
            var _ = session.CloseAsync();

            Console.ReadLine();
        }
Exemplo n.º 38
0
        static void Main(string[] args)
        {
            LongOpt[] opts = new[] {
                new LongOpt("help", Argument.No, null, 'h'),
                new LongOpt("compress", Argument.Required, null, 'c'),
                new LongOpt("decompress", Argument.Required, null, 'd'),
                new LongOpt("recompress", Argument.Required, null, 'r'),
                new LongOpt("same-filename", Argument.No, null, 's'),
                new LongOpt("little-endian", Argument.No, null, 'l'),
                new LongOpt("no-size", Argument.No, null, 'n')
            };
            Getopt          getopt       = new Getopt("KensSharp", args, Getopt.digest(opts), opts);
            Mode?           mode         = null;
            CompressionType?type         = null;
            Endianness      endian       = Endianness.BigEndian;
            bool            size         = true;
            bool            samefilename = false;
            int             opt          = getopt.getopt();

            while (opt != -1)
            {
                switch (opt)
                {
                case 'h':
                    ShowHelp();
                    return;

                case 'c':
                    mode = Mode.Compress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'd':
                    mode = Mode.Decompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'r':
                    mode = Mode.Recompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 's':
                    samefilename = true;
                    break;

                case 'l':
                    endian = Endianness.LittleEndian;
                    break;

                case 'n':
                    size = false;
                    break;
                }
                opt = getopt.getopt();
            }
            if (mode == null || type == null || getopt.Optind + (mode == Mode.Recompress | samefilename ? 0 : 1) >= args.Length)
            {
                ShowHelp();
                return;
            }
            string input = args[getopt.Optind];
            string output;

            if (getopt.Optind + 1 == args.Length)
            {
                output = input;
            }
            else
            {
                output = args[getopt.Optind + 1];
            }
            if (samefilename && input != "-")
            {
                switch (mode)
                {
                case Mode.Compress:
                    switch (type)
                    {
                    case CompressionType.Kosinski:
                        output = Path.ChangeExtension(input, "kos");
                        break;

                    case CompressionType.Enigma:
                        output = Path.ChangeExtension(input, "eni");
                        break;

                    case CompressionType.Nemesis:
                        output = Path.ChangeExtension(input, "nem");
                        break;

                    case CompressionType.Saxman:
                        output = Path.ChangeExtension(input, "sax");
                        break;

                    case CompressionType.KosinskiModuled:
                        output = Path.ChangeExtension(input, "kosm");
                        break;
                    }
                    break;

                case Mode.Decompress:
                    output = Path.ChangeExtension(input, "unc");
                    break;
                }
            }
            byte[] indata  = ReadInput(input);
            byte[] outdata = null;
            switch (mode)
            {
            case Mode.Compress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(indata, size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(indata, endian);
                    break;
                }
                break;

            case Mode.Decompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Decompress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Decompress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Decompress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Decompress(indata);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Decompress(indata, endian);
                    break;
                }
                break;

            case Mode.Recompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(Kosinski.Decompress(indata));
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(Enigma.Decompress(indata, endian), endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(Nemesis.Decompress(indata));
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(Saxman.Decompress(indata), size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(ModuledKosinski.Decompress(indata, endian), endian);
                    break;
                }
                break;
            }
            WriteOutput(output, outdata);
        }
Exemplo n.º 39
0
 private void Setup()
 {
     enigma = new Enigma(new [] { 'a', 'A', 'g' });
 }
Exemplo n.º 40
0
        private static ActorCommonData GetItemByHeroLocation(Enigma.D3.Enums.ItemLocation ItemLocation)
        {
            try
            {
                lock(A_Collection.Me.HeroDetails.EquippedItems)
                {
                    var Container = A_Collection.Me.HeroDetails.EquippedItems.ToList();

                    return Container.FirstOrDefault(x => x.x114_ItemLocation == ItemLocation);
                }
            }
            catch { return null; }
        }
Exemplo n.º 41
0
        public bool Connect(bool loadPossibleApps = false)
        {
            try
            {
                logger.Info($"Connect to: {ConnectUri.AbsoluteUri}");
                var config = new EnigmaConfigurations()
                {
                    Url          = ConnectUri.AbsoluteUri,
                    CreateSocket = async(Url) =>
                    {
                        var webSocket = new ClientWebSocket();
                        webSocket.Options.Cookies = new CookieContainer();
                        webSocket.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
                        var credentials = Config?.Credentials ?? null;
                        var credType    = Config?.Credentials?.Type ?? QlikCredentialType.NONE;
                        logger.Debug($"Connection type is '{credType}'");
                        var jwtSession = new JwtSessionManager();
                        switch (credType)
                        {
                        case QlikCredentialType.SESSION:
                            logger.Debug($"Session-Cookie {credentials?.Key}={credentials?.Value}.");
                            ConnectCookie = new Cookie(credentials?.Key, credentials?.Value)
                            {
                                Secure = true,
                                Domain = ConnectUri.Host,
                                Path   = "/",
                            };
                            webSocket.Options.Cookies.Add(ConnectCookie);
                            logger.Debug($"Session type: {credentials?.Type} with Session {credentials?.Value}");
                            break;

                        case QlikCredentialType.JWT:
                            logger.Debug($"Jwt type: {credentials?.Key} - {credentials?.Value}.");
                            var newCookie = jwtSession.GetJWTSession(Config.ServerUri, credentials?.Value.Replace("Bearer ", ""), "X-Qlik-Session-ser");
                            ConnectCookie = newCookie;
                            webSocket.Options.Cookies.Add(ConnectCookie);
                            break;

                        case QlikCredentialType.CLOUD:
                            logger.Debug($"Connecting to Qlik Cloud.");
                            logger.Debug($"Cloud type: {credentials?.Key} - {credentials?.Value}.");
                            webSocket.Options.SetRequestHeader(credentials?.Key, credentials?.Value);
                            break;

                        case QlikCredentialType.NEWSESSION:
                            logger.Debug($"Connecting to Qlik with a new Session.");
                            logger.Debug($"Session infos: {credentials?.Key} - {credentials?.Value}.");
                            var newSession = jwtSession.CreateNewSession(Config, new DomainUser(credentials?.Value), Config.App);
                            ConnectCookie = newSession.Cookie;
                            webSocket.Options.Cookies.Add(ConnectCookie);
                            break;

                        case QlikCredentialType.NONE:
                            // No Authentication for DESKTOP and DOCKER
                            logger.Debug($"None type: No Authentication.");
                            break;

                        default:
                            throw new Exception("Unknown Qlik connection type.");
                        }
                        webSocket.Options.KeepAliveInterval = TimeSpan.FromDays(48);
                        await webSocket.ConnectAsync(new Uri(Url), CancellationToken.None);

                        return(webSocket);
                    },
                };

                SocketSession = Enigma.Create(config);
                var globalTask = SocketSession.OpenAsync();
                globalTask.Wait(7500);
                if (!globalTask.IsCompleted)
                {
                    throw new Exception("No connection to qlik.");
                }
                IGlobal global = Impromptu.ActLike <IGlobal>(globalTask.Result);
                var     task   = global.IsDesktopModeAsync();
                task.Wait(2500);
                if (!task.IsCompleted)
                {
                    throw new Exception("No connection to qlik.");
                }
                if (task.Result)
                {
                    Mode = QlikAppMode.DESKTOP;
                }
                if (loadPossibleApps)
                {
                    lock (lockObject)
                    {
                        PossibleApps = global.GetDocListAsync().Result;
                    }
                }
                logger.Debug($"Use connection mode: {Mode}");
                if (IsSharedSession)
                {
                    try
                    {
                        CurrentApp = global.GetActiveDocAsync().Result;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "No existing shared session found. Please open the app in the browser.");
                        return(false);
                    }
                }
                else
                {
                    var appName = String.Empty;
                    if (Mode == QlikAppMode.DESKTOP)
                    {
                        appName = HelperUtilities.GetFullAppName(Config.App);
                    }
                    else
                    {
                        appName = GetAppId(global);
                    }
                    logger.Debug($"Connect with app name: {appName}");
                    CurrentApp = global.OpenDocAsync(appName).Result;
                }
                logger.Debug("The Connection to Qlik was successfully");
                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"The connection to Qlik Sense with uri '{ConnectUri}' app '{Config.App}' could not be established.");
                return(false);
            }
        }
Exemplo n.º 42
0
        static Enigma CreateSampleEnigma()
        {
            var enigma = new Enigma();
            enigma.Reflector = Enigma.Reflector_A();
            enigma.Rotor_1 = Enigma.Rotor_III();
            enigma.Rotor_2 = Enigma.Rotor_I();
            enigma.Rotor_3 = Enigma.Rotor_V();

            enigma.Rotor_1.InitialPosition = 'F';
            enigma.Rotor_2.InitialPosition = 'T';
            enigma.Rotor_3.InitialPosition = 'W';

            enigma.PlugBoard.AddPlug('f', 'q');
            enigma.PlugBoard.AddPlug('t', 's');
            enigma.PlugBoard.AddPlug('a', 'z');
            enigma.PlugBoard.AddPlug('g', 'j');
            enigma.PlugBoard.AddPlug('m', 'n');
            enigma.PlugBoard.AddPlug('b', 'o');

            enigma.Initialize();
            return enigma;
        }
Exemplo n.º 43
0
        public void SymmetryIsEnsuredWithOneFixedRotorAndReflector()
        {
            const string plaintext = "HELLO";

            Rotor[] rotors = new Rotor[2];
            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[1] = new Rotor(AlphabetUtils.ReverseAlphabetString, "reflector");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("BB");

            string ciphertext = enigma.SubmitString(plaintext);

            Assert.AreEqual(plaintext, enigma.SubmitString(ciphertext), "Encryption symmetry is not ensured.");
        }
Exemplo n.º 44
0
        public static void Compress(byte[] file, string destination, CompressionType cmp)
        {
            try
            {
                switch (cmp)
                {
                case CompressionType.Uncompressed:
                    File.WriteAllBytes(destination, file);
                    break;

                case CompressionType.Kosinski:
                    using (MemoryStream input = new MemoryStream(file))
                    {
                        using (FileStream output = File.Create(destination))
                        {
                            using (PaddedStream paddedOutput = new PaddedStream(output, 2, PaddedStreamMode.Write))
                            {
                                Kosinski.Compress(input, paddedOutput);
                            }
                        }
                    }
                    break;

                case CompressionType.KosinskiM:
                    using (MemoryStream input = new MemoryStream(file))
                    {
                        using (FileStream output = File.Create(destination))
                        {
                            using (PaddedStream paddedOutput = new PaddedStream(output, 2, PaddedStreamMode.Write))
                            {
                                ModuledKosinski.Compress(input, paddedOutput, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                            }
                        }
                    }
                    break;

                case CompressionType.Nemesis:
                    Nemesis.Compress(file, destination);
                    break;

                case CompressionType.Enigma:
                    Enigma.Compress(file, destination, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.SZDD:
                    SZDDComp.SZDDComp.Compress(file, destination);
                    break;

                case CompressionType.Comper:
                    Comper.Compress(file, destination);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!");
                }
            }
            catch
            {
                LevelData.Log("Unable to write file \"" + destination + "\" with compression " + cmp.ToString() + ":");
                throw;
            }
        }
Exemplo n.º 45
0
 static bool _shouldBeCorrect(Enigma machine)
 {
     if (machine.Rotor_1.Id == "III" && machine.Rotor_2.Id == "I" && machine.Rotor_3.Id == "V")
     {
         if (machine.Rotor_1.InitialPosition == 'F' && machine.Rotor_2.InitialPosition == 'T' && machine.Rotor_3.InitialPosition == 'W')
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 46
0
        public static SlimDX.DirectInput.Key convert_KeyToSlimDxKey(Enigma.D3.Enums.Key Key)
        {
            switch (Key)
            {
                case Enigma.D3.Enums.Key.ESCAPE:
                    return SlimDX.DirectInput.Key.Escape;
                case Enigma.D3.Enums.Key.D1:
                    return SlimDX.DirectInput.Key.D1;
                case Enigma.D3.Enums.Key.D2:
                    return SlimDX.DirectInput.Key.D2;
                case Enigma.D3.Enums.Key.D3:
                    return SlimDX.DirectInput.Key.D3;
                case Enigma.D3.Enums.Key.D4:
                    return SlimDX.DirectInput.Key.D4;
                case Enigma.D3.Enums.Key.D5:
                    return SlimDX.DirectInput.Key.D5;
                case Enigma.D3.Enums.Key.D6:
                    return SlimDX.DirectInput.Key.D6;
                case Enigma.D3.Enums.Key.D7:
                    return SlimDX.DirectInput.Key.D7;
                case Enigma.D3.Enums.Key.D8:
                    return SlimDX.DirectInput.Key.D8;
                case Enigma.D3.Enums.Key.D9:
                    return SlimDX.DirectInput.Key.D9;
                case Enigma.D3.Enums.Key.D0:
                    return SlimDX.DirectInput.Key.D0;
                case Enigma.D3.Enums.Key.MINUS:
                    return SlimDX.DirectInput.Key.Minus;
                case Enigma.D3.Enums.Key.EQUALS:
                    return SlimDX.DirectInput.Key.Equals;
                case Enigma.D3.Enums.Key.BACK:
                    return SlimDX.DirectInput.Key.Backspace;
                case Enigma.D3.Enums.Key.TAB:
                    return SlimDX.DirectInput.Key.Tab;
                case Enigma.D3.Enums.Key.Q:
                    return SlimDX.DirectInput.Key.Q;
                case Enigma.D3.Enums.Key.W:
                    return SlimDX.DirectInput.Key.W;
                case Enigma.D3.Enums.Key.E:
                    return SlimDX.DirectInput.Key.E;
                case Enigma.D3.Enums.Key.R:
                    return SlimDX.DirectInput.Key.R;
                case Enigma.D3.Enums.Key.T:
                    return SlimDX.DirectInput.Key.T;
                case Enigma.D3.Enums.Key.Y:
                    return SlimDX.DirectInput.Key.Y;
                case Enigma.D3.Enums.Key.U:
                    return SlimDX.DirectInput.Key.U;
                case Enigma.D3.Enums.Key.I:
                    return SlimDX.DirectInput.Key.I;
                case Enigma.D3.Enums.Key.O:
                    return SlimDX.DirectInput.Key.O;
                case Enigma.D3.Enums.Key.P:
                    return SlimDX.DirectInput.Key.P;
                case Enigma.D3.Enums.Key.LBRACKET:
                    return SlimDX.DirectInput.Key.LeftBracket;
                case Enigma.D3.Enums.Key.RBRACKET:
                    return SlimDX.DirectInput.Key.RightBracket;
                case Enigma.D3.Enums.Key.RETURN:
                    return SlimDX.DirectInput.Key.Return;
                case Enigma.D3.Enums.Key.LCONTROL:
                    return SlimDX.DirectInput.Key.LeftControl;
                case Enigma.D3.Enums.Key.A:
                    return SlimDX.DirectInput.Key.A;
                case Enigma.D3.Enums.Key.S:
                    return SlimDX.DirectInput.Key.S;
                case Enigma.D3.Enums.Key.D:
                    return SlimDX.DirectInput.Key.D;
                case Enigma.D3.Enums.Key.F:
                    return SlimDX.DirectInput.Key.F;
                case Enigma.D3.Enums.Key.G:
                    return SlimDX.DirectInput.Key.G;
                case Enigma.D3.Enums.Key.H:
                    return SlimDX.DirectInput.Key.H;
                case Enigma.D3.Enums.Key.J:
                    return SlimDX.DirectInput.Key.J;
                case Enigma.D3.Enums.Key.K:
                    return SlimDX.DirectInput.Key.K;
                case Enigma.D3.Enums.Key.L:
                    return SlimDX.DirectInput.Key.L;
                case Enigma.D3.Enums.Key.SEMICOLON:
                    return SlimDX.DirectInput.Key.Semicolon;
                case Enigma.D3.Enums.Key.APOSTROPHE:
                    return SlimDX.DirectInput.Key.Apostrophe;
                case Enigma.D3.Enums.Key.GRAVE:
                    return SlimDX.DirectInput.Key.Grave;
                case Enigma.D3.Enums.Key.LSHIFT:
                    return SlimDX.DirectInput.Key.LeftShift;
                case Enigma.D3.Enums.Key.BACKSLASH:
                    return SlimDX.DirectInput.Key.Backslash;
                case Enigma.D3.Enums.Key.Z:
                    return SlimDX.DirectInput.Key.Z;
                case Enigma.D3.Enums.Key.X:
                    return SlimDX.DirectInput.Key.X;
                case Enigma.D3.Enums.Key.C:
                    return SlimDX.DirectInput.Key.C;
                case Enigma.D3.Enums.Key.V:
                    return SlimDX.DirectInput.Key.V;
                case Enigma.D3.Enums.Key.B:
                    return SlimDX.DirectInput.Key.B;
                case Enigma.D3.Enums.Key.N:
                    return SlimDX.DirectInput.Key.N;
                case Enigma.D3.Enums.Key.M:
                    return SlimDX.DirectInput.Key.M;
                case Enigma.D3.Enums.Key.COMMA:
                    return SlimDX.DirectInput.Key.Comma;
                case Enigma.D3.Enums.Key.PERIOD:
                    return SlimDX.DirectInput.Key.Period;
                case Enigma.D3.Enums.Key.SLASH:
                    return SlimDX.DirectInput.Key.Slash;
                case Enigma.D3.Enums.Key.RSHIFT:
                    return SlimDX.DirectInput.Key.RightShift;
                case Enigma.D3.Enums.Key.MULTIPLY:
                    return SlimDX.DirectInput.Key.NumberPadStar;
                case Enigma.D3.Enums.Key.LMENU:
                    return SlimDX.DirectInput.Key.LeftAlt;
                case Enigma.D3.Enums.Key.SPACE:
                    return SlimDX.DirectInput.Key.Space;
                case Enigma.D3.Enums.Key.CAPITAL:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.F1:
                    return SlimDX.DirectInput.Key.F1;
                case Enigma.D3.Enums.Key.F2:
                    return SlimDX.DirectInput.Key.F2;
                case Enigma.D3.Enums.Key.F3:
                    return SlimDX.DirectInput.Key.F3;
                case Enigma.D3.Enums.Key.F4:
                    return SlimDX.DirectInput.Key.F4;
                case Enigma.D3.Enums.Key.F5:
                    return SlimDX.DirectInput.Key.F5;
                case Enigma.D3.Enums.Key.F6:
                    return SlimDX.DirectInput.Key.F6;
                case Enigma.D3.Enums.Key.F7:
                    return SlimDX.DirectInput.Key.F7;
                case Enigma.D3.Enums.Key.F8:
                    return SlimDX.DirectInput.Key.F8;
                case Enigma.D3.Enums.Key.F9:
                    return SlimDX.DirectInput.Key.F9;
                case Enigma.D3.Enums.Key.F10:
                    return SlimDX.DirectInput.Key.F10;
                case Enigma.D3.Enums.Key.NUMLOCK:
                    return SlimDX.DirectInput.Key.NumberLock;
                case Enigma.D3.Enums.Key.SCROLL:
                    return SlimDX.DirectInput.Key.ScrollLock;
                case Enigma.D3.Enums.Key.NUMPAD7:
                    return SlimDX.DirectInput.Key.NumberPad7;
                case Enigma.D3.Enums.Key.NUMPAD8:
                    return SlimDX.DirectInput.Key.NumberPad8;
                case Enigma.D3.Enums.Key.NUMPAD9:
                    return SlimDX.DirectInput.Key.NumberPad9;
                case Enigma.D3.Enums.Key.SUBTRACT:
                    return SlimDX.DirectInput.Key.Minus;
                case Enigma.D3.Enums.Key.NUMPAD4:
                    return SlimDX.DirectInput.Key.NumberPad4;
                case Enigma.D3.Enums.Key.NUMPAD5:
                    return SlimDX.DirectInput.Key.NumberPad5;
                case Enigma.D3.Enums.Key.NUMPAD6:
                    return SlimDX.DirectInput.Key.NumberPad6;
                case Enigma.D3.Enums.Key.ADD:
                    return SlimDX.DirectInput.Key.NumberPadPlus;
                case Enigma.D3.Enums.Key.NUMPAD1:
                    return SlimDX.DirectInput.Key.NumberPad1;
                case Enigma.D3.Enums.Key.NUMPAD2:
                    return SlimDX.DirectInput.Key.NumberPad2;
                case Enigma.D3.Enums.Key.NUMPAD3:
                    return SlimDX.DirectInput.Key.NumberPad3;
                case Enigma.D3.Enums.Key.NUMPAD0:
                    return SlimDX.DirectInput.Key.NumberPad0;
                case Enigma.D3.Enums.Key.DECIMAL:
                    return SlimDX.DirectInput.Key.Slash;
                case Enigma.D3.Enums.Key.OEM_102:
                    return SlimDX.DirectInput.Key.Oem102;
                case Enigma.D3.Enums.Key.F11:
                    return SlimDX.DirectInput.Key.F11;
                case Enigma.D3.Enums.Key.F12:
                    return SlimDX.DirectInput.Key.F12;
                case Enigma.D3.Enums.Key.F13:
                    return SlimDX.DirectInput.Key.F13;
                case Enigma.D3.Enums.Key.F14:
                    return SlimDX.DirectInput.Key.F14;
                case Enigma.D3.Enums.Key.F15:
                    return SlimDX.DirectInput.Key.F15;
                case Enigma.D3.Enums.Key.KANA:
                    return SlimDX.DirectInput.Key.Kana;
                case Enigma.D3.Enums.Key.ABNT_C1:
                    return SlimDX.DirectInput.Key.AbntC1;
                case Enigma.D3.Enums.Key.CONVERT:
                    return SlimDX.DirectInput.Key.Convert;
                case Enigma.D3.Enums.Key.NOCONVERT:
                    return SlimDX.DirectInput.Key.NoConvert;
                case Enigma.D3.Enums.Key.YEN:
                    return SlimDX.DirectInput.Key.Yen;
                case Enigma.D3.Enums.Key.ABNT_C2:
                    return SlimDX.DirectInput.Key.AbntC2;
                case Enigma.D3.Enums.Key.NUMPADEQUALS:
                    return SlimDX.DirectInput.Key.NumberPadEquals;
                case Enigma.D3.Enums.Key.PREVTRACK:
                    return SlimDX.DirectInput.Key.PreviousTrack;
                case Enigma.D3.Enums.Key.AT:
                    return SlimDX.DirectInput.Key.AT;
                case Enigma.D3.Enums.Key.COLON:
                    return SlimDX.DirectInput.Key.Colon;
                case Enigma.D3.Enums.Key.UNDERLINE:
                    return SlimDX.DirectInput.Key.Underline;
                case Enigma.D3.Enums.Key.KANJI:
                    return SlimDX.DirectInput.Key.Kanji;
                case Enigma.D3.Enums.Key.STOP:
                    return SlimDX.DirectInput.Key.Stop;
                case Enigma.D3.Enums.Key.AX:
                    return SlimDX.DirectInput.Key.AX;
                case Enigma.D3.Enums.Key.UNLABELED:
                    return SlimDX.DirectInput.Key.Unlabeled;
                case Enigma.D3.Enums.Key.NEXTTRACK:
                    return SlimDX.DirectInput.Key.NextTrack;
                case Enigma.D3.Enums.Key.NUMPADENTER:
                    return SlimDX.DirectInput.Key.NumberPadEnter;
                case Enigma.D3.Enums.Key.RCONTROL:
                    return SlimDX.DirectInput.Key.RightControl;
                case Enigma.D3.Enums.Key.MUTE:
                    return SlimDX.DirectInput.Key.Mute;
                case Enigma.D3.Enums.Key.CALCULATOR:
                    return SlimDX.DirectInput.Key.Calculator;
                case Enigma.D3.Enums.Key.PLAYPAUSE:
                    return SlimDX.DirectInput.Key.PlayPause;
                case Enigma.D3.Enums.Key.MEDIASTOP:
                    return SlimDX.DirectInput.Key.MediaStop;
                case Enigma.D3.Enums.Key.VOLUMEDOWN:
                    return SlimDX.DirectInput.Key.VolumeDown;
                case Enigma.D3.Enums.Key.VOLUMEUP:
                    return SlimDX.DirectInput.Key.VolumeUp;
                case Enigma.D3.Enums.Key.WEBHOME:
                    return SlimDX.DirectInput.Key.WebHome;
                case Enigma.D3.Enums.Key.NUMPADCOMMA:
                    return SlimDX.DirectInput.Key.NumberPadComma;
                case Enigma.D3.Enums.Key.DIVIDE:
                    return SlimDX.DirectInput.Key.Slash;
                case Enigma.D3.Enums.Key.SYSRQ:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.RMENU:
                    return SlimDX.DirectInput.Key.RightAlt;
                case Enigma.D3.Enums.Key.PAUSE:
                    return SlimDX.DirectInput.Key.Pause;
                case Enigma.D3.Enums.Key.HOME:
                    return SlimDX.DirectInput.Key.Home;
                case Enigma.D3.Enums.Key.UP:
                    return SlimDX.DirectInput.Key.UpArrow;
                case Enigma.D3.Enums.Key.PRIOR:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.LEFT:
                    return SlimDX.DirectInput.Key.LeftArrow;
                case Enigma.D3.Enums.Key.RIGHT:
                    return SlimDX.DirectInput.Key.RightArrow;
                case Enigma.D3.Enums.Key.END:
                    return SlimDX.DirectInput.Key.End;
                case Enigma.D3.Enums.Key.DOWN:
                    return SlimDX.DirectInput.Key.DownArrow;
                case Enigma.D3.Enums.Key.NEXT:
                    return SlimDX.DirectInput.Key.NextTrack;
                case Enigma.D3.Enums.Key.INSERT:
                    return SlimDX.DirectInput.Key.Insert;
                case Enigma.D3.Enums.Key.DELETE:
                    return SlimDX.DirectInput.Key.Delete;
                case Enigma.D3.Enums.Key.LWIN:
                    return SlimDX.DirectInput.Key.LeftWindowsKey;
                case Enigma.D3.Enums.Key.RWIN:
                    return SlimDX.DirectInput.Key.RightWindowsKey;
                case Enigma.D3.Enums.Key.APPS:
                    return SlimDX.DirectInput.Key.Applications;
                case Enigma.D3.Enums.Key.Power:
                    return SlimDX.DirectInput.Key.Power;
                case Enigma.D3.Enums.Key.SLEEP:
                    return SlimDX.DirectInput.Key.Sleep;
                case Enigma.D3.Enums.Key.WAKE:
                    return SlimDX.DirectInput.Key.Wake;
                case Enigma.D3.Enums.Key.WEBSEARCH:
                    return SlimDX.DirectInput.Key.WebSearch;
                case Enigma.D3.Enums.Key.WEBFAVORITES:
                    return SlimDX.DirectInput.Key.WebFavorites;
                case Enigma.D3.Enums.Key.WEBREFRESH:
                    return SlimDX.DirectInput.Key.WebRefresh;
                case Enigma.D3.Enums.Key.WEBSTOP:
                    return SlimDX.DirectInput.Key.WebStop;
                case Enigma.D3.Enums.Key.WEBFORWARD:
                    return SlimDX.DirectInput.Key.WebForward;
                case Enigma.D3.Enums.Key.WEBBACK:
                    return SlimDX.DirectInput.Key.WebBack;
                case Enigma.D3.Enums.Key.MYCOMPUTER:
                    return SlimDX.DirectInput.Key.MyComputer;
                case Enigma.D3.Enums.Key.MAIL:
                    return SlimDX.DirectInput.Key.Mail;
                case Enigma.D3.Enums.Key.MEDIASELECT:
                    return SlimDX.DirectInput.Key.MediaSelect;
                case Enigma.D3.Enums.Key.Mouse1:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.Mouse2:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.Mouse3:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.Mouse4:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.Mouse5:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.MWheelUp:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.MWheelDown:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.OEM_8:
                    return SlimDX.DirectInput.Key.Unknown;
                case Enigma.D3.Enums.Key.Undefined:
                    return SlimDX.DirectInput.Key.Unknown;

                default:
                    return SlimDX.DirectInput.Key.Unknown;
            }
        }
Exemplo n.º 47
0
 static Enigma _createMachine(Rotor rotor1, Rotor rotor2, Rotor rotor3, Reflector reflector)
 {
     var enigma = new Enigma();
     enigma.Rotor_1 = rotor1;
     enigma.Rotor_2 = rotor2;
     enigma.Rotor_3 = rotor3;
     enigma.Reflector = reflector;
     return enigma;
 }
Exemplo n.º 48
0
 static bool _check(Enigma machine, String cipherText, String expectedPlaintext)
 {
     int index = 0;
     var plainText = "";
     foreach(var letter in cipherText)
     {
         var output = machine.Input(letter);
         if (!output.Equals(expectedPlaintext[index]))
         {
             return false;
         }
         plainText = plainText + output;
         index = index + 1;
     }
     return true;
 }