Imagara 3 năm trước cách đây
mục cha
commit
322de64df2
2 tập tin đã thay đổi với 24 bổ sung5 xóa
  1. 6 3
      Encrypter/MainWindow.xaml
  2. 18 2
      Encrypter/MainWindow.xaml.cs

+ 6 - 3
Encrypter/MainWindow.xaml

@@ -142,14 +142,17 @@
                                 HorizontalAlignment="Center"
                                 Grid.Column="1">
                         <Label Content="Ввод"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob3_input2"
+                                 Width="200" 
                                  Height="40"/>
                         <Label Content="Результат"/>
-                        <TextBox Width="200" 
+                        <TextBox Name="sposob3_output2"
+                                 Width="200" 
                                  Height="40"/>
                         <Button Width="200"
                                 Height="40"
-                                Content="Расшифровать"/>
+                                Content="Расшифровать"
+                                Click="sposob3_decrypt"/>
                     </StackPanel>
                 </Grid>
             </TabItem>

+ 18 - 2
Encrypter/MainWindow.xaml.cs

@@ -20,6 +20,7 @@ namespace Encrypter
     /// </summary>
     public partial class MainWindow : Window
     {
+        Encoding ascii = Encoding.ASCII;
         public MainWindow()
         {
             InitializeComponent();
@@ -27,12 +28,27 @@ namespace Encrypter
 
         private void sposob3_encrypt(object sender, RoutedEventArgs e)
         {
-            Encoding ascii = Encoding.ASCII;
             string input = sposob3_input.Text, output = "";
             Byte[] encodedBytes = ascii.GetBytes(input);
             foreach (Byte b in encodedBytes)
-                output += $"{b + input.Length}%^?";
+                output += $"{b + input.Length}%{input.Length}^?";
             sposob3_output.Text = output;
         }
+        private void sposob3_decrypt(object sender, RoutedEventArgs e)
+        {
+            string input = sposob3_input2.Text;
+            int count = input.Count(c => c == '%');
+            string output = "";
+            while(input.IndexOf($"%{count}^?") != -1)
+            {
+                byte temp = Convert.ToByte(Convert.ToInt32(input.Substring(0, input.IndexOf($"%{count}^?"))) - count);
+                output += Convert.ToChar(temp);
+                MessageBox.Show("output = " + output);
+                input = input.Remove(0, output.Length+4);
+                MessageBox.Show("input = " + input);
+            }    
+            sposob3_output2.Text = output;
+
+        }
     }
 }