Files
ivy/doc/sample/CaesarCipher.im

65 lines
888 B
Plaintext

package net.doorstuck.test
cout put:'Encode a string with a Caesar cipher.'
message = ''
while true do
cout print:'Message to encode: '
cout flush
cin get:message
if message != '' then
break
end
end
shift-width = 0
while true do
cout print:'Shift size: '
cout flush
shift-str = cin read-line.
if shift-str == '' then
continue
end
try
shift-width = Int parse:shift-str
catch ($err:number-format, err)
continue
end
break
end
encoded-message = ''
for c in message do
i = c to-ordinal
sub = 0
if i >= 65 && i <= 90 then
sub = 65
elif i >= 97 && i <= 122 then
sub = 97
else
continue
end
i -= sub
i += shift-width
if i >= 26 then
i -= 26
end
c2 = i to-char
encoded-message += c2
end
cout put:encoded-message