Witam!
Mam taki temat : zrobić kodowanie xor oraz rot13 plus do tego dodać trzeci dowolny rodzaj kodowania oraz możliwość odczytu pliku txt który po zakodowaniu zostanie zapisany z podobną nazwa...
może ktoś pomódz w temacie?
tyle mam już zrobione :
(xor i rot13)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace kodowanie
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string input;
string output = "";
string kodowanie = "";
string klucz;
System.Console.WriteLine("Wybierz metody szyfrowania");
System.Console.WriteLine("1. ROT13");
System.Console.WriteLine("2. XOR");
kodowanie = System.Console.ReadLine();
System.Console.WriteLine("wprowadz tekst");
input = System.Console.ReadLine(); //sprawdzic czy wprowadzono text
Koder koder = new Koder();
switch (kodowanie)
{
case "1":
output = koder.rot13(input);
break;
case "2":
System.Console.WriteLine("Wprowadz klucz");
klucz = System.Console.ReadLine(); //sprawdzic czy wprowadzono klucz
output = koder.XOR(input, klucz);
break;
default:
System.Console.WriteLine("wprowadzono zle dane");
break;
}
System.Console.WriteLine("Tekst po zakodowaniu : \n{0}",
output);
System.Console.ReadKey();
}
}
public class Koder
{
public string rot13(string tekst)
{
if (tekst == "") return tekst;
else
{
char x;
string wynik = "";
for (int i = 0; i < tekst.Length; i++)
{
if ((Convert.ToInt16(tekst[i]) >= 65) &&
(Convert.ToInt16(tekst[i]) <= 91))
{
x = Convert.ToChar(Convert.ToInt16(tekst[i]) +
13);
System.Console.WriteLine("x = " + x + " : " +
Convert.ToInt16(x));
if (Convert.ToInt16(x) >= 91) x =
Convert.ToChar(Convert.ToInt16(tekst[i]) - 13);
System.Console.WriteLine("x = " + x + " : " +
Convert.ToInt16(x));
}
else
{
if (((int)tekst[i] >= 97) && ((int)tekst[i] <
123))
{
x = Convert.ToChar((int)tekst[i] + 13);
if ((int)x >= 123) x = (char)((int)tekst[i] -
13);
}
else { x = tekst[i]; }
}
wynik += Convert.ToString(x);
}
return wynik;
}
}
public string XOR(string tekst, string klucz)
{
return tekst;
}
}
}