Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApplication1
- {
- public class Rot13
- {
- private String tekst;
- public Rot13(String inTekst)
- {
- this.tekst = inTekst;
- this.tekst = this.tekst.ToLower();
- }
- public void szyfr()
- {
- char[] tmp = tekst.ToCharArray();
- int tmpi;
- int tmpa;
- for(int i=0;i<this.tekst.Length;i++)
- {
- if (Convert.ToInt32(tmp[i]) > 96 && Convert.ToInt32(tmp[i]) < 124)
- {
- tmpi = Convert.ToInt32(tmp[i]);
- tmpi = tmpi + 13;
- if (tmpi > 122)
- {
- tmpa = tmpi - 123;
- tmpi = 97 + tmpa;
- }
- tmp[i] =Convert.ToChar(tmpi);
- }
- }
- Console.Out.Write("Zaszyfrowany tekst to ");
- for (int i = 0; i < tmp.Length; i++) Console.Out.Write(tmp[i]);
- Console.Out.Write("\n");
- }
- public void deszyfr()
- {
- char[] tmp = tekst.ToCharArray();
- int tmpi;
- int tmpa;
- for (int i = 0; i < this.tekst.Length; i++)
- {
- if (Convert.ToInt32(tmp[i]) > 96 && Convert.ToInt32(tmp[i]) < 124)
- {
- tmpi = Convert.ToInt32(tmp[i]);
- tmpi = tmpi - 13;
- if (tmpi < 97)
- {
- tmpa = 97 - tmpi;
- tmpi = 123 - tmpa;
- }
- tmp[i] = Convert.ToChar(tmpi);
- }
- }
- Console.Out.Write("Odszyfrowany tekst to ");
- for (int i = 0; i < tmp.Length; i++) Console.Out.Write(tmp[i]);
- Console.Out.Write("\n");
- }
- }
- public class Cezar
- {
- private String tekst;
- public Cezar(String inTekst)
- {
- this.tekst = inTekst;
- this.tekst = this.tekst.ToLower();
- }
- public void szyfr()
- {
- char[] tmp = tekst.ToCharArray();
- int tmpi;
- int tmpa;
- for (int i = 0; i < this.tekst.Length; i++)
- {
- if (Convert.ToInt32(tmp[i]) > 96 && Convert.ToInt32(tmp[i]) < 124)
- {
- tmpi = Convert.ToInt32(tmp[i]);
- tmpi = tmpi + 3;
- if (tmpi > 122)
- {
- tmpa = tmpi - 123;
- tmpi = 97 + tmpa;
- }
- tmp[i] = Convert.ToChar(tmpi);
- }
- }
- Console.Out.Write("Zaszyfrowany tekst to ");
- for (int i = 0; i < tmp.Length; i++) Console.Out.Write(tmp[i]);
- Console.Out.Write("\n");
- }
- public void deszyfr()
- {
- char[] tmp = tekst.ToCharArray();
- int tmpi;
- int tmpa;
- for (int i = 0; i < this.tekst.Length; i++)
- {
- if (Convert.ToInt32(tmp[i]) > 96 && Convert.ToInt32(tmp[i]) < 124)
- {
- tmpi = Convert.ToInt32(tmp[i]);
- tmpi = tmpi - 3;
- if (tmpi < 97)
- {
- tmpa = 97 - tmpi;
- tmpi = 123 - tmpa;
- }
- tmp[i] = Convert.ToChar(tmpi);
- }
- }
- Console.Out.Write("Odszyfrowany tekst to ");
- for (int i = 0; i < tmp.Length; i++) Console.Out.Write(tmp[i]);
- Console.Out.Write("\n");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.Out.WriteLine("Podaj tekst");
- String tekst = Console.In.ReadLine();
- Console.Out.WriteLine("Podaj metode szyfrowania (1. ROT13, 2. Szyfr Cezara");
- String c="";
- //String c2="";
- while (c != "q")
- {
- c = Console.In.ReadLine();
- if (c == "1")
- {
- Console.Out.WriteLine("Podaj operacje (1. Szyfrowanie, 2. Deszyfrowanie");
- c = Console.In.ReadLine();
- if (c == "1")
- {
- new Rot13(tekst).szyfr();
- }
- if (c == "2")
- {
- new Rot13(tekst).deszyfr();
- }
- }
- if (c == "2")
- {
- Console.Out.WriteLine("Podaj operacje (1. Szyfrowanie, 2. Deszyfrowanie");
- c = Console.In.ReadLine();
- if (c == "1")
- {
- new Cezar(tekst).szyfr();
- }
- if (c == "2")
- {
- new Cezar(tekst).deszyfr();
- }
- }
- Console.Out.WriteLine("Wpisz q aby zakonczyc...");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment