Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #region Zadanie2b
  2.  
  3. private void szyfrowanie2b_Click(object sender, RoutedEventArgs e)
  4. {
  5. char[] alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  6. string wynik = null;
  7. char[] key = text2bklucz.Text.ToCharArray();
  8. int[] kluczglowny = new int[key.Length];
  9. // int[] keytable = new int[key.Length];
  10. string haslo = text2bhaslo.Text;
  11. char[] temp = haslo.ToCharArray();
  12. int pozycja = 0;
  13.  
  14. //tworzenia klucza jak w 2a
  15. for (int i = 0; i < alfabet.Length; i++)
  16. {
  17. for (int j = 0; j < key.Length; j++)
  18. {
  19. if (alfabet[i] == key[j])
  20. {
  21. kluczglowny[j] = pozycja;
  22. pozycja++;
  23. }
  24.  
  25. }
  26. }
  27. finalkey = kluczglowny;
  28. //kodowanko
  29. char[] encodeslowo = new char[haslo.Length];
  30. int[] pointers = (int[])kluczglowny.Clone();
  31.  
  32. int mainPointer = 0;
  33.  
  34. for (int j = 0; j < pointers.Length; j++)
  35. {
  36. while (pointers[j] < haslo.Length)
  37. {
  38. encodeslowo[mainPointer++] = haslo[pointers[j]];
  39. pointers[j] += pointers.Length;
  40. }
  41. }
  42.  
  43.  
  44.  
  45. foreach (var item in encodeslowo)
  46. {
  47. wynik += item;
  48. }
  49.  
  50.  
  51.  
  52. text2bzaszyfrowane.Text = wynik;
  53.  
  54. }
  55. private void Odszyfrowanie2b_Click(object sender, RoutedEventArgs e)
  56. {
  57. char[] alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  58. string wynik = null;
  59. char[] key = text2bklucz.Text.ToCharArray();
  60. int[] kluczglowny = new int[key.Length];
  61. // int[] keytable = new int[key.Length];
  62. string haslo = text2bhaslodoodszyfrowania.Text;
  63. char[] temp = haslo.ToCharArray();
  64. int pozycja = 0;
  65.  
  66. //tworzenia klucza jak w 2a
  67.  
  68. // kodowanko :D
  69.  
  70. char[] decodedWord = new char[haslo.Length];
  71.  
  72. int[] pointers = (int[])finalkey.Clone();
  73.  
  74. int mainPointer = 0;
  75.  
  76. for (int j = 0; j < pointers.Length; j++)
  77. {
  78. while (pointers[j] < haslo.Length)
  79. {
  80.  
  81. decodedWord[pointers[j]] = haslo[mainPointer++];
  82. pointers[j] += pointers.Length;
  83. }
  84.  
  85. }
  86. foreach (var item in decodedWord)
  87. {
  88. wynik += item;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. text2bpoodszyfrowaniu.Text = wynik;
  95. }
  96.  
  97. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement