95 lines
2.5 KiB
Plaintext
95 lines
2.5 KiB
Plaintext
/* NetRexx */
|
|
options replace format comments java crossref savelog symbols nobinary
|
|
|
|
parse arg fileNames
|
|
|
|
rdr = BufferedReader
|
|
|
|
do
|
|
if fileNames.length > 0 then do
|
|
loop n_ = 1 for fileNames.words
|
|
fileName = fileNames.word(n_)
|
|
rdr = BufferedReader(FileReader(File(fileName)))
|
|
encipher(rdr)
|
|
end n_
|
|
end
|
|
else do
|
|
rdr = BufferedReader(InputStreamReader(System.in))
|
|
encipher(rdr)
|
|
end
|
|
catch ex = IOException
|
|
ex.printStackTrace
|
|
end
|
|
|
|
return
|
|
|
|
method encipher(rdr = BufferedReader) public static signals IOException
|
|
|
|
loop label l_ forever
|
|
line = rdr.readLine
|
|
if line = null then leave l_
|
|
say rot13(line)
|
|
end l_
|
|
return
|
|
|
|
method rot13(input) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, 13, isFalse)
|
|
|
|
method caesar(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
|
|
|
if idx < 1 | idx > 25 then signal IllegalArgumentException()
|
|
|
|
-- 12345678901234567890123456
|
|
itab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
shift = itab.length - idx
|
|
parse itab tl +(shift) tr
|
|
otab = tr || tl
|
|
|
|
if caps then input = input.upper
|
|
|
|
cipher = input.translate(itab || itab.lower, otab || otab.lower)
|
|
|
|
return cipher
|
|
|
|
method caesar_encipher(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, idx, caps)
|
|
|
|
method caesar_decipher(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, int(26) - idx, isFalse)
|
|
|
|
method caesar_encipher(input = Rexx, idx = int) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, idx, isFalse)
|
|
|
|
method caesar_decipher(input = Rexx, idx = int) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, int(26) - idx, isFalse)
|
|
|
|
method caesar_encipher(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, idx, opt)
|
|
|
|
method caesar_decipher(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, int(26) - idx, opt)
|
|
|
|
method caesar(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
|
|
|
if opt.upper.abbrev('U') >= 1 then caps = isTrue
|
|
else caps = isFalse
|
|
|
|
return caesar(input, idx, caps)
|
|
|
|
method caesar(input = Rexx, idx = int) public static signals IllegalArgumentException
|
|
|
|
return caesar(input, idx, isFalse)
|
|
|
|
method isTrue public static returns boolean
|
|
return (1 == 1)
|
|
|
|
method isFalse public static returns boolean
|
|
return \isTrue
|