Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards. The first letter is replaced with the last letter, the second with the second-last, and so on.
An Atbash cipher for the Latin alphabet would be as follows:
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: zyxwvutsrqponmlkjihgfedcba
It is a very weak cipher because it only has one possible key, and it is a simple monoalphabetic substitution cipher. However, this may not have been an issue in the cipher's time.
Ciphertext is written out in groups of fixed length, the traditional group size being 5 letters, and punctuation is excluded. This is to make it harder to guess things based on word boundaries.
test
gives gvhg
gvhg
gives test
gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt
gives thequickbrownfoxjumpsoverthelazydog
## SourceWikipedia http://en.wikipedia.org/wiki/Atbash
This exercise has been tested on Julia versions >=1.0.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
In [ ]:
# submit
function encode(input::AbstractString)
end
function decode(input::AbstractString)
end
In [ ]:
# canonical data version: 1.2.0
using Test
# include("atbash-cipher.jl")
@testset "encoding from English to atbash" begin
@test encode("yes") == "bvh"
@test encode("no") == "ml"
@test encode("OMG") == "lnt"
@test encode("O M G") == "lnt"
@test encode("mindblowingly") == "nrmwy oldrm tob"
@test encode("Testing,1 2 3, testing.") == "gvhgr mt123 gvhgr mt"
@test encode("Truth is fiction.") == "gifgs rhurx grlm"
@test encode("The quick brown fox jumps over the lazy dog.") == "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
end
@testset "decoding from atbash to English" begin
@test decode("vcvix rhn") == "exercism"
@test decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") == "anobstacleisoftenasteppingstone"
@test decode("gvhgr mt123 gvhgr mt") == "testing123testing"
@test decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") == "thequickbrownfoxjumpsoverthelazydog"
@test decode("vc vix r hn") == "exercism"
@test decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv") == "anobstacleisoftenasteppingstone"
end
To submit your exercise, you need to save your solution in a file called atbash-cipher.jl
before using the CLI.
You can either create it manually or use the following functions, which will automatically write every notebook cell that starts with # submit
to the file atbash-cipher.jl
.
In [ ]:
# using Pkg; Pkg.add("Exercism")
# using Exercism
# Exercism.create_submission("atbash-cipher")