Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- using System.Text;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.IO.Compression;
- using System.Security.Cryptography;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- byte[] Key;
- byte[] IV;
- ICryptoTransform encryptor;
- ICryptoTransform decryptor;
- bool
- public Form1()
- {
- InitializeComponent();
- using (Rijndael myRijndael = Rijndael.Create())
- {
- IV = myRijndael.IV;
- Key = myRijndael.Key;
- encryptor = myRijndael.CreateEncryptor(Key, IV);
- decryptor = myRijndael.CreateDecryptor(Key, IV);
- }
- RunWhateva();
- }
- public void RunWhateva()
- {
- String[] tekst = File.ReadAllLines("TestFile.txt");
- Dictionary<String, List<String>> slownik = new Dictionary<string, List<String>>();
- foreach (String s in tekst)
- {
- //Array t = s.ToArray();
- //char[] t = s.ToCharArray();
- List<char> t = s.ToLower().ToList();
- t.Sort();
- String st = "";
- for (int i = 0; i < t.Count; i++)
- {
- st += t[i];
- }
- //Console.WriteLine(st);
- if (!slownik.ContainsKey(st))
- {
- slownik[st] = new List<string>();
- }
- slownik[st].Add(s);
- }
- List<String> myList = new List<string>();
- foreach (var key in slownik.Keys)
- {
- myList.Add(key + " " + slownik[key].Count);
- }
- myList.Sort();
- try
- {
- using (Stream fileStream = File.Open("listklucze.bin", FileMode.Create))
- {
- if(checkBox1.Checked)
- {
- }
- using (Stream cryptoStream = new CryptoStream(fileStream, encryptor, CryptoStreamMode.Write))
- {
- using (var stream = new GZipStream(cryptoStream, CompressionMode.Compress))
- {
- BinaryFormatter bin = new BinaryFormatter();
- bin.Serialize(cryptoStream, myList);
- }
- }
- }
- }
- catch (IOException)
- {
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- List<String> kupa;
- String readFromFile = String.Empty;
- using (Rijndael rijAlg = Rijndael.Create())
- {
- using (Stream fileStream = File.Open("listklucze.bin", FileMode.Open, FileAccess.Read))
- {
- using (Stream cryptoStream = new CryptoStream(fileStream, decryptor, CryptoStreamMode.Read))
- {
- using (var stream = new GZipStream(cryptoStream, CompressionMode.Decompress))
- {
- BinaryFormatter bin = new BinaryFormatter();
- kupa = (List<String>)bin.Deserialize(stream);
- }
- }
- }
- }
- foreach (String k in kupa)
- { readFromFile += k + "\n"; }
- richTextBox1.Text = readFromFile;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement