Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public String Random_binary_generator(int size)
- {
- String seq = "";
- Random random = new Random();
- int n = 0;
- for (var i = 0; i < size; i++)
- {
- n = random.Next(0, 2);
- seq += n;
- }
- return seq;
- }
- public char Polar_to_binary(char polar)
- {
- if (polar == 'L' || polar == 'H') return '0';
- else return '1';
- }
- #region Интерфейс алисы
- // Генерация случайной последовательности Алисой
- private void Button1_Click(object sender, EventArgs e)
- {
- // TODO: Add try-catch block for Convert operation
- if (richTextBox2.Text != "")
- {
- richTextBox1.Text = Random_binary_generator(Convert.ToInt32(richTextBox2.Text));
- }
- }
- // Генерация способа измерения Алисы
- private void Button2_Click(object sender, EventArgs e)
- {
- // TODO: Add try-catch block for Convert operation
- if (richTextBox2.Text != "")
- {
- richTextBox3.Text = Random_binary_generator(Convert.ToInt32(richTextBox2.Text));
- }
- }
- // Проверка Алисой совпадающих способов измерения
- private void Button4_Click(object sender, EventArgs e)
- {
- String alice_measure = richTextBox3.Text;
- String bob_measue = richTextBox7.Text;
- String ans = "";
- for(int i = 0; i < alice_measure.Length; i++)
- {
- if(alice_measure[i] == bob_measue[i])
- {
- ans += '1';
- }
- else
- {
- ans += '0';
- }
- }
- richTextBox8.Text = ans;
- }
- // Составление Алисой ключа шифрования
- private void Button5_Click(object sender, EventArgs e)
- {
- String polar = richTextBox4.Text;
- String ans = richTextBox8.Text;
- String output_key = "";
- for (int i = 0; i < polar.Length; i++)
- {
- if (ans[i] == '1')
- {
- output_key += Polar_to_binary(polar[i]);
- }
- }
- richTextBox10.Text = output_key;
- }
- #endregion
- #region Интерфейс Боба
- // Генерация способа измерения Боба
- private void Button3_Click(object sender, EventArgs e)
- {
- // TODO: Add try-catch block for Convert operation
- if (richTextBox12.Text != "")
- {
- richTextBox5.Text = Random_binary_generator(Convert.ToInt32(richTextBox12.Text));
- }
- }
- // Составление Бобом ключа шифрования
- private void Button6_Click(object sender, EventArgs e)
- {
- String polar = richTextBox6.Text;
- String ans = richTextBox9.Text;
- String output_key = "";
- for (int i = 0; i < polar.Length; i++)
- {
- if (ans[i] == '1')
- {
- output_key += Polar_to_binary(polar[i]);
- }
- }
- richTextBox11.Text = output_key;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement