// C# 7.3
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace Rextester
{
public class Program
public static void Main(string[] args)
var crypted = "";
for (int i = 0; i < CaesarCipher.Ru.Length; i++)
Console.WriteLine(CaesarCipher.Decode(i, crypted));
}
class CaesarCipher
public static readonly string Ru = "";
public static readonly string RuD = "";
private static readonly int defaultStep = 3;
public static CaesarEncrypted Encode(int step, string source, Func<string, string> translate)
string translatedData = translate(source);
var stringBuilder = new StringBuilder();
foreach (char c in translatedData.ToLower())
stringBuilder.Append(RuD[Ru.IndexOf(c) + step]);
return new CaesarEncrypted(step, stringBuilder.ToString());
public static CaesarEncrypted Encode(int step, string source)
return Encode(step, source, x => x);
public static string Decode(CaesarEncrypted source)
var step = source.Step;
return Encode(-step + Ru.Length, source.ToString(), x => x);
public static string Decode(int step, string source)
return Encode(-step + Ru.Length, source, x => x);
class CaesarEncrypted : IEnumerable, IEnumerable<char>
public int Step { get; set; }
public string Data { get; set; }
public CaesarEncrypted(int step, string initData)
Step = step;
Data = initData;
public CaesarEncrypted(string initData) : this(int.MaxValue, initData)
{}
public IEnumerator<char> GetEnumerator()
foreach (char c in Data)
yield return c;
IEnumerator IEnumerable.GetEnumerator() => (IEnumerator<char>)GetEnumerator();
public override string ToString() => Data;
public static implicit operator string(CaesarEncrypted source) => source.ToString();
Объяснение:
1. Пронумеруем разряды:
3-й разряд - 4;
2-й разряд - 1;
1-й разряд - 5;
0-й разряд - 3.
4153₈=4·8³+1·8²+5·8¹+3·8⁰
2. 4153₈=4·8³+1·8²+5·8¹+3·8⁰=2048+16+40+3=2155₁₀
3. 125/8=15 (5)
15/8=1 (7)
(1)
125₁₀=175₈
4. Пронумеруем разряды:
2-й разряд - A;
1-й разряд - 6;
0-й разряд - E;
A6E₁₆=(10)(6)(14)=10·16²+6·16¹+14·16⁰
5. A6E₁₆=10·16²+6·16¹+14·16⁰=2560+96+14=2670₁₀
6. 350/16=21 (14=E)
21/16=1 (5)
350₁₀=15E₁₆
7. 247/2=123 (1)
123/2=61 (1)
61/2=30 (1)
30/2=15 (0)
15/2=7 (1)
7/2=3 (1)
3/2=1 (1)
247₁₀=11110111₂
247/8=30 (7)
30/8=3 (6)
(3)
247₁₀=367₈
247/16=7 (15=F)
(7)
247₁₀=7F₁₆
Получившиеся числа между собой равны, так как имеют одинаковое число в десятичной системе счисления.
// C# 7.3
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
var crypted = "";
for (int i = 0; i < CaesarCipher.Ru.Length; i++)
Console.WriteLine(CaesarCipher.Decode(i, crypted));
}
}
class CaesarCipher
{
public static readonly string Ru = "";
public static readonly string RuD = "";
private static readonly int defaultStep = 3;
public static CaesarEncrypted Encode(int step, string source, Func<string, string> translate)
{
string translatedData = translate(source);
var stringBuilder = new StringBuilder();
foreach (char c in translatedData.ToLower())
{
stringBuilder.Append(RuD[Ru.IndexOf(c) + step]);
}
return new CaesarEncrypted(step, stringBuilder.ToString());
}
public static CaesarEncrypted Encode(int step, string source)
{
return Encode(step, source, x => x);
}
public static string Decode(CaesarEncrypted source)
{
var step = source.Step;
return Encode(-step + Ru.Length, source.ToString(), x => x);
}
public static string Decode(int step, string source)
{
return Encode(-step + Ru.Length, source, x => x);
}
}
class CaesarEncrypted : IEnumerable, IEnumerable<char>
{
public int Step { get; set; }
public string Data { get; set; }
public CaesarEncrypted(int step, string initData)
{
Step = step;
Data = initData;
}
public CaesarEncrypted(string initData) : this(int.MaxValue, initData)
{}
public IEnumerator<char> GetEnumerator()
{
foreach (char c in Data)
yield return c;
}
IEnumerator IEnumerable.GetEnumerator() => (IEnumerator<char>)GetEnumerator();
public override string ToString() => Data;
public static implicit operator string(CaesarEncrypted source) => source.ToString();
}
}
Объяснение:
1. Пронумеруем разряды:
3-й разряд - 4;
2-й разряд - 1;
1-й разряд - 5;
0-й разряд - 3.
4153₈=4·8³+1·8²+5·8¹+3·8⁰
2. 4153₈=4·8³+1·8²+5·8¹+3·8⁰=2048+16+40+3=2155₁₀
3. 125/8=15 (5)
15/8=1 (7)
(1)
125₁₀=175₈
4. Пронумеруем разряды:
2-й разряд - A;
1-й разряд - 6;
0-й разряд - E;
A6E₁₆=(10)(6)(14)=10·16²+6·16¹+14·16⁰
5. A6E₁₆=10·16²+6·16¹+14·16⁰=2560+96+14=2670₁₀
6. 350/16=21 (14=E)
21/16=1 (5)
(1)
350₁₀=15E₁₆
7. 247/2=123 (1)
123/2=61 (1)
61/2=30 (1)
30/2=15 (0)
15/2=7 (1)
7/2=3 (1)
3/2=1 (1)
(1)
247₁₀=11110111₂
247/8=30 (7)
30/8=3 (6)
(3)
247₁₀=367₈
247/16=7 (15=F)
(7)
247₁₀=7F₁₆
Получившиеся числа между собой равны, так как имеют одинаковое число в десятичной системе счисления.