forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubstitutionCipherFilter.cs
More file actions
47 lines (40 loc) · 1.33 KB
/
SubstitutionCipherFilter.cs
File metadata and controls
47 lines (40 loc) · 1.33 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
46
47
using System.Collections.Generic;
using System.IO;
namespace LibGit2Sharp.Tests.TestHelpers
{
public class SubstitutionCipherFilter : Filter
{
public int CleanCalledCount = 0;
public int SmudgeCalledCount = 0;
public SubstitutionCipherFilter(string name, IEnumerable<FilterAttributeEntry> attributes)
: base(name, attributes)
{
}
protected override void Clean(string path, string root, Stream input, Stream output)
{
CleanCalledCount++;
RotateByThirteenPlaces(input, output);
}
protected override void Smudge(string path, string root, Stream input, Stream output)
{
SmudgeCalledCount++;
RotateByThirteenPlaces(input, output);
}
public static void RotateByThirteenPlaces(Stream input, Stream output)
{
int value;
while ((value = input.ReadByte()) != -1)
{
if ((value >= 'a' && value <= 'm') || (value >= 'A' && value <= 'M'))
{
value += 13;
}
else if ((value >= 'n' && value <= 'z') || (value >= 'N' && value <= 'Z'))
{
value -= 13;
}
output.WriteByte((byte)value);
}
}
}
}