commit 59954190eb25e0b311d53770021a01e98ae8646e
parent 8363fc8b036459685e84dbb45159327dd5f7aee2
Author: Samir Parikh <noreply@samirparikh.com>
Date: Fri, 28 Jan 2022 16:38:18 +0000
initial commit
Diffstat:
4 files changed, 244 insertions(+), 0 deletions(-)
diff --git a/atbash-cipher/AtbashCipher.pm b/atbash-cipher/AtbashCipher.pm
@@ -0,0 +1,17 @@
+package AtbashCipher;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<encode_atbash decode_atbash>;
+
+sub encode_atbash {
+ my ($phrase) = @_;
+ return undef;
+}
+
+sub decode_atbash {
+ my ($phrase) = @_;
+ return undef;
+}
+
+1;
diff --git a/atbash-cipher/HELP.md b/atbash-cipher/HELP.md
@@ -0,0 +1,35 @@
+# Help
+
+## Running the tests
+
+There is a Perl 5 script with the extension `.t`, which will be used to test
+your solution. You can run through the tests by using the command:
+
+```bash
+`prove .`
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit AtbashCipher.pm` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
+\ No newline at end of file
diff --git a/atbash-cipher/README.md b/atbash-cipher/README.md
@@ -0,0 +1,51 @@
+# Atbash Cipher
+
+Welcome to Atbash Cipher on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+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:
+
+```text
+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.
+
+## Examples
+
+- Encoding `test` gives `gvhg`
+- Decoding `gvhg` gives `test`
+- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @dnmfarrell
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Wikipedia - http://en.wikipedia.org/wiki/Atbash
+\ No newline at end of file
diff --git a/atbash-cipher/atbash-cipher.t b/atbash-cipher/atbash-cipher.t
@@ -0,0 +1,139 @@
+#!/usr/bin/env perl
+use Test2::V0;
+use JSON::PP;
+use constant JSON => JSON::PP->new;
+
+use FindBin qw<$Bin>;
+use lib $Bin, "$Bin/local/lib/perl5";
+
+use AtbashCipher qw<encode_atbash decode_atbash>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+plan 15;
+
+imported_ok qw<encode_atbash decode_atbash> or bail_out;
+
+for my $case (@test_cases) {
+ is(
+ $case->{property} eq 'encode'
+ ? encode_atbash( $case->{input}{phrase} )
+ : decode_atbash( $case->{input}{phrase} ),
+ $case->{expected}, $case->{description}
+ );
+}
+
+__DATA__
+[
+ {
+ "description": "encode: encode yes",
+ "expected": "bvh",
+ "input": {
+ "phrase": "yes"
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode no",
+ "expected": "ml",
+ "input": {
+ "phrase": "no"
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode OMG",
+ "expected": "lnt",
+ "input": {
+ "phrase": "OMG"
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode spaces",
+ "expected": "lnt",
+ "input": {
+ "phrase": "O M G"
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode mindblowingly",
+ "expected": "nrmwy oldrm tob",
+ "input": {
+ "phrase": "mindblowingly"
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode numbers",
+ "expected": "gvhgr mt123 gvhgr mt",
+ "input": {
+ "phrase": "Testing,1 2 3, testing."
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode deep thought",
+ "expected": "gifgs rhurx grlm",
+ "input": {
+ "phrase": "Truth is fiction."
+ },
+ "property": "encode"
+ },
+ {
+ "description": "encode: encode all the letters",
+ "expected": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt",
+ "input": {
+ "phrase": "The quick brown fox jumps over the lazy dog."
+ },
+ "property": "encode"
+ },
+ {
+ "description": "decode: decode exercism",
+ "expected": "exercism",
+ "input": {
+ "phrase": "vcvix rhn"
+ },
+ "property": "decode"
+ },
+ {
+ "description": "decode: decode a sentence",
+ "expected": "anobstacleisoftenasteppingstone",
+ "input": {
+ "phrase": "zmlyh gzxov rhlug vmzhg vkkrm thglm v"
+ },
+ "property": "decode"
+ },
+ {
+ "description": "decode: decode numbers",
+ "expected": "testing123testing",
+ "input": {
+ "phrase": "gvhgr mt123 gvhgr mt"
+ },
+ "property": "decode"
+ },
+ {
+ "description": "decode: decode all the letters",
+ "expected": "thequickbrownfoxjumpsoverthelazydog",
+ "input": {
+ "phrase": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
+ },
+ "property": "decode"
+ },
+ {
+ "description": "decode: decode with too many spaces",
+ "expected": "exercism",
+ "input": {
+ "phrase": "vc vix r hn"
+ },
+ "property": "decode"
+ },
+ {
+ "description": "decode: decode with no spaces",
+ "expected": "anobstacleisoftenasteppingstone",
+ "input": {
+ "phrase": "zmlyhgzxovrhlugvmzhgvkkrmthglmv"
+ },
+ "property": "decode"
+ }
+]