/* NetRexx */ options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].right(3) ec = caesar_encipher(in, keys[k_]) dc = caesar_decipher(ec, keys[k_]) say in say ec say dc say end k_ say 'Rot-13:' ec = rot13(in) dc = rot13(ec) say in say ec say dc say end m_ 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