Skip to main content

Spiral Cipher Documentation

PyPI

The Spiral Cipher is a Python package for text encryption and decryption using a spiral pattern. It writes text in a spiral pattern within a square matrix and reads it back row by row for encoding. The reverse process is used for decoding. The package also supports file-based encryption/decryption and customizable encryption keys.


Features

  • Text Encryption/Decryption: Encrypt and decrypt text using a spiral pattern.
  • File Encryption/Decryption: Encrypt and decrypt files.
  • Customizable Key: Use a key to shift characters for additional security.
  • UTF-8 Support: Works with Unicode characters.
  • Command-Line Interface (CLI): Easy-to-use CLI for text and file operations.
  • Python API: Programmatic access to encryption/decryption functions.

Installation

Install the package using pip:

pip install spiral-cipher

Usage

Python API

The package provides a Python API for programmatic usage.

1. Encoding and Decoding Text

from spiral_cipher import encode, decode

# Encode text
encoded_text = encode("Hello, World!", key=1111) # any key : int , ex : 9999999
print(encoded_text)  # Output: "AxeeQQQhew!,khP"

# Decode text
decoded_text = decode(encoded_text, key=1111)
print(decoded_text)  # Output: "Hello, World!"

2. Using the SpiralCipher Class

from spiral_cipher import SpiralCipher

# Initialize the cipher with a key
cipher = SpiralCipher(key=3)

# Encode text
encoded_text = cipher.encode("Hello, World!")
print(encoded_text)  # Output: "KhooAAArog!,urZ"

# Decode text
decoded_text = cipher.decode(encoded_text)
print(decoded_text)  # Output: "Hello, World!"

# Encrypt a file
cipher.encrypt_file("input.txt", "encrypted.txt")

# Decrypt a file
cipher.decrypt_file("encrypted.txt", "decrypted.txt")

Command-Line Interface (CLI)

The package provides a CLI for easy text and file processing.

1. Text Processing

# Encode text
spiral-cipher encode "Hello, World!" -k 3

# Decode text
spiral-cipher decode "KhooAAArog!,urZ " -k 3 #don't miss space +_+

2. File Processing

# Encrypt a file
spiral-cipher encode input.txt -f -o encrypted.txt -k 3

# Decrypt a file
spiral-cipher decode encrypted.txt -f -o decrypted.txt -k 3

3. CLI Options

Argument Description
action Action to perform (encode or decode)
input Text to process or input file path
-k, --key Encryption key (default: 1)
-f, --file Treat input as a file path
-o, --output Output file path (required for file operations)
-h, --help Show help message

How It Works

Encryption Process

  1. Create a Square Matrix:

    • The input text is padded (if necessary) to fit into the smallest square matrix.
  2. Write Text in Spiral Pattern:

    • The text is written in a spiral pattern (clockwise or counterclockwise) within the matrix.
  3. Shift Characters:

    • Each character is shifted by the key value for additional security.
  4. Read Row by Row:

    • The matrix is read row by row to generate the encrypted text.

Decryption Process

  1. Create a Square Matrix:

    • The encrypted text is placed into a square matrix.
  2. Read Text in Spiral Pattern:

    • The text is read in the reverse spiral pattern.
  3. Unshift Characters:

    • Each character is unshifted by the key value.
  4. Remove Padding:

    • Padding characters are removed to retrieve the original text.

Examples

Example 1: Encoding and Decoding Text

from spiral_cipher import encode, decode

# Encode text
encoded = encode("Hello, World!", key=3)
print(encoded)  # Output: "Khoog$ro/urZ#"

# Decode text
decoded = decode(encoded, key=3)
print(decoded)  # Output: "Hello, World!"

Example 2: File Encryption and Decryption

from spiral_cipher import SpiralCipher

# Initialize the cipher
cipher = SpiralCipher(key=3)

# Encrypt a file
cipher.encrypt_file("input.txt", "encrypted.txt")

# Decrypt a file
cipher.decrypt_file("encrypted.txt", "decrypted.txt")

Example 3: CLI Usage

# Encode text
spiral-cipher encode "hellow" -k 3

# Decode text
spiral-cipher decode "khoAAoAzr" -k 3

# Encrypt a file
spiral-cipher encode input.txt -f -o encrypted.txt -k 3

# Decrypt a file
spiral-cipher decode encrypted.txt -f -o decrypted.txt -k 3

Development

1. Clone the Repository

git clone https://github.com/ishanoshada/spiral-cipher.git
cd spiral-cipher

2. Install in Development Mode

pip install -e .

3. Run Tests

python -m unittest discover tests

License

This project is licensed under the MIT License. See the LICENSE file for details.


Author


Links


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Repository Views Views

Metadata

Release files for spiral-cipher 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spiral-cipher 0.1.2
File Size Uploaded
spiral_cipher-0.1.2.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spiral-cipher 0.1.2
File Interpreter ABI Platform
spiral_cipher-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / spiral_cipher-0.1.2.tar.gz

Download URL spiral_cipher-0.1.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
db1aad5c5d25a5dddf69b166b0d0dc03014f846ddaeaedf70b6fcca6b9fda43d
BLAKE2b-256 checksum
How to use checksums
d0f2a2f1102989aba761ba3cc52a96c6e16b861808a819f553deb276f298810c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / spiral_cipher-0.1.2-py3-none-any.whl

Download URL spiral_cipher-0.1.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
971f44262f16ebb1c3eda70cd6a1eb521b6d53ebc5785b7441d0f63b57045332
BLAKE2b-256 checksum
How to use checksums
2a49fbe37ce30d8b7bdd265979e2c79b8b1e02e5abeeec4b0d491f9e28b4e19c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page