Advertisement
le_lukasz

Untitled

Apr 22nd, 2020
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  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 szyfrator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         string SzyfrCezara(string tekst, int przesuniecie)
  20.         {
  21.             char[] bufor = tekst.ToCharArray();
  22.  
  23.             for(int i=0; i< bufor.Length; i++)
  24.             {
  25.                 char litera = bufor[i];
  26.  
  27.                 if (litera ==' '||litera == '.' || litera == ',')
  28.                 {
  29.                     continue;
  30.                 }
  31.                
  32.                 if('A'<= litera && litera <= 'Z')
  33.                 {
  34.                     litera = (char)(litera + przesuniecie);
  35.                     if(litera > 'Z')
  36.                     {
  37.                         litera = (char)(litera - 26);
  38.                     }
  39.                     else if (litera < 'A')
  40.                     {
  41.                         litera = (char)(litera + 26);
  42.                     }
  43.                 }
  44.                 else
  45.                 {
  46.                     litera = (char)(litera + przesuniecie);
  47.                     if (litera > 'z')
  48.                     {
  49.                         litera = (char)(litera - 26);
  50.                     }
  51.                     else if (litera < 'a')
  52.                     {
  53.                         litera = (char)(litera + 26);
  54.                     }
  55.                 }
  56.                 bufor[i] = litera;
  57.             }
  58.             return new string(bufor);
  59.         }
  60.         private void BtnKoduj_Click(object sender, EventArgs e)
  61.         {
  62.             string tekstDoZakodowania = txtDoZakodowania.Text;
  63.             int przesuniecie = (int)numPrzesuniecie.Value;
  64.             string tekstZakodowany = SzyfrCezara(tekstDoZakodowania, przesuniecie);
  65.  
  66.             txtZakdowany.Text = tekstZakodowany;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement