-
-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
|
||
namespace Rot13; | ||
|
||
class Program | ||
{ | ||
public static void Usage() | ||
{ | ||
Console.WriteLine("Usage: please provide a string to encrypt"); | ||
Environment.Exit(0); | ||
} | ||
|
||
public static void Rot13(StringView str, ref String result) | ||
{ | ||
result.Clear(); | ||
result.Reserve(str.Length); | ||
for (char8 ch in str) | ||
{ | ||
char8 chLower = ch.ToLower; | ||
if (chLower >= 'a' && chLower <= 'm') | ||
{ | ||
ch += 13; | ||
} | ||
else if (chLower >= 'n' && chLower <= 'z') | ||
{ | ||
ch -= 13; | ||
} | ||
|
||
result += ch; | ||
} | ||
} | ||
|
||
public static int Main(String[] args) | ||
{ | ||
if (args.Count < 1 || args[0].Length < 1) | ||
{ | ||
Usage(); | ||
} | ||
|
||
String result = scope String(); | ||
Rot13(args[0], ref result); | ||
Console.WriteLine(result); | ||
return 0; | ||
} | ||
} |