Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace SzyfryHomofoniczne
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. String haslo = textBox1.Text;
  23. haslo = haslo.ToUpper();
  24. ArrayList al = new ArrayList();
  25. String hasloZaszyfrowane = "";
  26. Char[,] tablicaHomofonow = new char[26, 3];
  27. Char[] tablicaLiter = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
  28. Random r = new Random(11352233);
  29. Random r2 = new Random();
  30. int random;
  31. for (int i = 0; i < 26; i++)
  32. {
  33. for (int j = 0; j < 3; j++)
  34. {
  35. random = r.Next(33, 126);
  36. while (al.Contains(random))
  37. {
  38. random = r.Next(33, 126);
  39. }
  40. tablicaHomofonow[i, j] = (char)random;
  41. al.Add(random);
  42. Console.Write(tablicaHomofonow[i,j]);
  43. }
  44. Console.WriteLine("");
  45. }
  46.  
  47.  
  48. // Console.WriteLine(al);
  49.  
  50.  
  51. for (int i = 0; i < haslo.Length; i++)
  52. {
  53. for(int j = 0; j < 26; j++)
  54. {
  55. if (haslo[i] == tablicaLiter[j])
  56. {
  57. hasloZaszyfrowane += tablicaHomofonow[j,r2.Next(3)];
  58. }
  59. }
  60.  
  61. }
  62. label1.Text = hasloZaszyfrowane;
  63. }
  64.  
  65. private void button2_Click(object sender, EventArgs e)
  66. {
  67. String haslo = label1.Text;
  68. ArrayList al = new ArrayList();
  69. String hasloOdszyfrowane = "";
  70. Char[,] tablicaHomofonow = new char[26, 3];
  71. Char[] tablicaLiter = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
  72. Random r = new Random(11352233);
  73. Random r2 = new Random();
  74. int random;
  75. for (int i = 0; i < 26; i++)
  76. {
  77. for (int j = 0; j < 3; j++)
  78. {
  79. random = r.Next(33, 126);
  80. while (al.Contains(random))
  81. {
  82. random = r.Next(33, 126);
  83. }
  84. tablicaHomofonow[i, j] = (char)random;
  85. al.Add(random);
  86. Console.Write(tablicaHomofonow[i, j]);
  87. }
  88. Console.WriteLine("");
  89. }
  90. for (int i = 0; i < haslo.Length; i++)
  91. {
  92. for (int j = 0; j < 26; j++)
  93. {
  94. for (int k = 0; k < 3; k++)
  95. {
  96. if (haslo[i] == tablicaHomofonow[j,k])
  97. {
  98. hasloOdszyfrowane += tablicaLiter[j];
  99. }
  100. }
  101. }
  102.  
  103. }
  104. label2.Text = hasloOdszyfrowane;
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement