RosettaCodeData/Task/Caesar-cipher/Seed7/caesar-cipher.seed7

30 lines
909 B
Plaintext

$ include "seed7_05.s7i";
const func string: rot (in string: stri, in integer: encodingKey) is func
result
var string: encodedStri is "";
local
var char: ch is ' ';
var integer: index is 0;
begin
encodedStri := stri;
for ch key index range stri do
if ch >= 'a' and ch <= 'z' then
ch := chr((ord(ch) - ord('a') + encodingKey) rem 26 + ord('a'));
elsif ch >= 'A' and ch <= 'Z' then
ch := chr((ord(ch) - ord('A') + encodingKey) rem 26 + ord('A'));
end if;
encodedStri @:= [index] ch;
end for;
end func;
const proc: main is func
local
const integer: exampleKey is 3;
const string: testText is "The five boxing wizards jump quickly";
begin
writeln("Original: " <& testText);
writeln("Encrypted: " <& rot(testText, exampleKey));
writeln("Decrypted: " <& rot(rot(testText, exampleKey), 26 - exampleKey));
end func;