-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrot13.d
39 lines (33 loc) · 822 Bytes
/
rot13.d
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
import std.ascii;
import std.range;
import std.stdio;
int main(string[] args) {
File input;
if (args.length == 1) {
input = stdin;
} else if (args.length == 2) {
input = File(args[1], "r");
} else {
stderr.writeln("USAGE: rot13 [filename]");
return 1;
}
dchar[] yvar;
foreach (line; input.byLine(KeepTerminator.yes)) {
foreach (c; line.stride(1)) {
switch(c) {
case 'A': .. case 'Z':
yvar ~= ((c - 'A') + 13) % 26 + 'A';
break;
case 'a': .. case 'z':
yvar ~= ((c - 'a') + 13) % 26 + 'a';
break;
default:
yvar ~= c;
}
}
write(yvar);
yvar = [];
}
input.close();
return 0;
}