

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: What Is a Cipher?
incomplete
2: Caesar Cipher
incomplete
3: Caesar Cipher Security
incomplete
This lesson's interactive features are locked, please to keep using them
Example of Caesar cipher with right shift 3:
Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shifted: DEFGHIJKLMNOPQRSTUVWXYZABC
Each letter in the plaintext alphabet maps directly to its corresponding match in the cipher alphabet.
For example:
"A" -> "D"
"B" -> "E"
To demonstrate the superiority of our modern ciphers at Passly, we've been asked to implement a Caesar cipher. It's so the marketing team can show off how much better our algorithms are than the ones used by the Romans. Go figure.
Complete the encrypt, decrypt, crypt, and getOffsetChar functions. The encrypt and decrypt functions do what you would expect, crypt and getOffsetChar are helper functions.
Should call and return the result of crypt().
Should call and return the result of crypt(), but should pass in the negative value of key so that the offset is reversed.
This is where the meat of the encryption/decryption happens. Iterate over each character in the text, and use getOffsetChar to get the proper substitution character. Return a string of all of the substitution characters.
This function takes a single character (as a rune) and an offset. It should return the character (as a string) that is offset positions away from the given character. The alphabet has been provided for you.
For example, when offset = 5:
a -> f
b -> g
...
x -> c
z -> e
Or when offset = 1:
a -> b
b -> c
...
x -> y
z -> a
Remember that offset can be negative, and remember that the alphabet wraps around. For example, when offset = -5:
a -> v
b -> w
c -> x
d -> y
e -> z
If you can't find the character in the alphabet, return an empty string.