Пример #1
0
        private void btn_Encrypt_Click(object sender, EventArgs e)
        {
            KeyGen NewEncryptor    = new KeyGen(null, null, null);
            string encryptedString = string.Empty;

            NewEncryptor = KeyGen.EncryptRand(NewEncryptor);

            for (int x = 0; x < NewEncryptor.characters.Count(); x++)
            {
                //Console.WriteLine(NewEncryptor.characters[x] + " " + NewEncryptor.order[x] + " " + NewEncryptor.binary[x]);
            }

            List <string> testListString = TextHandler.ParseString(tb_Input.Text);

            encryptedString = TextHandler.EncryptString(testListString, NewEncryptor);
            tb_Input.Clear();
            //Console.WriteLine(encryptedString);
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "cthulhu Files (*.cthulhu)|*.cthulhu";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(saveFileDialog1.FileName, encryptedString);
            }
            else
            {
            }
        }
Пример #2
0
        public static string EncryptString(List <string> parsedString, KeyGen encKey)
        {
            string encryptedString = string.Empty;
            string orderString     = string.Empty;

            //Create the order lead tag
            for (int y = 0; y < encKey.order.Count(); y++)
            {
                if (Convert.ToString(encKey.order[y]).Length < 2)
                {
                    orderString = "0" + Convert.ToString(encKey.order[y]);
                }
                else if (Convert.ToString(encKey.order[y]).Length == 2)
                {
                    orderString = Convert.ToString(encKey.order[y]);
                }
                else
                {
                    //Console.WriteLine("Bad order length");
                    break;
                }
                encryptedString = encryptedString + orderString;
                orderString     = string.Empty;
            }

            //Create the message start tag
            encryptedString = encryptedString + "cthulhu";

            //Encrypt the characters in the parsed string
            foreach (string c in parsedString)
            {
                for (int x = 0; x < encKey.order.Count(); x++)
                {
                    if (c == encKey.characters[x])
                    {
                        encryptedString = encryptedString + encKey.binary[x] + " ";
                        break;
                    }
                    else
                    {
                    }
                }
            }

            return(encryptedString);
        }
Пример #3
0
        public static KeyGen ExistingKey(int[] keyOrder)
        {
            KeyGen completedKey = new KeyGen(null, null, null);
            int    charCount    = completedKey.characters.Count();

            if (keyOrder.Count() != charCount)
            {
                throw new IndexOutOfRangeException();
            }

            for (int x = 0; x < charCount; x++)
            {
                completedKey.order[x]  = keyOrder[x];
                completedKey.binary[x] = Convert.ToString(keyOrder[x], 2);
            }

            return(completedKey);
        }
Пример #4
0
        public static KeyGen EncryptRand(KeyGen target)
        {
            int    charCount = target.characters.Count();
            Random rng       = new Random();
            int    x         = 0;

            while (x < charCount)
            {
                bool   orderCheck   = true;
                string tempString   = string.Empty;
                int    addZeros     = 0;
                int    lengthHolder = 0;
                if (x == 0)
                {
                    target.order[x] = rng.Next(1, charCount + 1);
                    tempString      = Convert.ToString(target.order[x], 2);

                    if (tempString.Length == 6)
                    {
                    }
                    else if (tempString.Length < 6)
                    {
                        lengthHolder = tempString.Length;
                        for (addZeros = 0; addZeros < (6 - lengthHolder); addZeros++)
                        {
                            tempString = "0" + tempString;
                        }
                    }
                    target.binary[x] = tempString;
                    tempString       = string.Empty;
                    lengthHolder     = 0;
                    x++;
                }
                else if (x > 0)
                {
                    int nextValue = rng.Next(1, charCount + 1);
                    for (int y = 0; y < charCount; y++)
                    {
                        if (target.order[y] == nextValue)
                        {
                            orderCheck = false;
                            break;
                        }
                        else
                        {
                        }
                    }

                    if (orderCheck == true)
                    {
                        target.order[x] = nextValue;
                        tempString      = Convert.ToString(target.order[x], 2);

                        if (tempString.Length == 6)
                        {
                        }
                        else if (tempString.Length < 6)
                        {
                            lengthHolder = tempString.Length;
                            for (addZeros = 0; addZeros < (6 - lengthHolder); addZeros++)
                            {
                                tempString = "0" + tempString;
                            }
                        }
                        target.binary[x] = tempString;
                        tempString       = string.Empty;
                        lengthHolder     = 0;
                        x++;
                    }
                    else
                    {
                    }
                }
            }

            return(target);
        }