Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Win32;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace szyfrcezara
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- Queue arrayToCode = new Queue();
- char[] abecadlo = { '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'};
- int klucz = 3;
- private void wczytaj_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog dialog = new OpenFileDialog();
- if (dialog.ShowDialog() == true)
- {
- input.Text = File.ReadAllText(dialog.FileName);
- }
- }
- private void zapisz_Click(object sender, RoutedEventArgs e)
- {
- string fileText = input.Text;
- SaveFileDialog dialog = new SaveFileDialog()
- {
- Filter = "Text Files(*.txt)|*.txt|All(*.*)|*"
- };
- if (dialog.ShowDialog() == true)
- {
- File.WriteAllText(dialog.FileName, fileText);
- }
- }
- private void zakoduj_Click(object sender, RoutedEventArgs e)
- {
- output.Text = "";
- string codedString = "";
- foreach (char letter in input.Text.ToUpper())
- {
- if(letter != ' ')
- {
- arrayToCode.Enqueue(letter);
- }
- }
- foreach (char letter in arrayToCode)
- {
- //output.Text += Array.IndexOf(abecadlo, letter);
- int x = Array.IndexOf(abecadlo, letter);
- if (letter != '_')
- {
- if (x <= 25 - klucz)
- {
- codedString += abecadlo[x + klucz];
- }
- else
- {
- codedString += abecadlo[(x + 3) % 26];
- }
- }
- else
- {
- codedString += "_";
- }
- }
- output.Text = codedString;
- arrayToCode.Clear();
- }
- private void dekoduj_Click(object sender, RoutedEventArgs e)
- {
- output.Text = "";
- string decodedString = "";
- foreach (char letter in input.Text.ToUpper())
- {
- if (letter != ' ')
- {
- arrayToCode.Enqueue(letter);
- }
- }
- foreach (char letter in arrayToCode)
- {
- //output.Text += Array.IndexOf(abecadlo, letter);
- int x = Array.IndexOf(abecadlo, letter);
- if (x != '_')
- {
- if (x >= klucz)
- {
- decodedString += abecadlo[x - klucz];
- }
- else
- {
- decodedString += abecadlo[x+23];
- }
- }
- else
- {
- decodedString += "_";
- }
- }
- output.Text = decodedString;
- arrayToCode.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement