-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCesarCipher.cs
More file actions
32 lines (23 loc) · 992 Bytes
/
CesarCipher.cs
File metadata and controls
32 lines (23 loc) · 992 Bytes
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
using System.Text;
namespace AlgorithmsAndDataStructures.Algorithms.Cryptography;
public class CesarCipher
{
#pragma warning disable CA1822 // Mark members as static
public string Encode(string input, byte padding)
#pragma warning restore CA1822 // Mark members as static
{
if (string.IsNullOrEmpty(input)) return string.Empty;
var resultBuilder = new StringBuilder(input.Length);
foreach (var symbol in input) resultBuilder.Append((char)((byte)symbol + padding));
return resultBuilder.ToString();
}
#pragma warning disable CA1822 // Mark members as static
public string Decode(string input, byte padding)
#pragma warning restore CA1822 // Mark members as static
{
if (string.IsNullOrEmpty(input)) return string.Empty;
var resultBuilder = new StringBuilder(input.Length);
foreach (var symbol in input) resultBuilder.Append((char)((byte)symbol - padding));
return resultBuilder.ToString();
}
}