26 lines
731 B
Plaintext
26 lines
731 B
Plaintext
; caesar.xom
|
|
global integer gi-k initial {13}
|
|
global stream gs-ed initial {'encode'}
|
|
global stream gs-phrase
|
|
|
|
define stream function apply-cipher (value stream phrase, value integer k, value stream ed) as
|
|
local integer b
|
|
local stream ciphered
|
|
open ciphered as buffer
|
|
repeat scan phrase
|
|
match letter => char
|
|
set b to char binary 0
|
|
increment b by k when ed = 'encode'
|
|
increment b by 26 - k when ed = 'decode'
|
|
decrement b by 26 when char matches uc and b > 90
|
|
decrement b by 26 when char matches lc and b > 122
|
|
put ciphered "b" % b
|
|
match any => char
|
|
put ciphered char
|
|
again
|
|
close ciphered
|
|
return ciphered
|
|
|
|
process
|
|
output apply-cipher(gs-phrase, gi-k, gs-ed) || '%n%n'
|