Caesar Cipher
Specification
- Input:
- A word to encode.
- An integer as the key.
- Output:
An encoded word.
- Relationship: ch is encoded as chr(ord(ch) + key)
To keep it simple, let us assume that the input word is composed of
uppercase alphabets 'A' ~ 'Z' only.
This is similar to the Caesar
Cipher exercise as we did with Python. However, in C language, the char
data type is actually handled as integers, so you don't need the ord()
and chr()
functions to convert characters to integers, or vice versa.
This is where C language seems to be more convenient and powerful.
The pseudo code of the program may look like:
============
Get a word to encode.
Get a number as the key.
For each character ch in the word,
output ch + key.
The program may run as below:
Please input the plaintext -- XYZABC
Please input your key -- 3
ABCDEF