RosettaCodeData/Task/Rot-13/C-sharp/rot-13.cs

29 lines
669 B
C#
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
using System;
2023-09-01 09:35:06 -07:00
using System;
2023-07-01 11:58:00 -04:00
using System.IO;
using System.Linq;
using System.Text;
2023-09-01 09:35:06 -07:00
class Program {
private static char shift(char c) {
return c.ToString().ToLower().First() switch {
>= 'a' and <= 'm' => (char)(c + 13),
>= 'n' and <= 'z' => (char)(c - 13),
var _ => c
};
2023-07-01 11:58:00 -04:00
}
2023-12-16 21:33:55 -08:00
static string Rot13(string s) => new string(s.Select(c => shift(c)).ToArray());
2023-07-01 11:58:00 -04:00
2023-09-01 09:35:06 -07:00
static void Main(string[] args) {
foreach (var file in args.Where(file => File.Exists(file))) {
2023-07-01 11:58:00 -04:00
Console.WriteLine(Rot13(File.ReadAllText(file)));
}
2023-09-01 09:35:06 -07:00
if (!args.Any()) {
2023-07-01 11:58:00 -04:00
Console.WriteLine(Rot13(Console.In.ReadToEnd()));
}
}
}