Files
ivy/doc/sample/CaesarCipher.im

66 lines
894 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
shiftWidth = 0
while true do
cout print:'Shift size: '
cout flush
shiftStr = ''
cin get:shiftStr
if shiftStr == '' then
continue
end
try
shiftWidth = Int parse:shiftStr
catch (#err:number_format, err)
continue
end
break
end
encodedMessage = ''
for c in message do
i = c toOrdinal
sub = 0
if i >= 65 && i <= 90 then
sub = 65
elif i >= 97 && i <= 122 then
sub = 97
else
continue
end
i -= sub
i += shiftWidth
if i >= 26 then
i -= 26
end
c2 = i toChar
encodedMessage += c2
end
cout put:encodedMessage