python_base_flex

A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.

https://github.com/valerius21/python_base_flex

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.

Basic Info
  • Host: GitHub
  • Owner: valerius21
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 16.6 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

Base-Flex Encoder/Decoder

A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.

Note: If you are looking for a faster, more robust implementation for standart encodings, use the standard library. This library goal is to provide a flexible implementation for custom base-N encodings and alphabets!

Features

  • Support for any base-N encoding with power-of-2 alphabet size
  • Built-in support for common encodings (Base64, Base32)
  • Pre-defined standard alphabets in alphabets module
  • Configurable padding character
  • Optional separators between encoded characters
  • Comprehensive test suite
  • Type hints and detailed documentation
  • Efficient implementation using bitwise operations

Installation

bash pip install base-flex

Usage

```python from baseflex import BaseN from baseflex.alphabets import BASE64ALPHABET, BASE32ALPHABET

Base64 encoding/decoding

base64 = BaseN(list(BASE64_ALPHABET))

Basic encoding/decoding

encoded = base64.encode(b"Hello, World!") decoded = base64.decode(encoded)

Using separators for better readability

base64sep = BaseN(list(BASE64ALPHABET), separator="-") encodedwithsep = base64sep.encode(b"Hello, World!") decodedwithsep = base64sep.decode(encodedwithsep)

Base32 encoding/decoding

base32 = BaseN(list(BASE32ALPHABET)) encodedbase32 = base32.encode(b"Hello, World!") decodedbase32 = base32.decode(encodedbase32)

Custom base-N encoding

You can create your own base-N encoding by providing a custom alphabet

The alphabet length (excluding padding char) must be a power of 2

The last character of the alphabet is the padding character, and every element must be unique!

customalphabet = list("01234567=") # Base8 example base8 = BaseN(customalphabet) encodedbase8 = base8.encode(b"Hello") decodedbase8 = base8.decode(encoded_base8) ```

Project Structure

base_flex/ ├── base_flex/ │ ├── __init__.py │ ├── base_flex.py # Main implementation │ ├── alphabets.py # Pre-defined standard alphabets │ └── tests/ │ ├── __init__.py │ └── test_base_flex.py ├── README.md └── pyproject.toml

Running Tests

The project includes a comprehensive test suite. To run the tests:

bash python -m unittest discover -v && coverage report

Implementation Details

The implementation follows these steps:

Encoding

  1. Converts input bytes to a binary string
  2. Splits the binary string into n-bit chunks
  3. Converts each chunk to a base-N character
  4. Adds padding if necessary
  5. Joins characters with separator (if specified)

Decoding

  1. Removes separators and padding
  2. Converts each character back to its binary representation
  3. Concatenates binary strings
  4. Converts binary string back to bytes

Validation

  • Ensures alphabet length (excluding padding) is a power of 2
  • Checks for duplicate characters in the alphabet
  • Validates input characters during decoding

License

MIT License

Citation

If you use this software, please cite it as below:

APA

Mattfeld, V. (2025). Base-Flex (Version 0.1.0) [Computer software]. https://github.com/valerius21/base-flex

BibTeX

bibtex @software{Mattfeld_Base-Flex_2025, author = {Mattfeld, Valerius}, month = feb, title = {{Base-Flex}}, url = {https://github.com/valerius21/base-flex}, version = {0.1.0}, year = {2025} }

Owner

  • Name: Valerius Mattfeld
  • Login: valerius21
  • Kind: user
  • Location: Göttingen, Germany
  • Company: @elegal-ev @ksb-intax

full-stack developer / computer science and law graduate

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: "Mattfeld"
    given-names: "Valerius"
    orcid: "https://orcid.org/0000-0003-0263-0332"
title: "Base-Flex"
version: 0.1.0
date-released: 2025-02-01
url: "https://github.com/valerius21/base-flex"

GitHub Events

Total
  • Release event: 1
  • Push event: 3
  • Create event: 3
Last Year
  • Release event: 1
  • Push event: 3
  • Create event: 3

Dependencies

poetry.lock pypi
  • coverage 7.6.10
pyproject.toml pypi
  • coverage ^7.6.10
  • python ^3.9