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.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace RS232
- {
- public partial class Sender : Form
- {
- static string resource_data = Properties.Resources.dictionary;
- List<string> words = resource_data.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
- Client klient = new Client();
- public Sender()
- {
- InitializeComponent();
- klient.Show();
- }
- private void convertButton_Click(object o, EventArgs e)
- {
- //this.binBox.Text = ToBinary(ConvertToASCII(CheckDictionary(this.textBox.Text)));
- foreach (byte b in ToBinary(ConvertToASCII(CheckDictionary(this.textBox.Text))))
- Console.Write(b);
- }
- private byte[] ConvertToASCII(String data)
- {
- return Encoding.ASCII.GetBytes(data);
- }
- private byte[] ToBinary(byte[] data)
- {
- string temp = string.Join("", data.Select(byt => Convert.ToString(byt, 2).PadLeft(8, '0').PadLeft(9, '1').PadRight(11, '1')));
- return temp.Select(c => (byte)(c - '0')).ToArray();
- }
- private string CheckDictionary(string data)
- {
- const string CensoredText = "*****";
- const string PatternTemplate = @"\b({0})(s?)\b";
- const RegexOptions Options = RegexOptions.IgnoreCase;
- IEnumerable<Regex> badWordMatchers = words.
- Select(x => new Regex(string.Format(PatternTemplate, x), Options));
- return badWordMatchers.Aggregate(data, (current, matcher) => matcher.Replace(current, CensoredText));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement