Project Awesome project awesome

SimpleBaseLib4Pascal

Simple to use Base Encoding Package for Delphi/FreePascal Compilers that provides at the moment support for encoding and decoding various bases such as Base16, Base32 (various variants), Base58 (various variants) and Base64 (various variants) and Base85 (various variants).

Package 51 stars GitHub

SimpleBaseLib4Pascal logo

SimpleBaseLib4Pascal

Base encoding and decoding for Object Pascal

Build Status License: MIT Delphi FreePascal 3.2.2+


SimpleBaseLib4Pascal is a base encoding/decoding library for Object Pascal with support for multiple base families, non-allocating APIs, and stream-based APIs across Delphi and FreePascal.

Table of Contents

Features

  • Base encoding/decoding implementations for common and extended base families.
  • Multiple alphabet variants for several bases (for example Base32, Base58, Base64, Base85).
  • Non-allocating TryEncode/TryDecode APIs for performance-sensitive paths.
  • Stream-based encode/decode support for large inputs.
  • Compatible with both Delphi and FreePascal toolchains.

Available Encodings

  • Base2
  • Base8
  • Base10
  • Base16
  • Base32 (RFC 4648, Crockford, Extended Hex, and more)
  • Base36
  • Base45
  • Base58 (Bitcoin, Ripple, Flickr, Monero variants)
  • Base62
  • Base64 (Default, URL-style variants)
  • Base85 (Ascii85, Z85)

Getting Started

Prerequisites

  • Delphi: 2010 and above
  • FreePascal: 3.2.2 and above

Installation

Delphi

  1. Open package:
    • SimpleBaseLib/src/Packages/Delphi/SimpleBaseLib4PascalPackage.dpk
  2. Build and install the package in the IDE.
  3. Add SimpleBaseLib/src subfolders to your project search path if needed.

FreePascal / Lazarus

  1. Open package:
    • SimpleBaseLib/src/Packages/FPC/SimpleBaseLib4PascalPackage.lpk
  2. Build/install package in Lazarus, or add SimpleBaseLib/src paths to your FPC project.

Quick Examples

Base16 Encode/Decode

uses
  SysUtils, SbpBase16;

var
  LBytes: TBytes;
  LText: String;
begin
  LBytes := TBytes.Create($DE, $AD, $BE, $EF);
  LText := TBase16.UpperCase.Encode(LBytes); // DEADBEEF
  LBytes := TBase16.UpperCase.Decode(LText);
end;

Base64 URL Variant

uses
  SysUtils, SbpBase64;

var
  LData: TBytes;
  LEncoded: String;
begin
  LData := TBytes.Create($FB, $FF, $EF);
  LEncoded := TBase64.Url.Encode(LData);
  LData := TBase64.Url.Decode(LEncoded);
end;

Running Tests

Tests are provided for both Delphi and FreePascal.

  • Delphi: open and run
    • SimpleBaseLib.Tests/Delphi.Tests/SimpleBaseLib.Tests.dpr
  • FreePascal/Lazarus: open and run
    • SimpleBaseLib.Tests/FreePascal.Tests/SimpleBaseLib.Tests.lpi

Tip Jar

If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏

Cryptocurrency Wallet Address
Bitcoin Bitcoin (BTC) bc1quqhe342vw4ml909g334w9ygade64szqupqulmu
Ethereum Ethereum (ETH) 0x53651185b7467c27facab542da5868bfebe2bb69
Solana Solana (SOL) BPZHjY1eYCdQjLecumvrTJRi5TXj3Yz1vAWcmyEB9Miu

License

This project is licensed under the MIT License.

Back to Pascal