Advertisement
desdemona

.net

Oct 7th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Text;
  11. using System.IO;
  12. using System.Runtime.Serialization.Formatters.Binary;
  13. using System.IO.Compression;
  14. using System.Security.Cryptography;
  15.  
  16. namespace WindowsFormsApplication1
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         byte[] Key;
  21.         byte[] IV;
  22.         ICryptoTransform encryptor;
  23.         ICryptoTransform decryptor;
  24.  
  25.         bool
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.             using (Rijndael myRijndael = Rijndael.Create())
  30.             {
  31.                 IV = myRijndael.IV;
  32.                 Key = myRijndael.Key;
  33.                 encryptor = myRijndael.CreateEncryptor(Key, IV);
  34.                 decryptor = myRijndael.CreateDecryptor(Key, IV);
  35.             }
  36.             RunWhateva();
  37.  
  38.         }
  39.  
  40.         public void RunWhateva()
  41.         {
  42.             String[] tekst = File.ReadAllLines("TestFile.txt");
  43.  
  44.  
  45.             Dictionary<String, List<String>> slownik = new Dictionary<string, List<String>>();
  46.  
  47.             foreach (String s in tekst)
  48.             {
  49.                 //Array t = s.ToArray();
  50.                 //char[] t = s.ToCharArray();
  51.                 List<char> t = s.ToLower().ToList();
  52.                 t.Sort();
  53.                 String st = "";
  54.                 for (int i = 0; i < t.Count; i++)
  55.                 {
  56.                     st += t[i];
  57.                 }
  58.                 //Console.WriteLine(st);
  59.  
  60.                 if (!slownik.ContainsKey(st))
  61.                 {
  62.                     slownik[st] = new List<string>();
  63.                 }
  64.                 slownik[st].Add(s);
  65.             }
  66.             List<String> myList = new List<string>();
  67.             foreach (var key in slownik.Keys)
  68.             {
  69.                 myList.Add(key + " " + slownik[key].Count);
  70.             }
  71.             myList.Sort();
  72.  
  73.             try
  74.             {
  75.  
  76.                 using (Stream fileStream = File.Open("listklucze.bin", FileMode.Create))
  77.                 {
  78.                     if(checkBox1.Checked)
  79.                     {
  80.  
  81.                     }
  82.                     using (Stream cryptoStream = new CryptoStream(fileStream, encryptor, CryptoStreamMode.Write))
  83.                     {
  84.                         using (var stream = new GZipStream(cryptoStream, CompressionMode.Compress))
  85.                         {
  86.                             BinaryFormatter bin = new BinaryFormatter();
  87.                             bin.Serialize(cryptoStream, myList);
  88.                         }
  89.                     }
  90.                 }
  91.             }
  92.             catch (IOException)
  93.             {
  94.             }
  95.  
  96.  
  97.  
  98.  
  99.         }
  100.  
  101.         private void button1_Click(object sender, EventArgs e)
  102.         {
  103.             List<String> kupa;
  104.             String readFromFile = String.Empty;
  105.  
  106.             using (Rijndael rijAlg = Rijndael.Create())
  107.             {
  108.                 using (Stream fileStream = File.Open("listklucze.bin", FileMode.Open, FileAccess.Read))
  109.                 {
  110.                     using (Stream cryptoStream = new CryptoStream(fileStream, decryptor, CryptoStreamMode.Read))
  111.                     {
  112.                         using (var stream = new GZipStream(cryptoStream, CompressionMode.Decompress))
  113.                         {
  114.                             BinaryFormatter bin = new BinaryFormatter();
  115.                             kupa = (List<String>)bin.Deserialize(stream);
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.             foreach (String k in kupa)
  121.             { readFromFile += k + "\n"; }
  122.             richTextBox1.Text = readFromFile;
  123.  
  124.         }
  125.  
  126.     }
  127.    
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement