-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
119 lines (111 loc) · 2.84 KB
/
Program.cs
File metadata and controls
119 lines (111 loc) · 2.84 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System.Buffers.Text;
using System.Text;
static string Rot13(string value)
{
int shift = 13;
char[] array = value.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = array[i];
switch (num)
{
case 110:
case 111:
case 112:
case 113:
case 114:
case 115:
case 116:
case 117:
case 118:
case 119:
case 120:
case 121:
case 122:
num -= shift;
break;
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
num += shift;
break;
default:
switch (num)
{
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
num -= shift;
break;
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
num += shift;
break;
}
break;
}
array[i] = (char)num;
}
return new string(array);
}
static string DecryptInfo(string path)
{
var s = File.ReadAllText(path);
s = Rot13(s.Substring(1));
s = Encoding.UTF8.GetString(Convert.FromBase64String(s));
return s;
}
static string EncryptInfo(string path)
{
var json = File.ReadAllText(path);
var utf8 = Encoding.UTF8.GetBytes(json);
var base64 = Convert.ToBase64String(utf8);
var shifted = Rot13(base64);
return "\0" + shifted;
}
string[] cli_args = Environment.GetCommandLineArgs();
if (cli_args.Length == 4 && cli_args[1] == "decrypt")
{
string json = DecryptInfo(cli_args[2]);
File.WriteAllText(cli_args[3], json);
Console.WriteLine(json);
} else if (cli_args.Length == 4 && cli_args[1] == "encrypt")
{
string bin = EncryptInfo(cli_args[2]);
File.WriteAllText(cli_args[3], bin);
} else
{
Console.WriteLine($"Command Line Usage: {cli_args[0]} (encrpyt|decrypt) in out");
}