Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace RandomShift {
- public partial class Form1 : Form {
- private int przesuniecie = 2;
- public Form1() {
- InitializeComponent();
- }
- //szyfruj
- private void button1_Click(object sender, EventArgs e) {
- TextBox tekstJawnyTB = (TextBox) tbTekstJawny;
- string tekst_jawny = tekstJawnyTB.Text;
- TextBox szyfrogramTB = (TextBox) tbSzyfrogram;
- string szyfrogram = "";
- TextBox kluczTB = (TextBox) tbKlucz;
- int klucz = Int32.Parse(kluczTB.Text);
- foreach (char c in tekst_jawny) {
- if (Char.IsLetter(c)) {
- int code = (int) c;
- int newCode = code - 65 + klucz;
- newCode = newCode % 26;
- newCode += 65;
- if (newCode < 65) {
- newCode += 26;
- } else if (newCode > 90) {
- newCode -= 26;
- }
- char newLetter = (char) newCode;
- szyfrogram += newLetter.ToString();
- klucz += przesuniecie;
- }
- }
- szyfrogramTB.Text = szyfrogram;
- }
- //odszyfruj
- private void button2_Click(object sender, EventArgs e) {
- TextBox szyfrogramTB = (TextBox) tbSzyfrogram;
- string szyfrogram = szyfrogramTB.Text;
- TextBox odszyfrowanyTB = (TextBox) tbOdszyfrowany;
- string odszyfrowany = "";
- TextBox kluczTB = (TextBox) tbKlucz;
- int klucz = Int32.Parse(kluczTB.Text);
- foreach (char c in szyfrogram) {
- if (Char.IsLetter(c)) {
- int code = (int)c;
- int newCode = 0;
- newCode = code - 65 - klucz;
- newCode = newCode % 26;
- newCode += 65;
- if (newCode < 65) {
- newCode += 26;
- } else if (newCode > 90) {
- newCode -= 26;
- }
- char newLetter = (char) newCode;
- odszyfrowany += newLetter.ToString();
- klucz += przesuniecie;
- }
- }
- odszyfrowanyTB.Text = odszyfrowany;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement