- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Caeser_method
{
class Program
{
static void Main(string[] args)
{
int n = 3;
Console.Write("Input string to encoding: ");
string input = Console.ReadLine();
Csr enc = new Csr(n,input);
// Csr dec;
enc.encrypt();
Console.WriteLine(enc);
// dec = new Csr(n, input);
enc.decrypt();
Console.WriteLine(enc);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Caeser_method
{
class Csr
{
public int n;
public string phraze,outputphr;
public Csr(int n, string phraze)
{
this.n = n;
this.phraze = phraze;
this.outputphr = "";
}
public void encrypt()
{
foreach (char c in this.phraze)
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
{
if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
(c + this.n > 'Z' ? ('A' + ((c -'Z' + (this.n - 1)))) : (c + this.n)) :
(c + this.n > 'z' ? ('a' + ((c - 'z' + (this.n - 1)))) : (c + this.n)));
else this.outputphr += c;
}
else
{
if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
(c + this.n > 'Я' ? ('А' + ((c - 'Я' + (this.n - 1)))) : (c + this.n)) :
(c + this.n > 'я' ? ('а' + ((c - 'я' + (this.n - 1)))) : (c + this.n)));
else this.outputphr += c;
}
}
public void decrypt()
{
this.phraze = this.outputphr;
this.outputphr = "";
foreach (char c in this.phraze)
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
{
if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
(c - this.n < 'A' ? ('Z' - (('A' - c + (this.n - 1)))) : (c - this.n)) :
(c - this.n < 'a' ? ('z' - (('a' - c + (this.n - 1)))) : (c - this.n)));
else this.outputphr += c;
}
else
{
if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
(c - this.n < 'А' ? ('Я' - (('А' - c + (this.n - 1)))) : (c - this.n)) :
(c - this.n < 'а' ? ('я' - (('а' - c + (this.n - 1)))) : (c - this.n)));
else this.outputphr += c;
}
}
public override string ToString()
{
return string.Format("Encoded string: {0}",this.outputphr);
}
}
}
body90 28.03.2011 01:00 # +1
bugmenot 28.03.2011 01:11 # −1
abatishchev 28.03.2011 09:09 # +2
abatishchev 28.03.2011 09:10 # −4
abatishchev 28.03.2011 09:10 # 0
tr00_gr1m_doomster 28.03.2011 11:01 # +1
bugmenot 28.03.2011 12:50 # 0
Lure Of Chaos 28.03.2011 15:23 # 0
bugmenot 28.03.2011 12:55 # 0
Lure Of Chaos 28.03.2011 15:23 # +3
absolut 28.03.2011 16:11 # +2
da4ever 29.03.2011 05:05 # 0
и я опять понл зачем нужен линку!
Lure Of Chaos 29.03.2011 23:40 # 0
линку не надо, копирасты рядом
da4ever 30.03.2011 01:25 # 0