-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atbash.cs
39 lines (36 loc) · 1.04 KB
/
Atbash.cs
1
2
3
4
5
6
7
8
9
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
using System;
using System.Collections.Generic;
using System.Text;
namespace CodeBreaker
{
class Atbash : Cracker
{
Dictionary<char, char> Mapping = InitAtbash();
public string Crack(string input)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (char character in input)
{
sb.Append(GetChar(character));
}
return sb.ToString();
}
private char GetChar(char input)
{
if(input == ' ')
{
return ' ';
}
return Mapping[Char.ToLower(input)];
}
private static Dictionary<char, char> InitAtbash()
{
Dictionary<char, char> mapping = new Dictionary<char, char>();
for(int i = 0; i < Cracker.Characters.Count; i++)
{
mapping.Add(Cracker.Characters[i], Cracker.Characters[Cracker.Characters.Count - i - 1]);
}
return mapping;
}
}
}