123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Encrypter
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- Encoding ascii = Encoding.ASCII;
- public MainWindow()
- {
- InitializeComponent();
- }
- private void sposob1_encrypt(object sender, RoutedEventArgs e)
- {
- string input = sposob1_input.Text, output = "";
- Dictionary<char, int> dictionarys = input.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
- int uniqueSymbCount = dictionarys.Count();
- Byte[] encodedBytes = ascii.GetBytes(input);
- foreach (Byte b in encodedBytes)
- output += $"{b + Convert.ToInt32(dictionarys.Where(item => item.Key == Convert.ToChar(b)).Select(item => item.Value).FirstOrDefault())}%";
- sposob1_output.Text = output;
- }
- private void sposob1_decrypt(object sender, RoutedEventArgs e)
- {
- //not working
- string input = sposob1_input2.Text, output = "";
- Dictionary<char, int> dictionarys = input.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
- int uniqueSymbCount = dictionarys.Count();
- int pos = 0;
- while (input.IndexOf('%') != -1)
- {
- byte temp = Convert.ToByte(Convert.ToInt32(input.Substring(0, input.IndexOf('%'))) - Convert.ToInt32(dictionarys.Where(item => item.Key == Convert.ToChar(b)).Select(item => item.Value).FirstOrDefault()));
- pos++;
- output += Convert.ToChar(temp);
- input = input.Remove(0, input.IndexOf('%') + 1);
- }
- sposob1_output2.Text = output;
- }
- 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)
- {
- string input = sposob3_input.Text, output = "";
- Byte[] encodedBytes = ascii.GetBytes(input);
- foreach (Byte b in encodedBytes)
- output += $"{b + input.Length}%{input.Length}^?";
- sposob3_output.Text = output;
- }
- private void sposob3_decrypt(object sender, RoutedEventArgs e)
- {
- string input = sposob3_input2.Text, output = "";
- int count = input.Count(c => c == '%');
- while (input.IndexOf($"%{count}^?") != -1)
- {
- byte temp = Convert.ToByte(Convert.ToInt32(input.Substring(0, input.IndexOf($"%{count}^?"))) - count);
- output += Convert.ToChar(temp);
- input = input.Remove(0, input.IndexOf($"%{count}^?") + 3 + count.ToString().Length);
- }
- sposob3_output2.Text = output;
- }
- }
- }
|