all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
51
Task/Vigen-re-cipher/Seed7/vigen-re-cipher.seed7
Normal file
51
Task/Vigen-re-cipher/Seed7/vigen-re-cipher.seed7
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const func string: vigenereCipher (in string: source, in var string: keyword) is func
|
||||
result
|
||||
var string: dest is "";
|
||||
local
|
||||
var char: ch is ' ';
|
||||
var integer: index is 1;
|
||||
var integer: shift is 0;
|
||||
begin
|
||||
keyword := upper(keyword);
|
||||
for ch range source do
|
||||
if ch in {'A' .. 'Z'} | {'a' .. 'z'} then
|
||||
shift := ord(keyword[succ(pred(index) rem length(keyword))]) - ord('A');
|
||||
dest &:= chr(ord('A') + (ord(upper(ch)) - ord('A') + shift) rem 26);
|
||||
incr(index);
|
||||
end if;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const func string: vigenereDecipher (in string: source, in var string: keyword) is func
|
||||
result
|
||||
var string: dest is "";
|
||||
local
|
||||
var char: ch is ' ';
|
||||
var integer: index is 0;
|
||||
var integer: shift is 0;
|
||||
begin
|
||||
keyword := upper(keyword);
|
||||
for ch key index range source do
|
||||
if ch in {'A' .. 'Z'} | {'a' .. 'z'} then
|
||||
shift := ord(keyword[succ(pred(index) rem length(keyword))]) - ord('A');
|
||||
dest &:= chr(ord('A') + (ord(upper(ch)) - ord('A') - shift) mod 26);
|
||||
end if;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
const string: input is "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
|
||||
const string: keyword is "VIGENERECIPHER";
|
||||
var string: encrypted is "";
|
||||
var string: decrypted is "";
|
||||
begin
|
||||
writeln("Input: " <& input);
|
||||
writeln("key: " <& keyword);
|
||||
encrypted := vigenereCipher(input, keyword);
|
||||
writeln("Encrypted: " <& encrypted);
|
||||
decrypted := vigenereDecipher(encrypted, keyword);
|
||||
writeln("Decrypted: " <& decrypted);
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue