Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 30.05.2013
Сообщений: 37
1

Программа для зашифровывания сообщений с помощью ключа выдает ошибку

05.03.2015, 16:58. Показов 418. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
нужна помощь. программа для зашифровывания сообщений с помощью ключа. как вызвать элемент массива ? выдает ошибку. это весь код

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        int[] sbox = new int[] { 3, 14, 1, 10, 4, 9, 5, 6, 8, 14, 2, 11, 0, 4, 6, 7, 15, 8, 5, 3, 9, 13, 12, 1, 10, 11, 15, 2, 13, 12, 0, 5 };
        int[] sboxRev = new int[] { 14, 2, 11, 0, 4, 6, 7, 15, 8, 5, 3, 9, 13, 12, 1, 10, 3, 14, 1, 10, 4, 9, 5, 6, 8, 14, 2, 11, 0, 4, 6, 7 };
        int[,] chars = new int[32, 32];
        
        int numPairs=8;
        int [] chardat0=new int [32];
        int chardatmax = 0;
        int [] knownP0 = new int [10000];
        int [] knownP1 = new int [10000];
        int [] knownC0 = new int [10000];
        int [] knownC1 = new int [10000];
 
int goodP0, goodP1, goodC0, goodC1;
 
 
 
 
        private void label1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int plaintext = Convert.ToInt16(textBox1.Text);
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            int i, j;
           
 
            findDiffs(); //Find some good differentials in the S-Boxes
 
            richTextBox1.Text+="Creating XOR differential table:";
 
            for(i = 0; i < 32; i++)
            for(j = 0; j < 32; j++)
            chars[i ^ j, sbox[i] ^ sbox[j]]++;
 
 
            for (i=0; i<16;i++)
            {
                for (j=0; j<16; j++)
            richTextBox1.Text+= chars[ i, j] + '\n';
            }
 
 
            int a, b, c, plaint; 
 
            c = encrypt(1,2,3);
 
            richTextBox1.Text +="ciphertext is: ";
            richTextBox1.Text += c.ToString();
           
            plaint = decrypt(4,5,6);
 
            richTextBox1.Text+="plaintext is:";
            richTextBox1.Text+=plaint.ToString();
 
 
            //encrypt(int a, int b, int c);
            //public int decrypt(9, 4, 2);
            //int numPairs = 8; //Define number of known pairs
 
            //public string genCharData(4, 7); //Find inputs that lead a certain characteristic
 
            //public string genPairs(4); //Generate chosen-plaintext pairs
 
 
            
 
            //public findGoodPair(7); //Choose a known pair that satisfies the characteristic 
            //crack(); //Use charData and "good pair" in find key 
 
            
            while (true) {
            
            }
           
    }
 
        public void genPairs(int indiff)
        {
            Console.WriteLine("\nGenerating %i known pairs with input differential of %i.\n", numPairs, indiff);
 
            Random realk0 = new Random(); //Create random subkey0
            Random realk1 = new Random(); //Create random subkey0
 
            Console.WriteLine(" Real K0 = %i\n", realk0);
            Console.WriteLine(" Real K1 = %i\n", realk1);
 
 
            int c;
            for (c = 0; c < numPairs; c++) //Create plaintext pairs with XOR difference of indiff
            {
                Random knownP0 = new Random();
                knownP1 = knownP0[c] ^ indiff;
                knownC0 = encrypt(knownP0, realk0, realk1);
                knownC1 = encrypt(knownP1, realk0, realk1);
            }
        }
 
        public int roundFunc(int input, int key)
        {
            return sbox[key ^ input];
        }
 
 
        public int encrypt(int input, int k0, int k1)   
            {
                int x0 = roundFunc(input, k0);
                int c = x0 ^ k1;
                return c;
            }
 
        public int decrypt (int cipher, int k0, int k1)
            {
                int plaint = k0^ sbox[cipher^k1];
                return plaint;
            }
 
        public void findDiffs()
        
        {
            int c, d, e, f;
            int max;
 
            for(c = 0; c < 32; c++)
                for(d = 0; d < 32; d++)
           // chars[c,d][sbox[c] ^ sbox[d]]++; 
 
         for(c = 0; c < 32; c++)
 
        {
        for(d = 0; d < 32; d++)
        Console.WriteLine (" %x ", chars [c, d]);
        Console.WriteLine ("\n");
        }
      
        }
 
 
      public void genCharData(int indiff, int outdiff)
        {
            Console.WriteLine ("\nGenerating possible intermediate values based on differential(%i —> %i):\n", indiff, outdiff);
 
            chardatmax = 0;
            int f;
            for (f = 0; f < 32; f++)
            {
                int myComp = f ^ indiff;
 
                if ((sbox[f] ^ sbox[myComp]) == outdiff)
                {
                    Console.WriteLine (" Possibles: %i + %i —> %i + %i\n", f, myComp, sbox[f], sbox[myComp]);
                    chardat0[chardatmax] = f;
                    chardatmax++;
                }
            }
        }
 
            public void findGoodPair(int outdiff)
             {
          Console.WriteLine("\nSearching for good pair:\n");
          int c;
          for (c = 0; c < numPairs; c++)
              if ((knownC0[] ^ knownC1[]) == outdiff) //Does the ciphertext pair fit the characteristic?
              {
                  goodC0 = knownC0[c];
                  goodC1 = knownC1[c];
                  goodP0 = knownP0[c];
                  goodP1 = knownP1[c];
                  Console.WriteLine (" FOUND GOOD PAIR: (P0 = %i, P1 = %i) —> (C0 = %i, C1 = %i)\n", goodP0, goodP1, goodC0, goodC1);
                  return;
              }
          Console.WriteLine ("NO GOOD PAIR FOUND!\n");
      }
 
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
 
        }
           
    }
}
Добавлено через 1 минуту
Ошибка в 193 строке кода.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
05.03.2015, 16:58
Ответы с готовыми решениями:

С помощью библиотеки DirectX написал программу для 3D модели сферы, но выдаёт ошибку
Здравствуйте! С помощью библиотеки DirectX написал программу для 3D модели сферы, но выдаёт...

Программа для сравнения двух текстов выдает ошибку
Выдает ошибку:(( error LNK2019: ссылка на неразрешенный внешний символ _WinMain@16 в функции...

Программа для решения нелинейного уравнения, выдает ошибку в функции
Задача : Составить программу для решения нелинейного уравнения с точностью четырьмя способами: ...

Программа которая выдает платформу компьютера выдает ошибку
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics,...

2
124 / 124 / 17
Регистрация: 30.06.2010
Сообщений: 478
06.03.2015, 12:06 2
SholpanB, обращение к элементу массива происходит в квадратных скобках knownC1[0]
У тебя там не 1 ошибка. Поправил все ошибки, заработало.
Миниатюры
Программа для зашифровывания сообщений с помощью ключа выдает ошибку  
0
124 / 124 / 17
Регистрация: 30.06.2010
Сообщений: 478
06.03.2015, 12:08 3
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private int[] sbox = new int[]
        {3, 14, 1, 10, 4, 9, 5, 6, 8, 14, 2, 11, 0, 4, 6, 7, 15, 8, 5, 3, 9, 13, 12, 1, 10, 11, 15, 2, 13, 12, 0, 5};
 
        private int[] sboxRev = new int[]
        {14, 2, 11, 0, 4, 6, 7, 15, 8, 5, 3, 9, 13, 12, 1, 10, 3, 14, 1, 10, 4, 9, 5, 6, 8, 14, 2, 11, 0, 4, 6, 7};
 
        private int[,] chars = new int[32, 32];
 
        private int numPairs = 8;
        private int[] chardat0 = new int[32];
        private int chardatmax = 0;
        private int[] knownP0 = new int[10000];
        private int[] knownP1 = new int[10000];
        private int[] knownC0 = new int[10000];
        private int[] knownC1 = new int[10000];
 
        private int goodP0, goodP1, goodC0, goodC1;
 
        public void genPairs(int indiff)
        {
            Console.WriteLine("\nGenerating %i known pairs with input differential of %i.\n", numPairs, indiff);
 
            Random realk0 = new Random(); //Create random subkey0
            Random realk1 = new Random(); //Create random subkey0
 
            Console.WriteLine(" Real K0 = %i\n", realk0);
            Console.WriteLine(" Real K1 = %i\n", realk1);
 
            int c;
            for (c = 0; c < numPairs; c++) //Create plaintext pairs with XOR difference of indiff
            {
                Random knownP0 = new Random();
                knownP1[c] = knownP0.Next(10) ^ indiff;
                knownC0[c] = encrypt(knownP0.Next(10), realk0.Next(10), realk1.Next(10));
                knownC1[c] = encrypt(knownP1[c], realk0.Next(10), realk1.Next(10));
            }
        }
 
        public int roundFunc(int input, int key)
        {
            return sbox[key ^ input];
        }
 
 
        public int encrypt(int input, int k0, int k1)
        {
            int x0 = roundFunc(input, k0);
            int c = x0 ^ k1;
            return c;
        }
 
        public int decrypt(int cipher, int k0, int k1)
        {
            int plaint = k0 ^ sbox[cipher ^ k1];
            return plaint;
        }
 
        public void findDiffs()
        {
            int c, d, e, f;
            int max;
 
            for (c = 0; c < 32; c++)
                for (d = 0; d < 32; d++)
                    for (c = 0; c < 32; c++)
                    {
                        for (d = 0; d < 32; d++)
                            Console.WriteLine(" %x ", chars[c, d]);
                        Console.WriteLine("\n");
                    }
        }
 
 
        public void genCharData(int indiff, int outdiff)
        {
            Console.WriteLine("\nGenerating possible intermediate values based on differential(%i —> %i):\n", indiff,
                outdiff);
 
            chardatmax = 0;
            int f;
            for (f = 0; f < 32; f++)
            {
                int myComp = f ^ indiff;
 
                if ((sbox[f] ^ sbox[myComp]) == outdiff)
                {
                    Console.WriteLine(" Possibles: %i + %i —> %i + %i\n", f, myComp, sbox[f], sbox[myComp]);
                    chardat0[chardatmax] = f;
                    chardatmax++;
                }
            }
        }
 
        public void findGoodPair(int outdiff)
        {
            Console.WriteLine("\nSearching for good pair:\n");
            int c;
            for (c = 0; c < numPairs; c++)
                if ((knownC0[c] ^ knownC1[c]) == outdiff) //Does the ciphertext pair fit the characteristic?
                {
                    goodC0 = knownC0[c];
                    goodC1 = knownC1[c];
                    goodP0 = knownP0[c];
                    goodP1 = knownP1[c];
                    Console.WriteLine(" FOUND GOOD PAIR: (P0 = %i, P1 = %i) —> (C0 = %i, C1 = %i)\n", goodP0, goodP1,
                        goodC0, goodC1);
                    return;
                }
            Console.WriteLine("NO GOOD PAIR FOUND!\n");
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int plaintext = Convert.ToInt16(textBox1.Text);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            int i, j;
            
            findDiffs(); //Find some good differentials in the S-Boxes
 
            richTextBox1.Text += "Creating XOR differential table:";
 
            for (i = 0; i < 32; i++)
                for (j = 0; j < 32; j++)
                    chars[i ^ j, sbox[i] ^ sbox[j]]++;
 
 
            for (i = 0; i < 16; i++)
            {
                for (j = 0; j < 16; j++)
                    richTextBox1.Text += chars[i, j] + '\n';
            }
 
 
            int a, b, c, plaint;
 
            c = encrypt(1, 2, 3);
 
            richTextBox1.Text += "ciphertext is: ";
            richTextBox1.Text += c.ToString();
 
            plaint = decrypt(4, 5, 6);
 
            richTextBox1.Text += "plaintext is:";
            richTextBox1.Text += plaint.ToString();
        }
    }
}
0
06.03.2015, 12:08
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
06.03.2015, 12:08
Помогаю со студенческими работами здесь

При решении программа выдаёт значение функции, равное 0 или выдаёт ошибку. Что не так?
#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;cmath&gt; using namespace std; long Fact(short...

Получить данные с сайта с помощью requests(выдаёт ошибку 503)
использую s = requests.Session() r = s.get(url, auth=(login, password)) питон версии 3.5 ...

FCEditor "выдает ошибку" тормозится на строке 63. Программа для конвертации программного кода в блок-схему
using System; internal class Complex : IEquatable&lt;Complex&gt; { //int a действительная часть -...

При отправке почты с помощью CDONTS.NewMail, ASP выдает ошибку 'разрешение отклонено'.
На сервере стоит Exchange сервер. При отправке почты с помощью CDONTS.NewMail, ASP выдает ошибку...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru