Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 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.Collections;
  11.  
  12. namespace Szyfr_homofoniczny
  13. {
  14. public partial class Form1 : Form
  15. {
  16. String wordToEncrypt;
  17. String encryptedWord;
  18. String wordToDecrypt;
  19.  
  20. ArrayList alphabet = new ArrayList();
  21. ArrayList ASCII = new ArrayList();
  22.  
  23. Char[,] homophones = new Char[26, 3];
  24.  
  25. Random random = new Random(420);
  26. Random random2 = new Random();
  27.  
  28. char randomASCII;
  29. char randomASCII2;
  30.  
  31. public Form1()
  32. {
  33. InitializeComponent();
  34. }
  35.  
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38. wordToEncrypt = textBox1.Text;
  39. encryptedWord = "";
  40. alphabet.Clear();
  41. ASCII.Clear();
  42. textBox3.Clear();
  43.  
  44. for (char letter='A'; letter<='Z'; letter++)
  45. {
  46. alphabet.Add(letter);
  47. }
  48.  
  49. for (int code=33; code<127; code++)
  50. {
  51. ASCII.Add((char)(code));
  52. }
  53.  
  54. for (int i=0; i<alphabet.Count; i++)
  55. {
  56. for (int j=0; j<3; j++)
  57. {
  58. randomASCII = (char)random.Next(0, ASCII.Count);
  59.  
  60. homophones[i, j] = (char)ASCII[randomASCII];
  61.  
  62. ASCII.RemoveAt(randomASCII);
  63. }
  64. }
  65.  
  66. for (int i=0; i<wordToEncrypt.Length; i++)
  67. {
  68. randomASCII2 = (char)random2.Next(0, 3);
  69. encryptedWord += homophones[alphabet.IndexOf((char)wordToEncrypt[i]), randomASCII2];
  70. }
  71.  
  72. textBox2.Text = encryptedWord;
  73. }
  74.  
  75. private void button2_Click(object sender, EventArgs e)
  76. {
  77. wordToDecrypt = textBox2.Text;
  78. textBox3.Clear();
  79.  
  80. for (int i=0; i<wordToDecrypt.Length; i++)
  81. {
  82. for (int j=0; j<alphabet.Count; j++)
  83. {
  84. for (int k=0; k<3; k++)
  85. {
  86. if ((char)wordToDecrypt[i] == (char)homophones[j, k])
  87. {
  88. textBox3.Text += alphabet[j];
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement