Skip to content

Latest commit

 

History

History
122 lines (86 loc) · 2.84 KB

README.md

File metadata and controls

122 lines (86 loc) · 2.84 KB

🏛 Caesar Cipher CLI 🏛

This is an implementation of the historic caesar cipher. This serves mostly as an academic exercise which helped me to learn many of the Rust topics. In order to maximize learnings, a decision to just use the standard library was made.

Important: Users are encouraged to generally use modern cryptography instead ⚠


caesar caesar

Images by Wikipedia

Features

  • Support for the ascii alphabet. Other characters will be just omitted for processing, but included in the output.
  • Encrypt from stdin.
  • Encrypt from an input file.
  • Output will be written to stdout by default. Users can also specify an output file.
  • It supports positional overflow in the shift operation. The key (shift) can be a 6-digit number at a maximum.
  • It loads everything into memory. No streaming support, yet.

How to install

You will need a Rust installation as prerequisite.

Then just clone and install with:

git clone https://github.com/eloylp/rust-lab.git
cargo --install rust-lab/caesar

Great ! now you can execute caesar -h

$ caesar -h

🏛 Caesar Cipher 🏛

WARNING: Users are encouraged to use modern cryptography instead of this tool.
This was made for academic purposes with ❤ 🦀

Only -k argument is mandatory. If no other argument is provided stdin/stdout and
encryption mode are assumed.

Arguments:

-h     Shows this menu.
-v     Shows the version.
-k     The key, or positive shift number of the cipher (mandatory). Max is a 6 digit number.
-o     Write results to specified file.
-i     Specify path to input file.
-e     Encryption mode. (default).
-d     Decryption mode.

Here's a full example command:

$ caesar -k 10 -i input.txt -o output.txt -e

Common usages

Reading from stdin, write to stdout

For encryption:

$ echo "ABC" | caesar -k 1
BCD

For decryption:

$ echo "BCD" | caesar -k 1 -d
ABC

Reading from input file, write to stdout

For encryption:

$ echo "ABC" > sample.txt
$ caesar -i sample.txt -k 1
BCD

For decryption:

$ echo "BCD" > encrypted.txt
$ caesar -i encrypted.txt -k 1 -d
ABC

Reading from input file, write result to output file

For encryption:

$ echo "ABC" > plain.txt
$ caesar -k 1 -i plain.txt -o encrypted.txt
$ cat encrypted.txt
BCD

For decryption:

$ echo "BCD" > encrypted.txt
$ caesar -k 1 -d -i encrypted.txt -o plain.txt
$ cat plain.txt
ABC