Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace SzyfryHomofoniczne
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String haslo = textBox1.Text;
- haslo = haslo.ToUpper();
- ArrayList al = new ArrayList();
- String hasloZaszyfrowane = "";
- Char[,] tablicaHomofonow = new char[26, 3];
- 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' };
- Random r = new Random(11352233);
- Random r2 = new Random();
- int random;
- for (int i = 0; i < 26; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- random = r.Next(33, 126);
- while (al.Contains(random))
- {
- random = r.Next(33, 126);
- }
- tablicaHomofonow[i, j] = (char)random;
- al.Add(random);
- Console.Write(tablicaHomofonow[i,j]);
- }
- Console.WriteLine("");
- }
- // Console.WriteLine(al);
- for (int i = 0; i < haslo.Length; i++)
- {
- for(int j = 0; j < 26; j++)
- {
- if (haslo[i] == tablicaLiter[j])
- {
- hasloZaszyfrowane += tablicaHomofonow[j,r2.Next(3)];
- }
- }
- }
- label1.Text = hasloZaszyfrowane;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- String haslo = label1.Text;
- ArrayList al = new ArrayList();
- String hasloOdszyfrowane = "";
- Char[,] tablicaHomofonow = new char[26, 3];
- 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' };
- Random r = new Random(11352233);
- Random r2 = new Random();
- int random;
- for (int i = 0; i < 26; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- random = r.Next(33, 126);
- while (al.Contains(random))
- {
- random = r.Next(33, 126);
- }
- tablicaHomofonow[i, j] = (char)random;
- al.Add(random);
- Console.Write(tablicaHomofonow[i, j]);
- }
- Console.WriteLine("");
- }
- for (int i = 0; i < haslo.Length; i++)
- {
- for (int j = 0; j < 26; j++)
- {
- for (int k = 0; k < 3; k++)
- {
- if (haslo[i] == tablicaHomofonow[j,k])
- {
- hasloOdszyfrowane += tablicaLiter[j];
- }
- }
- }
- }
- label2.Text = hasloOdszyfrowane;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement