public void NextTest(bool increment)
        {
            if (_count == 5)
            {
                this.Controls.Clear();
                Controls.Add(new FinishControl(0, 5));
            }

            var function = RandomGenerator.NextTrithemiusFunction();
            var key      = RandomGenerator.NextKey();
            var message  = RandomGenerator.NextENGMessage();

            IAlphabetEncoder trithemius = EncoderFactory
                                          .CreateEncoder(EncoderType.Trithemius)
                                          .SetMonoAlphabet(Alphabet.GetMono(MonoAlphabet.ENG))
                                          .Configure(key, (Func <int, int>)function);

            _enc = trithemius;
            _mes = message;

            label7.Text        = function.ToString();
            label8.Text        = key.ToString();
            lbDescription.Text = message;

            if (increment)
            {
                _count++;
            }

            lbCurrentTask.Text = _count.ToString();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var ENG_ALPHA = Alphabet.GetMono(MonoAlphabet.ENG);
            var UTF16     = Alphabet.GetMono(MonoAlphabet.UTF16);

            IAlphabetEncoder caesar = EncoderFactory
                                      .CreateEncoder(EncoderType.Caesar)
                                      .SetMonoAlphabet(UTF16)
                                      .Configure(1);

            IAlphabetEncoder trithemius = EncoderFactory
                                          .CreateEncoder(EncoderType.Trithemius)
                                          .SetMonoAlphabet(ENG_ALPHA)
                                          .Configure(2, new Func <int, int>(x => x + 1));

            IAlphabetEncoder vigener = EncoderFactory
                                       .CreateEncoder(EncoderType.Vigenere)
                                       .Configure("Lemon");

            IAlphabetEncoder diffiHelman = EncoderFactory
                                           .CreateEncoder(EncoderType.DiffiHelman)
                                           .Configure(5, 23, new List <int>()
            {
                23, 43
            });
            IAlphabetEncoder elgamal = EncoderFactory
                                       .CreateEncoder(EncoderType.Elgamal)
                                       .Configure(11, 2, 8, 9);

            IAlphabetEncoder des = EncoderFactory
                                   .CreateBitEncoder(BitEncodingType.Des)
                                   .Configure("чр3Ъ");

            Console.WriteLine(caesar.Encode("Azb12365.,&^%$@"));

            Console.WriteLine(trithemius.Decode(trithemius.Encode("Azb")));

            Console.WriteLine(vigener.Encode("ATTACKATDAWN"));
            Console.WriteLine(diffiHelman.Decode(null));
            Console.WriteLine(elgamal.Decode("5"));
            Console.WriteLine(elgamal.Encode("6,9"));

            string input = "Input";

            BitMessage mess   = BitMessage.Parse(input);
            string     binary = mess.ToBinaryString();

            string output = mess.ToString();

            Console.WriteLine($"\n{input}\n{binary}\n{output}");
            byte[] b   = new UnicodeEncoding().GetBytes(des.Encode("Do you know"));
            string str = new UnicodeEncoding().GetString(b);

            Console.WriteLine(str);
            b.ToList().ForEach(x => Console.WriteLine(x));

            Console.ReadLine();
        }
        public CalculationResult Calculate(string input)
        {
            var result = CalculationResult.StartCalculations
                             (input, _monoAlphabet, EncoderType.Trithemius, _codingType, out IMonoAlphabet alpha);

            IAlphabetEncoder trithemius = EncoderFactory
                                          .CreateEncoder(EncoderType.Trithemius)
                                          .SetMonoAlphabet(alpha)
                                          .Configure(_key, (Func <int, int>)_map);

            var output = _codingType == CodingType.Encoding
                ? trithemius.Encode(input) : trithemius.Decode(input);

            return(result.WithKey(_key.ToString()).WithFunction(_map).EndCalculations(output));
        }
        public CalculationResult Calculate(string input)
        {
            var result = CalculationResult.StartCalculations
                             (input, _monoAlphabet, EncoderType.Caesar, _codingType, out IMonoAlphabet alpha);

            IAlphabetEncoder caesar = EncoderFactory
                                      .CreateEncoder(EncoderType.Caesar)
                                      .SetMonoAlphabet(alpha)
                                      .Configure(_key);

            var output = _codingType == CodingType.Encoding
                ? caesar.Encode(input) : caesar.Decode(input);

            return(result.WithKey(_key.ToString()).EndCalculations(output));
        }
Exemple #5
0
        public Tuple <AnswerType, string> CheckAnswer(
            IQuestion currentQuestion,
            MonoAlphabet mono,
            PolyAlphabet poly,
            params object[] args)
        {
            IAlphabetEncoder encoder = EncoderFactory
                                       .CreateEncoder(currentQuestion.EncodingType)
                                       .SetMonoAlphabet(Alphabet.GetMono(mono))
                                       .Configure(args);
            string answer = String.Empty;

            switch (currentQuestion.CodingType)
            {
            case CodingType.Decoding:
                answer =
                    encoder.Decode(currentQuestion.Description.Description);

                if (currentQuestion.Answer.Answer.ToLower()
                    .Equals(answer.ToLower()))
                {
                    return(new Tuple <AnswerType, string>
                               (AnswerType.Correct, answer));
                }
                break;

            case CodingType.Encoding:
                answer =
                    encoder.Encode(currentQuestion.Description.Description);

                if (currentQuestion.Answer.Answer.ToLower()
                    .Equals(answer.ToLower()))
                {
                    return(new Tuple <AnswerType, string>
                               (AnswerType.Correct, answer));
                }
                break;
            }


            return(new Tuple <AnswerType, string>
                       (AnswerType.NotCorrect, answer));
        }
        private void InitQuestion()
        {
            if (_countQuestion >= EncodingCountConfiguration.GetCountByTest
                    (EncoderType.DiffiHelman))
            {
                _encodersForm.panelQuestion.Controls.Remove(this);

                _encodersForm.panelQuestion.Controls
                .Add(new FinishControl(_countCorrectQuestion, _countQuestion));

                // _encodersForm.tabPage3.Controls.Add(new FinishControl(_encodersForm));
            }

            tbN.Text = RandomGenerator.NextENGMessage(8);
            tbG.Text = RandomGenerator.NextENGMessage(8);
            tbX.Text = _codingType == CodingType.Decoding? EncoderFactory
                       .CreateEncoder(EncoderType.DSA)
                       .Configure(tbN.Text, tbG.Text).Encode(RandomGenerator.NextENGMessage(7)): RandomGenerator.NextENGMessage(7);

            tbKey.Text = string.Empty;
            _countQuestion++;
            lbCurrentTask.Text = _countQuestion.ToString();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var ENG_ALPHA = Alphabet.GetMono(MonoAlphabet.ENG);
            var UTF16     = Alphabet.GetMono(MonoAlphabet.UTF16);

            IAlphabetEncoder caesar = EncoderFactory
                                      .CreateEncoder(EncoderType.Caesar)
                                      .SetMonoAlphabet(UTF16)
                                      .Configure(1);

            IAlphabetEncoder trithemius = EncoderFactory
                                          .CreateEncoder(EncoderType.Trithemius)
                                          .SetMonoAlphabet(UTF16)
                                          .Configure(2, new Func <int, int>(x => x + 1));

            IAlphabetEncoder vigener = EncoderFactory
                                       .CreateEncoder(EncoderType.Vigenere)
                                       .Configure("Lemon");

            IAlphabetEncoder diffiHelman = EncoderFactory
                                           .CreateEncoder(EncoderType.DiffiHelman)
                                           .Configure(5, 23, new List <int>()
            {
                23, 43
            });
            IAlphabetEncoder DSA = EncoderFactory
                                   .CreateEncoder(EncoderType.DSA)
                                   .Configure(19, 5).Configure("OBCDEFQW", "ABCDEFQW");
            IAlphabetEncoder elgamal = EncoderFactory
                                       .CreateEncoder(EncoderType.Elgamal)
                                       .Configure(11, 2, 8, 9);

            IAlphabetEncoder des = EncoderFactory
                                   .CreateBitEncoder(BitEncodingType.Des)
                                   .Configure("чр3Ъ");

            // Console.WriteLine(caesar.Encode("Azb12365.,&^%$@"));
            Console.WriteLine(trithemius.Encode("<Azb"));
            Console.WriteLine(trithemius.Decode(trithemius.Encode("Azb")));


            //Console.WriteLine(diffiHelman.Decode(null));
            //string v = DSA.Encode("Here is some data to encrypt.");
            //Console.WriteLine(v);
            //Console.WriteLine(DSA.Decode(v));
            //Console.WriteLine(elgamal.Encode("6,9"));

            //string input = "Input";

            //BitMessage mess = BitMessage.Parse(input);
            //string binary = mess.ToBinaryString();

            //string output = mess.ToString();

            //Console.WriteLine($"\n{input}\n{binary}\n{output}");
            //byte[] b = new UnicodeEncoding().GetBytes(des.Encode("Do you know"));
            //string str = new UnicodeEncoding().GetString(b);
            //Console.WriteLine(str);
            //b.ToList().ForEach(x => Console.WriteLine(x));
            //var mark = new Mark(1, 5);
            //Console.WriteLine(mark.Total);

            Console.ReadLine();
        }