Caesar's cipher is the most famous symmetric key encryption algorithm. It was used by the Julius Caesar of Rome for military communications.
It works by replacing a letter with another letter by some fixed number of position. It's better understood with an example.
Suppose, we want to encrypt "hey". And the fixed number of position for replacement is 2.
Let's write the english alphabets. a b c d e f g h i j k l m n o p q r s t u v w x y z.
The letter two places ahead of h
is j
. Hence,
h becomes j
.
Similarly, e becomes g
.
Now, there's no letter ahead of two places of y
, so we go to the beginning. Hence,
y becomes a.
The fixed number of position is the encryption key.
Finally, encrypting the plaintext hey with key 2 will result in ciphertext jga.
To decrypt, instead of going forward number of positions, we go backwards. jga will become hey.
Your tasks in this challenge are:
encrypt(plaintext, key)
function and make
sure you
understand why we are using the if
condition there.decrypt(ciphertext, key)
function so that
it
returns "checkflank"
.decrypt() returns "checkflank"
You need to pass this challenge to go to the next lesson. Good luck!
📈 Please, fill a short feedback form designed for this lesson. We love you!