forked from Kanyelings/p2-25-coding-challenges-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exo39.cs
33 lines (30 loc) · 761 Bytes
/
exo39.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
using System;
using System.Text;
class exo39
{
static void Main()
{
String text = "ATTACKATONCE";
int s = 4;
StringBuilder cipher = encrypt(text, s);
Console.WriteLine(cipher);
}
public static StringBuilder encrypt(String text, int s)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < text.Length; i++)
{
if (char.IsUpper(text[i]))
{
char ch = (char)(((int)text[i] + s - 65) % 26 + 65);
result.Append(ch);
}
else
{
char ch = (char)(((int)text[i] + s - 97) % 26 + 97);
result.Append(ch);
}
}
return result;
}
}