Facebook
From Giganci Programowania, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace SzyfrCezara
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         static string szyfrCezar(string tekst, int przesuniecie) {
  21.             char[] bufor = tekst.ToArray();
  22.             for (int i = 0; i < bufor.Length; i++) {
  23.                 char litera = bufor[i];
  24.                 if (litera == ' ' || litera == '.' || litera == ',') {
  25.                     continue;
  26.                 }
  27.                 if ('A' <= litera && litera <= 'Z')
  28.                 {
  29.                     litera = (char)(litera + przesuniecie);
  30.                     if (litera > 'Z')
  31.                     {
  32.                         litera = (char)(litera - 26);
  33.                     }
  34.                     else if (litera < 'A')
  35.                     {
  36.                         litera = (char)(litera + 26);
  37.                     }
  38.                 }
  39.                 else {
  40.                     litera = (char)(litera + przesuniecie);
  41.                     if (litera > 'z')
  42.                     {
  43.                         litera = (char)(litera - 26);
  44.                     }
  45.                     else if (litera < 'a')
  46.                     {
  47.                         litera = (char)(litera + 26);
  48.                     }
  49.                 }
  50.                 bufor[i] = litera;
  51.             }
  52.             return new string(bufor);
  53.         }
  54.  
  55.         private void btnKoduj_Click(object sender, EventArgs e)
  56.         {
  57.             string tekst_do_zakodowania = txtDoZakodowania.Text;
  58.             int przesuniecie = (int)NumPrzesuniecie.Value;
  59.             txtZakodowany.Text = szyfrCezar(tekst_do_zakodowania, przesuniecie);
  60.         }
  61.     }
  62. }
  63.