Ejemplo n.º 1
0
        public void PermString_EncryptAndDecryptString()
        {
            Setup();

            string expected  = "Expected_String";
            string encrypted = enigma.PermString(expected);

            Setup();
            string actual = enigma.PermString(encrypted);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        } //E>b9k_-x#xoO

        public static string PassWordExample(string password)
        {
            if (password.Length <= 20 && password.Length >= 3)
            {
                Enigma enigma = new Enigma(new char[] { password[0], password[password.Length - 1], password[password.Length / 2] });

                Random rand         = new Random(DateTime.Now.Millisecond);
                int    fillerLength = 20 - password.Length;
                char   fillerLetter = (char)rand.Next(33, 123);
                string fillerString = "";
                for (int i = 0; i < fillerLength; i++)
                {
                    fillerString += fillerLetter;
                }

                string encodedPassword = enigma.PermString(password + fillerString);
                char   endCipher       = (char)(33 + password.Length);
                encodedPassword += enigma.PermLetter(endCipher);

                Console.WriteLine("What is stored in database:");
                Console.WriteLine(encodedPassword);

                return(encodedPassword);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private static async Task CleanRest()
        {
            Random rand = new Random(DateTime.Now.Millisecond);

            Console.WriteLine("Requesting key...");
            Consumer <char[]> consumer = new Consumer <char[]>(REST_URL);

            char[] key = await consumer.GetOneAsync("key");

            Console.WriteLine("Key received: " + key[0] + key[1] + key[2]);

            Enigma        enigma       = new Enigma(key);
            char          cipherLetter = (char)rand.Next(33, 123);
            string        passWord     = "******";
            StringBuilder builder      = new StringBuilder();

            for (int i = passWord.Length; i < 20; i++)
            {
                builder.Append(cipherLetter);
            }

            passWord += builder.ToString() + Convert.ToChar(passWord.Length + 33);

            string dec = enigma.PermString(passWord);

            Console.WriteLine("Generated password: "******"Sending password...");

            int response = await new Consumer <string>(REST_URL).PutAsync(dec, "clean");

            Console.WriteLine(response == 1 ? "Password accepted, Rest cleared" : "Password not accepted");
        }
Ejemplo n.º 4
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;
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
            }
        }