Giter Site home page Giter Site logo

base32encoder's Introduction

Base32Encoder

Carthage compatible Build Status codecov

Base32Encoder is a pure Swift library that encodes Data to a Base32 String, and decodes a Base32String to Data.

About

Encodes data as per the [RFC 3548 / RFC 4648] specification for Base32 data encodings.

This library was written for a project that required encoding of small data packets and to learn bit bashing. This means the code is written for learning and has not been optimized for elegance or performance.

Installation

Carthage

Simply add the requirement to your Cartfile: github "markrenaud/Base32Encoder"

Manually

Copy Base32.swift to your project

Usage

If the Base32Encoder was installed as a library, you must import it (this can be skipped if it was manually added to your project). import Base32Encoder

You can then encode data (and optionally pad as per RFC 3548 2.2 - Padding of encoded data)

let data = "hi".data(using: .ascii)!
let base32 = Base32.encode(data: data) // = "NBUQ"
let base32padded = Base32.encode(data: data, padding: true) // = "NBUQ===="

And decode Base32 strings back to dataf

let decodeBase32Data = Base32.decode(string: "NBUQ")
let decodedString = String(data: decodeBase32DataPadded!, encoding: .ascii) // = "hi"

Or you can use the Data and String extensions

let base32 = data.base32String(padded: true) // = "NBUQ===="
if let decoded = try? "NBUQ====".decodeBase32(padded: true) {
    let string = String(data: decoded, encoding: .ascii)    // = "hi"
}

Licence

This project is licensed under the MIT license. See the LICENCE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.