Caesar cipher: Difference between revisions

Content deleted Content added
Langurmonkey (talk | contribs)
Kennypete (talk | contribs)
Added OmniMark solution
 
Line 5,307: Line 5,307:
Pack my box with five dozen liquor jugs.
Pack my box with five dozen liquor jugs.
</pre>
</pre>

=={{header|OmniMark}}==

<syntaxhighlight lang="omnimark">
; 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'
</syntaxhighlight>

{{out}}
<pre>
> omnimark -sb caesar.xom -c gi-k 2 -d gs-ed encode -d gs-phrase 'HI! The quick brown fox jumps over the lazy dog.'
JK! Vjg swkem dtqyp hqz lworu qxgt vjg ncba fqi.

> omnimark -sb caesar.xom -c gi-k 20 -d gs-ed encode -d gs-phrase 'HI! The quick brown fox jumps over the lazy dog.'
BC! Nby kocwe vliqh zir dogjm ipyl nby futs xia.

> omnimark -sb caesar.xom -c gi-k 2 -d gs-ed decode -d gs-phrase 'JK! Vjg swkem dtqyp hqz lworu qxgt vjg ncba fqi.'
HI! The quick brown fox jumps over the lazy dog.

> omnimark -sb caesar.xom -c gi-k 20 -d gs-ed decode -d gs-phrase 'BC! Nby kocwe vliqh zir dogjm ipyl nby futs xia.'
HI! The quick brown fox jumps over the lazy dog.
</pre>

=={{header|OOC}}==
=={{header|OOC}}==
<syntaxhighlight lang="ooc">main: func (args: String[]) {
<syntaxhighlight lang="ooc">main: func (args: String[]) {