Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Zadanie2b
- private void szyfrowanie2b_Click(object sender, RoutedEventArgs e)
- {
- char[] alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- string wynik = null;
- char[] key = text2bklucz.Text.ToCharArray();
- int[] kluczglowny = new int[key.Length];
- // int[] keytable = new int[key.Length];
- string haslo = text2bhaslo.Text;
- char[] temp = haslo.ToCharArray();
- int pozycja = 0;
- //tworzenia klucza jak w 2a
- for (int i = 0; i < alfabet.Length; i++)
- {
- for (int j = 0; j < key.Length; j++)
- {
- if (alfabet[i] == key[j])
- {
- kluczglowny[j] = pozycja;
- pozycja++;
- }
- }
- }
- finalkey = kluczglowny;
- //kodowanko
- char[] encodeslowo = new char[haslo.Length];
- int[] pointers = (int[])kluczglowny.Clone();
- int mainPointer = 0;
- for (int j = 0; j < pointers.Length; j++)
- {
- while (pointers[j] < haslo.Length)
- {
- encodeslowo[mainPointer++] = haslo[pointers[j]];
- pointers[j] += pointers.Length;
- }
- }
- foreach (var item in encodeslowo)
- {
- wynik += item;
- }
- text2bzaszyfrowane.Text = wynik;
- }
- private void Odszyfrowanie2b_Click(object sender, RoutedEventArgs e)
- {
- char[] alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- string wynik = null;
- char[] key = text2bklucz.Text.ToCharArray();
- int[] kluczglowny = new int[key.Length];
- // int[] keytable = new int[key.Length];
- string haslo = text2bhaslodoodszyfrowania.Text;
- char[] temp = haslo.ToCharArray();
- int pozycja = 0;
- //tworzenia klucza jak w 2a
- // kodowanko :D
- char[] decodedWord = new char[haslo.Length];
- int[] pointers = (int[])finalkey.Clone();
- int mainPointer = 0;
- for (int j = 0; j < pointers.Length; j++)
- {
- while (pointers[j] < haslo.Length)
- {
- decodedWord[pointers[j]] = haslo[mainPointer++];
- pointers[j] += pointers.Length;
- }
- }
- foreach (var item in decodedWord)
- {
- wynik += item;
- }
- text2bpoodszyfrowaniu.Text = wynik;
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement