36 lines
701 B
Plaintext
36 lines
701 B
Plaintext
class Rot13
|
|
{
|
|
static Str rot13 (Str input)
|
|
{
|
|
Str result := ""
|
|
input.each |Int c|
|
|
{
|
|
if ((c.lower >= 'a') && (c.lower <= 'm'))
|
|
result += (c+13).toChar
|
|
else if ((c.lower >= 'n') && (c.lower <= 'z'))
|
|
result += (c-13).toChar
|
|
else
|
|
result += c.toChar
|
|
}
|
|
return result
|
|
}
|
|
|
|
public static Void main (Str[] args)
|
|
{
|
|
if (args.size == 1)
|
|
{ // process each line of given file
|
|
Str filename := args[0]
|
|
File(filename.toUri).eachLine |Str line|
|
|
{
|
|
echo (rot13(line))
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo ("Test:")
|
|
Str text := "abcstuABCSTU123!+-"
|
|
echo ("Text $text becomes ${rot13(text)}")
|
|
}
|
|
}
|
|
}
|