Advertisement
Guest User

Untitled

a guest
Nov 12th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 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.RegularExpressions;
  11. using System.Threading;
  12. using System.IO;
  13.  
  14. namespace SpintaxDecoder
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         List<string> sentences = new List<string>();
  24.         public int Count = 0;
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             button1.Text = "Generating...";
  29.             button1.Enabled = false;
  30.  
  31.             Application.DoEvents();
  32.  
  33.             string data = richTextBox1.Text;
  34.  
  35.             Random rand = new Random(this.Timestamp());
  36.  
  37.             for (; ; )
  38.             {
  39.                 string spun = this.spintax(rand, data);
  40.  
  41.                 if (sentences.Contains(spun) != true)
  42.                 {
  43.                     sentences.Add(spun);
  44.                 }
  45.                 else
  46.                 {
  47.                     this.Count++;
  48.                 }
  49.  
  50.                 if (this.Count == 1000)
  51.                 {
  52.                     break;
  53.                 }
  54.  
  55.             }
  56.  
  57.             label2.Text = this.sentences.Count().ToString();
  58.  
  59.             foreach (string sentence in sentences)
  60.             {
  61.                 richTextBox2.Text += sentence + "\n";
  62.             }
  63.  
  64.             MessageBox.Show("Completed!", "Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  65.  
  66.             button1.Enabled = true;
  67.             button1.Text = "Start Decoding";
  68.  
  69.             this.sentences.Clear();
  70.             this.Count = 0;
  71.         }
  72.  
  73.         public int Timestamp()
  74.         {
  75.             long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
  76.             ticks /= 10000000;
  77.             return Convert.ToInt32(ticks);
  78.         }
  79.  
  80.         public string spintax(Random rnd, string str)
  81.         {
  82.             string pattern = "{[^{}]*}";
  83.             Match m = Regex.Match(str, pattern);
  84.             while (m.Success)
  85.             {
  86.                 string seg = str.Substring(m.Index + 1, m.Length - 2);
  87.                 string[] choices = seg.Split('|');
  88.                 str = str.Substring(0, m.Index) + choices[rnd.Next(choices.Length)] + str.Substring(m.Index + m.Length);
  89.                 m = Regex.Match(str, pattern);
  90.             }
  91.  
  92.             return str;
  93.         }
  94.  
  95.         private void button2_Click(object sender, EventArgs e)
  96.         {
  97.             saveFileDialog1.Filter = "Text File|.txt";
  98.             saveFileDialog1.InitialDirectory = "C:\\";
  99.             saveFileDialog1.ShowDialog();
  100.  
  101.             string file = saveFileDialog1.FileName;
  102.  
  103.             if (file.Trim() != "")
  104.             {
  105.                 StreamWriter writer = new StreamWriter(file);
  106.  
  107.                 string[] lines = richTextBox2.Text.Split('\n');
  108.  
  109.                 foreach(string line in lines)
  110.                 {
  111.                     writer.WriteLine(line);
  112.                 }
  113.  
  114.                 writer.Close();
  115.                 MessageBox.Show("File saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement