Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.41 KB

File metadata and controls

91 lines (68 loc) · 3.41 KB

Caesar cipher CLI tool

Implement CLI tool that will encode and decode a text by Caesar cipher.

CLI tool should accept 4 options (short alias and full name):

  1. -s, --shift: a shift
  2. -i, --input: an input file
  3. -o, --output: an output file
  4. -a, --action: an action encode/decode

Details:

Basic Scope

  1. For command-line arguments could be used one of
  1. Action (encode/decode) and the shift are required, if one of them missed - an error should be shown, the process should exit with non-zero status code.
  2. If the input file is missed - use stdin as an input source.
  3. If the output file is missed - use stdout as an output destination.
  4. If the input and/or output file is given but doesn't exist or you can't read it (e.g. because of permissions or it is a directory) - human-friendly error should be printed in stderr.
  5. If passed params are fine the output (file or stdout) should contain encoded/decoded content of input (file or stdin).
  6. For encoding/decoding use only the English alphabet, all other characters should be kept untouched.
  7. Using streams for reading, writing and transformation of text is mandatory.
  8. The tool must work correctly with an integer values of shift (-s, --shift) that are greater than alphabet length.
  9. If any option is duplicated (i.e. bash $ node my_caesar_cli -a encode -s 7 --shift 7) then human-friendly error should be printed in stderr.

Advanced Scope

  1. The tool must work correctly with an integer values of shift (-s, --shift) that are lower than zero.

Hints: As suggested solution to make streams code more robust, and memory effective, consider to use pipeline method. Structure can be the following:

pipeline(
  input_stream, // input file stream or stdin stream
  transform_stream, // Transform stream
  output_stream // output file stream or stdout stream
)
.then(success and error callbacks)

Usage example:

  1. -a (--action) is encode
$ node my_caesar_cli -a encode -s 7 -i "./input.txt" -o "./output.txt"

input.txt This is secret. Message about "_" symbol!

output.txt Aopz pz zljyla. Tlzzhnl hivba "_" zftivs!

$ node my_caesar_cli --action encode --shift 7 --input plain.txt --output encoded.txt

plain.txt This is secret. Message about "_" symbol!

encoded.txt Aopz pz zljyla. Tlzzhnl hivba "_" zftivs!

  1. -a (--action) is decode
    Decoding encoded initial string with the same -s(--shift) number produces the initial string.
$ node my_caesar_cli --action decode --shift 7 --input encoded.txt --output plain.txt

encoded.txt Aopz pz zljyla. Tlzzhnl hivba "_" zftivs!

plain.txt This is secret. Message about "_" symbol!

  1. (Optional) Negative shift handling
$ node my_caesar_cli --action encode --shift -1 --input plain.txt --output encoded.txt

plain.txt This is secret. Message about "_" symbol!

encoded.txt Sghr hr rdbqds. Ldrrzfd zants "_" rxlank!