Last active
October 3, 2016 18:34
-
-
Save dz0/cb7e9837669baf256758665019144825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| 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 WpfApplication1_sifravimas | |
| { | |
| /// <summary> | |
| /// Interaction logic for MainWindow.xaml | |
| /// </summary> | |
| public partial class MainWindow : Window | |
| { | |
| public MainWindow() | |
| { | |
| InitializeComponent(); | |
| } | |
| string sifruok(string txt, int k = 1) | |
| // https://en.wikipedia.org/wiki/Caesar_cipher | |
| // k - per kiek vietu pastumti simboli ASCII lenteleje | |
| // http://www.asciitable.com/index/asciifull.gif | |
| { | |
| string rez = ""; | |
| foreach (char simb in txt) // su kiekvienu simboliu is teksto | |
| { | |
| int nr = (int)simb; // paverciame simboli i skaiciuka (jo numeri ASCII lentelej) | |
| // Kodavimo "burtai" | |
| // rez += (char)(nr + k); // pastumiam numeri, paverciam atgal i simboli, ir pridedam prie rezultato | |
| int naujas_nr = nr + k; // pastumiam numeri | |
| char naujas_simbolis = (char)naujas_nr; // paverciam atgal i simboli | |
| rez += naujas_simbolis; // ir pridedam prie rezultato | |
| Console.WriteLine(simb + " --> " + (char)(nr + k)); | |
| } | |
| return rez; | |
| } | |
| private void button_Click(object sender, RoutedEventArgs e) | |
| { | |
| textBox.Text = sifruok(textBox.Text); // uzsifruojam | |
| } | |
| private void button1_Click(object sender, RoutedEventArgs e) | |
| { | |
| textBox.Text = sifruok(textBox.Text, -1); // atsifruojam | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment