Артем Гавриленко 3 jaren geleden
bovenliggende
commit
41a84b87ee
2 gewijzigde bestanden met toevoegingen van 47 en 28 verwijderingen
  1. 19 14
      Encrypter/MainWindow.xaml
  2. 28 14
      Encrypter/MainWindow.xaml.cs

+ 19 - 14
Encrypter/MainWindow.xaml

@@ -43,24 +43,23 @@
                                 Content="Зашифровать"
                                 Click="sposob1_encrypt"/>
                     </StackPanel>
-                    <TextBox Visibility="Collapsed"
-                             Name="KeyBox"
-                             Grid.ColumnSpan="2"
-                             Width="200"
-                             Height="40"/>
+                    
                     <StackPanel Orientation="Vertical"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Center"
                                 Grid.Column="1">
                         <Label Content="Ввод"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob1_input2"
+                                 Width="200" 
                                  Height="40"/>
                         <Label Content="Результат"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob1_output2"
+                                 Width="200" 
                                  Height="40"/>
                         <Button Width="200"
                                 Height="40"
-                                Content="Расшифровать"/>
+                                Content="Расшифровать"
+                                Click="sposob1_encrypt"/>
                     </StackPanel>
                 </Grid>
             </TabItem>
@@ -82,14 +81,17 @@
                                 HorizontalAlignment="Center"
                                 Grid.Column="0">
                         <Label Content="Ввод"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob2_input"
+                                 Width="200" 
                                  Height="40"/>
                         <Label Content="Результат"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob2_output"
+                                 Width="200" 
                                  Height="40"/>
                         <Button Width="200"
                                 Height="40"
-                                Content="Зашифровать"/>
+                                Content="Зашифровать"
+                                Click="sposob2_encrypt"/>
                     </StackPanel>
 
                     <StackPanel Orientation="Vertical"
@@ -97,14 +99,17 @@
                                 HorizontalAlignment="Center"
                                 Grid.Column="1">
                         <Label Content="Ввод"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob2_input2"
+                                 Width="200" 
                                  Height="40"/>
                         <Label Content="Результат"/>
-                        <TextBox Width="200" 
+                        <TextBox x:Name="sposob2_output2"
+                                 Width="200" 
                                  Height="40"/>
                         <Button Width="200"
                                 Height="40"
-                                Content="Расшифровать"/>
+                                Content="Расшифровать"
+                                Click="sposob2_decrypt"/>
                     </StackPanel>
                 </Grid>
             </TabItem>

+ 28 - 14
Encrypter/MainWindow.xaml.cs

@@ -39,24 +39,24 @@ namespace Encrypter
 
 
 
-            char[] symb = dictionarys.Select(q => q.Key).ToArray();
+            //char[] symb = dictionarys.Select(q => q.Key).ToArray();
 
-            char[] newSymb = new char[uniqueSymbCount];
+            //char[] newSymb = new char[uniqueSymbCount];
 
             //foreach (KeyValuePair<char, int> keyValuePair in dictionarys)
             //{
             //    //keyValuePair.Value;
             //    MessageBox.Show($"{keyValuePair.Key} : {keyValuePair.Value}");
             //}
-            byte startSymb = 100;
+            //byte smb = 100;
 
 
-            for (int i = 0; i < newSymb.Length; i++)
-            {
-                newSymb[i] = Encoding.Unicode.GetChars(startSymb);
-                startSymb++;
-                MessageBox.Show(newSymb[i].ToString());
-            }
+            //for (int i = 0; i < newSymb.Length; i++)
+            //{
+            //    newSymb[i] = Convert.ToChar(smb);
+            //    smb++;
+            //    MessageBox.Show(newSymb[i].ToString());
+            //}
 
             //foreach (char c in sposob1_input.Text)
             //{
@@ -73,12 +73,28 @@ namespace Encrypter
         }
         private void sposob2_encrypt(object sender, RoutedEventArgs e)
         {
-
+            string input = sposob2_input.Text, output = "";
+            int pos = 0;
+            Byte[] encodedBytes = ascii.GetBytes(input);
+            foreach (Byte b in encodedBytes)
+            {
+                output += $"{b+pos}%";
+                pos++;
+            }
+            sposob2_output.Text = output;
         }
         private void sposob2_decrypt(object sender, RoutedEventArgs e)
         {
-
-
+            string input = sposob2_input2.Text, output = "";
+            int pos = 0;
+            while (input.IndexOf('%') != -1)
+            {
+                byte temp = Convert.ToByte(Convert.ToInt32(input.Substring(0, input.IndexOf('%'))) - pos);
+                pos++;
+                output += Convert.ToChar(temp);
+                input = input.Remove(0, input.IndexOf('%') +1);
+            }
+            sposob2_output2.Text = output;
         }
         private void sposob3_encrypt(object sender, RoutedEventArgs e)
         {
@@ -96,12 +112,10 @@ namespace Encrypter
             while (input.IndexOf($"%{count}^?") != -1)
             {
                 byte temp = Convert.ToByte(Convert.ToInt32(input.Substring(0, input.IndexOf($"%{count}^?"))) - count);
-                //MessageBox.Show(temp.ToString());
                 output += Convert.ToChar(temp);
                 input = input.Remove(0, input.IndexOf($"%{count}^?") + 3 + count.ToString().Length);
             }
             sposob3_output2.Text = output;
-
         }
     }
 }