-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypter.cs
More file actions
45 lines (43 loc) · 1.28 KB
/
Encrypter.cs
File metadata and controls
45 lines (43 loc) · 1.28 KB
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
40
41
42
43
44
45
using System;
using System.Linq;
namespace CypherBarrel
{
internal class Encrypter
{
private static void Main(string[] args)
{
string[] lines = System.IO.File.ReadAllLines(args[0]);
string key = null;
foreach (var line in lines.Skip(1).Select((s, i) =>
{
if (i % 2 == 0)
{
key = s;
return lines[i + 2];
}
return null;
}).Where(line => line != null))
{
var keypos = 0;
foreach (var letter in line)
{
if (keypos >= key.Length)
{
key = string.Concat(Enumerable.Reverse(key));
keypos = 0;
}
if (letter == ' ')
Console.Write(' ');
else
{
var newkey = letter + Char.GetNumericValue(key[keypos++]);
if (newkey > 'z')
newkey -= 26;
Console.Write((char)newkey);
}
}
Console.Write("\n");
}
}
}
}