Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
59
Task/Caesar-cipher/Oberon-2/caesar-cipher.oberon
Normal file
59
Task/Caesar-cipher/Oberon-2/caesar-cipher.oberon
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
MODULE Caesar;
|
||||
IMPORT
|
||||
Out;
|
||||
CONST
|
||||
encode* = 1;
|
||||
decode* = -1;
|
||||
|
||||
VAR
|
||||
text,cipher: POINTER TO ARRAY OF CHAR;
|
||||
|
||||
PROCEDURE Cipher*(txt: ARRAY OF CHAR; key: INTEGER; op: INTEGER; VAR cipher: ARRAY OF CHAR);
|
||||
VAR
|
||||
i: LONGINT;
|
||||
BEGIN
|
||||
i := 0;
|
||||
WHILE i < LEN(txt) - 1 DO
|
||||
IF (txt[i] >= 'A') & (txt[i] <= 'Z') THEN
|
||||
cipher[i] := CHR(ORD('A') + ((ORD(txt[i]) - ORD('A') + (key * op))) MOD 26)
|
||||
ELSIF (txt[i] >= 'a') & (txt[i] <= 'z') THEN
|
||||
cipher[i] := CHR(ORD('a') + ((ORD(txt[i]) - ORD('a') + (key * op))) MOD 26)
|
||||
ELSE
|
||||
cipher[i] := txt[i]
|
||||
END;
|
||||
INC(i)
|
||||
END;
|
||||
cipher[i] := 0X
|
||||
END Cipher;
|
||||
|
||||
BEGIN
|
||||
NEW(text,3);NEW(cipher,3);
|
||||
COPY("HI",text^);
|
||||
Out.String(text^);Out.String(" =e=> ");
|
||||
Cipher(text^,2,encode,cipher^);
|
||||
Out.String(cipher^);
|
||||
|
||||
COPY(cipher^,text^);
|
||||
Cipher(text^,2,decode,cipher^);
|
||||
Out.String(" =d=> ");Out.String(cipher^);Out.Ln;
|
||||
|
||||
COPY("ZA",text^);
|
||||
Out.String(text^);Out.String(" =e=> ");
|
||||
Cipher(text^,2,encode,cipher^);
|
||||
Out.String(cipher^);
|
||||
|
||||
COPY(cipher^,text^);
|
||||
Cipher(text^,2,decode,cipher^);
|
||||
Out.String(" =d=> ");Out.String(cipher^);Out.Ln;
|
||||
|
||||
NEW(text,37);NEW(cipher,37);
|
||||
COPY("The five boxing wizards jump quickly",text^);
|
||||
Out.String(text^);Out.String(" =e=> ");
|
||||
Cipher(text^,3,encode,cipher^);
|
||||
Out.String(cipher^);
|
||||
|
||||
COPY(cipher^,text^);
|
||||
Cipher(text^,3,decode,cipher^);
|
||||
Out.String(" =d=> ");Out.String(cipher^);Out.Ln;
|
||||
|
||||
END Caesar.
|
||||
Loading…
Add table
Add a link
Reference in a new issue