Created
May 22, 2020 20:08
-
-
Save rexim/7bc3c521a0a3daf39c63ee7cb717e5b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program rot13; | |
| { | |
| Byte = 1 byte | |
| ShortInt = 2 bytes | |
| Integer = 4 bytes | |
| } | |
| function rot13(x : char): char; | |
| var | |
| ans : ShortInt; | |
| shift : ShortInt; | |
| begin | |
| rot13 := x; | |
| shift := 0; | |
| if ('a' <= x) and (x <= 'z') then shift := ord('a'); | |
| if ('A' <= x) and (x <= 'Z') then shift := ord('A'); | |
| if shift > 0 then | |
| begin | |
| ans := ord(x); {convert to ASCII code} | |
| ans := ans - shift; {conver to number in the alphabet} | |
| ans := ans + 13; {shift by 13 to the right} | |
| ans := ans mod 26; {wrap around the alphabet} | |
| ans := ans + shift; {convert back to ASCII code} | |
| rot13 := chr(ans); {convert back to char} | |
| end; | |
| end; | |
| var | |
| chunk : String[512]; | |
| i : Integer; | |
| n : Integer; | |
| begin | |
| n := 0; | |
| repeat | |
| { TODO: the program probably does not work correctly with new lines} | |
| read(chunk); | |
| for i := 1 to length(chunk) do | |
| begin | |
| write(rot13(chunk[i])) | |
| end; | |
| inc(n); | |
| until length(chunk) = 0; | |
| writeln; | |
| writeln('Read ', n, ' chunks'); | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment