コード例 #1
0
 /// <inheritdoc />
 protected override void OnTextChanged(EventArgs e)
 {
     PTextBox.SetModelValue(this, PTextBox.TextProperty, Text, EBindingSourceUpdateReason.PropertyChanged);
     base.OnTextChanged(e);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Romjk3/KMZI
        private void CryptButton_Click(object sender, EventArgs e)
        {
            try
            {
                InputText.Text = InputText.Text.ToLower();
                string alphabet = "abcdefghijklmnopqrstuvwxyz";
                string binary_block = "", binary_block_last = "", binary_letter = "", binary_text = "";
                int    n = 0, F = 0, k = 0;
                int    p = Convert.ToInt32(PTextBox.Text);
                int    q = Convert.ToInt32(QTextBox.Text);
                int    E = Convert.ToInt32(ETextBox.Text);
                OutputText.Clear();
                n = p * q;
                F = (p - 1) * (q - 1);

                //Проверка p и q на простоту
                int a = 0, b = 0;
                for (int i = 1; i <= p; i++)
                {
                    if (p % i == 0)
                    {
                        a++;
                    }
                }
                for (int i = 1; i <= q; i++)
                {
                    if (q % i == 0)
                    {
                        b++;
                    }
                }
                if (q == p)
                {
                    MessageBox.Show("p=q!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    QTextBox.Clear(); PTextBox.Clear();
                }
                else
                {
                    //проверка e
                    int nod = 0;
                    for (int i = 1; i <= F; i++)
                    {
                        if ((E % i == 0) && (F % i == 0))
                        {
                            nod++;
                        }
                    }
                    if (nod != 1)
                    {
                        MessageBox.Show("Введена некорректная экспонента зашифрования", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); ETextBox.Clear(); E = 0;
                    }
                    else
                    {
                        int n1 = n;
                        // переведем n в двоичную, дабы определить необходимые размеры блоков
                        while (n1 != 0)
                        {
                            binary_letter = binary_letter + Convert.ToString(n1 % 2);
                            n1            = n1 / 2;
                        }
                        int length_of_block = binary_letter.Length - 1;

                        /* Теперь заменяем каждую букву соответствующим элементом
                         * кольца классов вычетов по модулю 26 и переводим получившееся число
                         * в двоичную `систему счисления*/
                        for (int i = 0; i <= InputText.Text.Length - 1; i++)
                        {
                            if (alphabet.IndexOf(InputText.Text[i]) != -1)
                            {
                                //если символ - буква - работаем
                                int j = alphabet.IndexOf(InputText.Text[k]) % 26;
                                binary_letter = "";

                                // Погнали переводить в двоичную систему
                                while (j != 0)
                                {
                                    binary_letter = binary_letter + Convert.ToString(j % 2);
                                    j             = j / 2;
                                }

                                /*предусматриваем случай, если длина битового слова < 5
                                 * добавляем незначащие нули, пока длина не станет равна 5 */
                                while (binary_letter.Length < 5)
                                {
                                    binary_letter = binary_letter + "0";
                                }

                                //инициализировали бинарный текст
                                binary_text = binary_text.Insert(0, binary_letter);
                                k++;
                            }
                            // Иначе просто пропускаем символ
                            else
                            {
                                k++;
                            }
                        }
                        //самое время побить бинарный текст на блоки длиной length_of block
                        for (int i = 0; i <= binary_text.Length - 1; i = i + length_of_block)
                        {
                            if (i + length_of_block <= binary_text.Length - 1)
                            {
                                double dec_block = 0, crypt_dec_block = 1;
                                binary_block = binary_text.Substring(i, length_of_block);
                                //сразу переводим блок в дек систему
                                for (int l = 0; l <= binary_block.Length - 1; l++)
                                {
                                    int arg = 2 * (Convert.ToInt32(binary_block[l]) - 48);
                                    if (arg != 0)
                                    {
                                        dec_block = dec_block + Math.Pow(arg, l);
                                    }
                                }
                                for (int h = 1; h <= E; h++)
                                {
                                    crypt_dec_block = (crypt_dec_block * dec_block) % n;
                                }
                                OutputText.Text = " " + OutputText.Text.Insert(0, Convert.ToString(crypt_dec_block));
                            }
                            else
                            {
                                // Последний блок
                                binary_block_last = binary_text.Substring(i, binary_text.Length - i);
                                double dec_block_last = 0, crypt_dec_block_last = 1;
                                //сразу переводим блок в дек систему
                                for (int l = 0; l <= binary_block_last.Length - 1; l++)
                                {
                                    int arg = 2 * (Convert.ToInt32(binary_block_last[l]) - 48);
                                    if (arg != 0)
                                    {
                                        dec_block_last = dec_block_last + Math.Pow(arg, l);
                                    }
                                }
                                for (int h = 1; h <= E; h++)
                                {
                                    crypt_dec_block_last = (crypt_dec_block_last * dec_block_last) % n;
                                }
                                OutputText.Text = OutputText.Text.Insert(0, Convert.ToString(crypt_dec_block_last));
                            }
                        }
                    }
                }
            }
            catch { MessageBox.Show("Ошибка!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: Spol-RafaSoftware/pulse
        protected override void OnLoad(EventArgs e)
        {
            lua = new Lua();

            lua.DoString("luanet=nil");
            Skin.luaInit();

            /*  Type ty = typeof(Config);
             * foreach (MethodInfo mi in ty.GetMethods())
             * {
             *   lua.RegisterFunction(mi.Name,this , mi);
             *   Console.WriteLine(mi.Name);
             * }*/
            conn             = new Client.Connection();
            conn.recvPacket += new Action <short, Client.RecievePacket>(conn_recvPacket);
            Pulse.Client.PacketWriter.sendCheckVersion(conn.Bw);
            this.Closing += new EventHandler <System.ComponentModel.CancelEventArgs>(Game_Closing);
            base.OnLoad(e);
            AudioManager.initBass();
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            if (Skin.MaskBursts)
            {
                Animation preloadBursts = new Animation(new Rectangle(1, 1, 1, 1), 1, "burst", 10, false, true);
            }
            blackOverlay.Colour = new Color4(0.0f, 0.0f, 0.0f, 0.2f);
            toasts        = new Queue <toast>();
            toasttexture  = new Rect(new Rectangle(0, 0, Config.ResWidth, 50), Skin.skindict["toast"]);
            volumeTexture = new Rect(new Rectangle((int)(Config.ResWidth * 0.26), 727, (int)(Config.ResWidth * 0.5), 43), Skin.skindict["volumecontrol"]);
            int toSet = (int)((Config.Volume / 100d) * (Config.ResWidth * 0.5));

            volumeRect        = new Rect(new Rectangle((int)(Config.ResWidth * 0.37), 739, toSet, 25));
            volumeRect.Colour = Color4.Orange;
            t         = new Text(new Size(Width, Height), new Size(Config.ResWidth, 50), new Point(50, 0));
            this.Icon = DefaultSkin.pulseicon;

            SongLibrary.loadSongInfo();
            SongLibrary.cacheSongInfo(); //for newly added songs while game wasn't onint diff = 0;
            m = new MediaPlayer(this);
            screens.Add("menuScreen", new MenuScreen(this, "Pulse Menu"));
            screens.Add("selectScreen", new SelectScreen(this, "Song Select"));
            screens.Add("sSScreen", new ScoreSelectScreen(this, "Score Select Screen"));
            screens.Add("editScreen", new EditorScreen(this, "Edit Mode"));
            screens.Add("timingScreen", new TimingScreen(this, "Timing Screen"));
            screens.Add("ingameScreen", new IngameScreen(this, "ingame"));
            screens["ingameScreen"].Hide();
            screens["timingScreen"].Hide();
            screens["editScreen"].Hide();
            screens["selectScreen"].Hide();
            screens["sSScreen"].Hide();
            screens["menuScreen"].Show();
            Active = screens["menuScreen"];

            GL.ClearColor(Color4.SlateGray);

            fpsText = new Text(new Size(Width, Height), new Size(150, 35), new Point(Config.ResWidth - 120, 733));
            fpsText.Update("fps: " + this.TargetRenderFrequency);
            fpsText.Colour = Color.Yellow;
            fpsText.Shadow = true;
            int tipIndex = new Random().Next(Tips.tips.Length);

            addToast(Tips.tips[tipIndex]);
            if (!Directory.Exists("skin"))
            {
                Directory.CreateDirectory("skin");
            }
            fsw = new FileSystemWatcher("skin");
            fsw.EnableRaisingEvents = true;
            fsw.Created            += new FileSystemEventHandler(fsw_Created);
            pbox = new PTextBox(game, new Rectangle(0, 768 - 300, Utils.getMX(1024), 290), "", ircl);
            pbox.minimize(0);
            // Thread check = new Thread(new ThreadStart(game.checkVersions));
            //   check.IsBackground = true;
            //   check.Start();
            Account.tryLoadAcc();
            int x = 5;

            SongLibrary.findByMD5("  ", ref x);
            userScreen = new UserDisplayScreen(this);
            //  n = new Notice(new Point(0, 200), 5000, "ASHASHASHASHASHASHASHASHASHASHASHASHASHASHASHASDFK;J");
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: Romjk3/KMZI
 private void DButton_Click(object sender, EventArgs e)
 {
     try
     {
         int F = 0, d = 0, a = 0, b = 0;
         int p = Convert.ToInt32(PTextBox.Text);
         int q = Convert.ToInt32(QTextBox.Text);
         int E = Convert.ToInt32(ETextBox.Text);
         F = (p - 1) * (q - 1);
         //Проверка p и q на простоту
         for (int i = 1; i <= p; i++)
         {
             if (p % i == 0)
             {
                 a++;
             }
         }
         for (int i = 1; i <= q; i++)
         {
             if (q % i == 0)
             {
                 b++;
             }
         }
         if (p == q)
         {
             MessageBox.Show("Рассчитать экспоненту расшифрования невозможно. p=q!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             QTextBox.Clear(); PTextBox.Clear();
         }
         else
         {
             if ((a != 2) || (b != 2))
             {
                 MessageBox.Show("Рассчитать экспоненту расшифрования невозможно. Может быть, введенные числа не простые", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 QTextBox.Clear(); PTextBox.Clear();
             }
             else
             {
                 //проверка e
                 int nod = 0;
                 for (int i = 1; i <= F; i++)
                 {
                     if ((E % i == 0) && (F % i == 0))
                     {
                         nod++;
                     }
                 }
                 if (nod != 1)
                 {
                     MessageBox.Show("Рассчитать экспоненту расшифрования невозможно. Введена некорректная экспонента зашифрования", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); ETextBox.Clear(); E = 0;
                 }
                 else
                 {
                     // задаем экспоненту расшифрования
                     while (((E * d) % F) != 1)
                     {
                         d++;
                     }
                     DTextBox.Text = Convert.ToString(d);
                 }
             }
         }
     }
     catch { MessageBox.Show("Ошибка!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }