Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. StringBuilder text = new StringBuilder(textBox2.Text);
  4. progressBar1.Maximum = text.Length;
  5. progressBar1.Value = 0;
  6. string key = textBox3.Text.ToUpper();
  7. int j = 0;
  8.  
  9. for (int i = 0; i < text.Length; i++)
  10. {
  11. int newCode = text[i] + (key[j] - 64);
  12.  
  13. if(char.IsUpper(text[i]) && newCode > 90)
  14. {
  15. text[i] = (char)(64 + newCode - 90);
  16. }
  17. if(char.IsLower(text[i]) && newCode > 122)
  18. {
  19. text[i] = (char)(96 + newCode - 122);
  20. }
  21. else
  22. {
  23. text[i] = (char)newCode;
  24. }
  25.  
  26. if (j == key.Length - 1)
  27. j = 0;
  28. else
  29. j++;
  30.  
  31. progressBar1.Value++;
  32. }
  33.  
  34. textBox1.Text = text.ToString();
  35. }
  36.  
  37. private void button2_Click(object sender, EventArgs e)
  38. {
  39. StringBuilder text = new StringBuilder(textBox2.Text);
  40. progressBar1.Maximum = text.Length;
  41. progressBar1.Value = 0;
  42. string key = textBox3.Text.ToUpper();
  43. int j = 0;
  44.  
  45. for (int i = 0; i < text.Length; i++)
  46. {
  47. int newCode = text[i] - (key[j] - 64);
  48.  
  49. if (char.IsUpper(text[i]) && newCode < 65)
  50. {
  51. text[i] = (char)(91 - (65 - newCode));
  52. }
  53. if (char.IsLower(text[i]) && newCode < 97)
  54. {
  55. text[i] = (char)(123- ( 97- newCode));
  56. }
  57. else
  58. {
  59. text[i] = (char)newCode;
  60. }
  61.  
  62. if (j == key.Length - 1)
  63. j = 0;
  64. else
  65. j++;
  66.  
  67. progressBar1.Value++;
  68. }
  69.  
  70. textBox1.Text = text.ToString();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement