1
0
Fork
You've already forked rotx
0
A simple CLI tool to do rotX encryption, written as a C exercise.
  • Shell 50.1%
  • C 49.9%
ilja space 787f85e648 Add tests
We now have a simple Shell script who runs tests.
When there's failures, it will end with exit code 1.
2026年03月17日 19:39:22 +01:00
.gitignore Add .gitignore 2026年03月16日 13:14:17 +01:00
README.md Add tests 2026年03月17日 19:39:22 +01:00
rotx.c Read from stdin 2026年03月16日 13:02:30 +01:00
test.sh Add tests 2026年03月17日 19:39:22 +01:00

A simple CLI tool to do rotX encryption, written as a C exercise.

Usage

RotX encryption takes each letter of a text and replaces it with the letter X places further up the Alphabet. When getting to the end of the alphabet, "Z" will roll over back to "A". It is an encryption scheme who, due its simplicity, is often used as introduction to encryption, and can also be found as puzzle exercises for kids.

The special case of rot3 is also known as Ceasar's cypher because this encryption scheme was known to be used by Julius Ceasar, over 2000 years ago! Another special case is Rot13, because running it twice will lead back to the original message.

Note that RotX is easy to break as it has many weaknesses. Having only 26 possible keys means it's easy to figure out the key. It also doesn't obscure patterns in text, so one can easily guess certain words or letters.

RotX is an example of symmetrical encryption because the key to encrypt and decrypt are the same. Encryption who relies on two different keys for encryption and decryption respectively is called asymmetrical encryption.

  • -k: The key, the number of places further to go in the alphabet for each letter. Defaults to 3
  • -d: Decrypt the message instead of encrypting.

The text to encrypt/decrypt is read from stdin.

Examples:

$ echo "abc ABC!" | ./rotx
def DEF!
$ echo "def DEF!" | ./rotx -d
abc ABC!
$ echo "abc ABC!" | ./rotx -k 13
nop NOP!
$ echo "nop NOP!" | ./rotx -k 13 -d
abc ABC!

Or with files

# Output the encrypted file content to the terminal
./rotx -k 13 < file_to_encrypt.txt
# Capture the output in a file
./rotx -k 13 < file_to_encrypt.txt > file_with_encrypted_content.txt
# Here we use a file for input and output, but we use key 13, and we decrypt instead of encrypting
./rotx -k 13 -d < file_with_encrypted_content.txt > file_with_decrypted_content.txt

Build

To compile the code, you can do

# Compile for production
gcc rotx.c -o rotx
# Optional for development purposes: Compile with extra checks so warnings are output when memory leaks are discovered
gcc -fsanitize=leak rotx.c -o rotx
# Optionally run the tests
./test.sh

Scope

It's really just a simple tool for educational purposes more than anything else. I may or may not play with it and add more things, but who knows.

Contributing

Since it's a personal exercise, I do not expect contributions or anything.

License

You can consider the code available under an EUPL-1.2 license.