forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JuliaLang#40 from andrej-makarov-skrt/ex-atbash-ci…
…pher Add exercise: atbash-cipher
- Loading branch information
Showing
4 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function encode(input::AbstractString) | ||
|
||
end | ||
|
||
function decode(input::AbstractString) | ||
|
||
end | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cipher(input::AbstractString) = map(x->isalpha(x)?Char(219-Int(x)):x, lowercase(filter(isalnum, input))) | ||
encode(input::AbstractString) = join(matchall(r"(.{1,5})", cipher(input)), ' ') | ||
decode(input::AbstractString) = cipher(input) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Base.Test | ||
|
||
include("atbash-cipher.jl") | ||
|
||
@testset "encoding from English to atbash" begin | ||
@testset "encode yes" begin | ||
@test encode("yes") == "bvh" | ||
end | ||
|
||
@testset "encode no" begin | ||
@test encode("no") == "ml" | ||
end | ||
|
||
@testset "encode OMG" begin | ||
@test encode("OMG") == "lnt" | ||
end | ||
|
||
@testset "encode spaces" begin | ||
@test encode("O M G") == "lnt" | ||
end | ||
|
||
@testset "encode mindblowingly" begin | ||
@test encode("mindblowingly") == "nrmwy oldrm tob" | ||
end | ||
|
||
@testset "encode numbers" begin | ||
@test encode("Testing,1 2 3, testing.") == "gvhgr mt123 gvhgr mt" | ||
end | ||
|
||
@testset "encode deep thought" begin | ||
@test encode("Truth is fiction.") == "gifgs rhurx grlm" | ||
end | ||
|
||
@testset "encode all the letters" begin | ||
@test encode("The quick brown fox jumps over the lazy dog.") == "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" | ||
end | ||
end | ||
|
||
@testset "decoding from atbash to English" begin | ||
@testset "decode exercism" begin | ||
@test decode("vcvix rhn") == "exercism" | ||
end | ||
|
||
@testset "decode a sentence" begin | ||
@test decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") == "anobstacleisoftenasteppingstone" | ||
end | ||
|
||
@testset "decode numbers" begin | ||
@test decode("gvhgr mt123 gvhgr mt") == "testing123testing" | ||
end | ||
|
||
@testset "decode all the letters" begin | ||
@test decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") == "thequickbrownfoxjumpsoverthelazydog" | ||
end | ||
end | ||
|