Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.33 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.  
  11. namespace WindowsFormsApp5
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         bool searchFor;
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.             textBox2.MaxLength = 1;
  21.             splitterBox.MaxLength = 1;
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.            
  27.             string input = textBox1.Text;
  28.             if (!searchFor)
  29.             {
  30.                 char ill = Convert.ToChar(textBox2.Text);
  31.                 MessageBox.Show("An folgender Stelle kommt der illegale Charakter vor: " + input.IndexOf(ill));
  32.             }
  33.             else
  34.             {
  35.                 string ill = textBox2.Text;
  36.                 MessageBox.Show("An folgender Stelle kommt der illegale Charakter vor: " + input.IndexOf(ill));
  37.             }
  38.            
  39.            
  40.         }
  41.  
  42.         private void checkChange(object sender, EventArgs e)
  43.         {
  44.             if (searchFor)
  45.             {
  46.                 illegal.Text = "illegal char";
  47.                 textBox2.MaxLength = 1;
  48.                 textBox2.Text = "";
  49.                 searchFor = false;
  50.             }
  51.             else
  52.             {
  53.                 illegal.Text = "illegal string";
  54.                 textBox2.MaxLength = 0;
  55.                 textBox2.Text = "";
  56.                 searchFor = true;
  57.             }
  58.         }
  59.  
  60.         private void button2_Click(object sender, EventArgs e)
  61.         {
  62.             string splitterString = splitBox.Text;
  63.             char splitter = Convert.ToChar(splitterBox.Text);
  64.             string[] splittedStrings = splitterString.Split(splitter);
  65.             for(int i = 0; i < splittedStrings.Length; i++)
  66.             {
  67.                 richTextBox1.AppendText(splittedStrings[i]);
  68.                 richTextBox1.AppendText("\n");
  69.             }
  70.         }
  71.  
  72.         private void button3_Click(object sender, EventArgs e)
  73.         {
  74.             string trimmerString = stringTrim.Text;
  75.             char[] remove = new char[] { 'a', 'e', 'i', 'u' };
  76.             trimmerString = trimmerString.Trim(remove);
  77.             richTextBox2.AppendText(trimmerString.Trim(remove));
  78.  
  79.         }
  80.  
  81.         private void button4_Click(object sender, EventArgs e)
  82.         {
  83.             string p = precodeString.Text;
  84.             int s = Convert.ToInt32(cipherShiftBox.Text);
  85.             encodeStringBox.Text = encodeString(p, s);
  86.         }
  87.  
  88.         private string encodeString(string s, int shift)
  89.         {
  90.             s = s.ToLower();
  91.             string res = null;
  92.             char[] code = s.ToCharArray();
  93.             for(int i = 0; i < code.Length; i++)
  94.             {
  95.                 int a = code[i];
  96.                 if(code[i] >= 'a' && code[i] <= 'z')
  97.                 {
  98.                     a += shift;
  99.                     if(a > 'z')
  100.                     {
  101.                         a -= 26;
  102.  
  103.                     }
  104.                     if(a < 'a')
  105.                     {
  106.                         a += 26;
  107.                     }
  108.                 }
  109.                 code[i] = (char)a;
  110.                 res += code[i];
  111.             }
  112.             return res;
  113.         }
  114.  
  115.         private string decodeString(string s, int shift)
  116.         {
  117.             s = s.ToLower();
  118.             string res = null;
  119.             char[] code = s.ToCharArray();
  120.             for (int i = 0; i < code.Length; i++)
  121.             {
  122.                 int a = code[i];
  123.                 if (code[i] >= 'a' && code[i] <= 'z')
  124.                 {
  125.                     a -= shift;
  126.                     if (a > 'z')
  127.                     {
  128.                         a -= 26;
  129.  
  130.                     }
  131.                     if (a < 'a')
  132.                     {
  133.                         a += 26;
  134.                     }
  135.                 }
  136.                 code[i] = (char)a;
  137.                 res += code[i];
  138.             }
  139.             return res;
  140.         }
  141.  
  142.         private void decodeButton_Click(object sender, EventArgs e)
  143.         {
  144.             string p = ripcodeString.Text;
  145.             int s = Convert.ToInt32(decipherShiftBox.Text);
  146.             decodedString.Text = decodeString(p, s);
  147.         }
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement