BitWiser - A simple library to help you in dealing with bytes, bits and nibbles

Related tags

Encryption BitWiser
Overview

BitWiser

Bitwiser is a collection of methods and properties that makes you work with bits, bytes and nibbles a piece of cake

The project is in early stages of development feel free to make pull requests for more funcionalities

FEATURES

  • No more bit masking. Access single bit values
  • Coverting from bytes array to Data and back has never been easier
  • Print Data into hex string
  • Set, reset, query, toggle each bit
  • Subscript
  • Chaining methods
  • Extensive code coverage
  • Multiplatform: iOS, macOS, tvOS, watchOS, Linux, Windows

INSTALLATION

Use Swift package manager. Add the following dependency to your Package.swift file:

.package(url: "https://github.com/DrAma999/BitWiser.git", from: "0.0.1")

Or simply add the URL from XCode menu Swift packages.

HOW TO USE IT

A Byte is simply a UInt8 that has been extended to access single bit values. A Bit is an enumeration that can assume two values .one or .zero.

 var value = Byte(0b1010_1010)
 let bits = value.bits 
 print(bits)
 // [0, 1, 0, 1, 0, 1, 0, 1]

Note: Bits representation is shown as an array of Bit where the array index 0 represents the least significant bit

After creating a Byte you can read in its position in different ways: Subscript

let bit = value[0]

Method

// Query the value
let bit = value.bit(0)
// Ask if bit is set (equal to one)
let isSet = value.isBitSet(0)

Properties

let bit = value.b0

After creating a mutable Byte you can write in its position in different ways: Subscript

value[0] = 1

Method

// Set the specified bit to 1
value.setBit(0)
// Reset the specified bit to 0
value.resetBit(0)
// Toggle the specified bit. If the bit in position zero is one it becomes zero and viceversa
value.resetBit(0)
// Change the value of the specified bit to one
value.changeBit(0, to: .one )

// Chaining modifiers that return a new value without mutating
let newValue = value
              .settingBit(0)
              .resettingBit(3)
              .togglingBit(4)

Properties

value.b0 = .zero

Pretty sure that if you worked in IOT you had an embedded engineer that put some infomration inside a nibble. With bit wiser you can extract nibbles from a byte:

 let value: Byte = 0b01011111
 let (msb, lsb) = value.nibbles

There are also a lot of methods and facilities to work with bit bites and nibbles.

CONTRIBUTING

Since I'm working on this project in my spare time any help is appreciated. Feel free to make a pull request.

THANKS

Icon made by  Freepik  from  www.flaticon.com

LICENSE

MIT License

Copyright (c) 2021 Andrea Finollo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
Util for generation RSA keys on your client and save to keychain or convert into Data 🔑 🔐

RSASwiftGenerator 🔑 🔐 To run the example project, clone the repo, and run pod install from the Example directory first. Requirements ⚠️ SWIFT 4 XCod

A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. 💡 Please note that this implementation of

A KeePass/Password Safe Client for iOS and OS X

Strongbox A Personal Password Manager for iOS & OSX that can be found on the Apple App Store here: https://apps.apple.com/app/strongbox-password-safe/

Fluetooth - Flutter library for sending bytes to Bluetooth devices on Android/iOS

A Flutter library for sending bytes to Bluetooth devices. Available on Android a

Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

Makes dealing with images buttery smooth.
Makes dealing with images buttery smooth.

ImageButter Image viewer for iOS that supports WebP. What is WebP? Find out more here. You can find more about why we created this here. Features Anim

An Xcode plugin to improve dealing with colors in your project
An Xcode plugin to improve dealing with colors in your project

Crayons is an Xcode7 plugin with various features that improve working with colors in your projects ##Code palettes (iOS only) You can share palettes

RadarKit - The Radar Kit allowing you to locate places, trip neary by you Or it will help you to search out the people around you with the few lines of code A platform where NYUAD students can both Help and Seek Help.
A platform where NYUAD students can both Help and Seek Help.

A platform where NYUAD students can both Help and Seek Help.

A guard to help you check if you make UI changes not in main thread
A guard to help you check if you make UI changes not in main thread

ODUIThreadGuard ODUIThreadGuard is a guard to help check if you make UI changes not in main thread. As Xcode 9 embedded this function into Xcode, ther

A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud written in Swift.

Elastic Path Commerce Cloud iOS Swift SDK A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elasti

Simple examples that help you get started with Appwrite + Apple with SwiftUI (=❤️)
Simple examples that help you get started with Appwrite + Apple with SwiftUI (=❤️)

Appwrite's Apple Playground 🎮 Appwrite playground is a simple way to explore the Appwrite API & Appwrite Apple SDK. Use the source code of this repos

Simple examples that help you get started with Appwrite + Swift for Server (=❤️)

Playground for Swift Simple examples that help you get started with Appwrite + Swift (= ❤️ ) This is Appwrite server side integration with Swift. For

A Simple way help you drop or drag your source (like UIImage) between different App.

A Simple way help you drop or drag your source (like UIImage) between different App.

📱💬🚦 TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.
📱💬🚦 TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.

TinyConsole TinyConsole is a tiny log console to display information while using your iOS app and written in Swift. Usage Wrap your Main ViewControlle

NotSwiftUI is designed to help you create UI components quickly and efficiently with code!
NotSwiftUI is designed to help you create UI components quickly and efficiently with code!

NotSwiftUI NotSwiftUI is designed to help you create UI components quickly and efficiently with code! Capitalizing on the idea that most of the UI ele

An open-source app which can help you record income and expense
An open-source app which can help you record income and expense

MoneyPlus An open-source app which can help you record income and expense. 中文 0x00 Introduction First quick devolopment in iOS using Swift programmati

👶🏻 An iOS app to help you track sleep, feedings and diaper change for your baby
👶🏻 An iOS app to help you track sleep, feedings and diaper change for your baby

🐣 Maby Maby is an iOS/watchOS open-source app to help you keep track of your baby's sleep, feedings, diaper changes and more to avoid the constant qu

Swiftline is a set of tools to help you create command line applications
Swiftline is a set of tools to help you create command line applications

Swiftline is a set of tools to help you create command line applications. Swiftline is inspired by highline Swiftline contains the following: Colorize

Comments
  • Bit, Nibble, Byte, Word in DSL

    Bit, Nibble, Byte, Word in DSL

    Create a DSL similar to SwiftUI language using resultBuilder, that helps in create bit, byte, word with specific operation modifier. Something similar to:

    Byte {
      Bit(0)
      Bit(1)
      Bit(0)
      Bit(1)
    } // will produce 000001010
    .masked(0b0000_0000)
    

    @samueleperricone what do you think? can it be useful?

    enhancement 
    opened by DrAma999 4
  • Use of result builders to create a DSL for byte arrays and data objects

    Use of result builders to create a DSL for byte arrays and data objects

    A DSL to create Data and array of byte has been created. It supports if, else and for loops. It also supports DataConvertible protocol. Any object that conforms to that protocol can become part of the DSL in creating a full Data object. For instance this is valid:

    Data {
           [UInt8(0)]
            UInt8(1)
            Int8(2)
            "\u{03}"
            Int16(1284)
            if dataClause {
                CustomData()
            }
    }
    

    Closes #3

    opened by DrAma999 1
  • DSL Style for Byte Array Creation

    DSL Style for Byte Array Creation

    Thanks to the ByteArrayBuilder now byte arrays and Data can be created using a specific DSL. It also supports if, if else and for loops, see Unit Test for more detail As an example this is valid:

    Data {
            [Byte(0x00)]
            Byte(0x01)
            0x02
            [UInt8(0x03)]
            if clause {
                [UInt8](repeating: 0x04, count: 1)
            }
    }
    

    also this:

    Array<Byte> {
            [Byte(0x00)]
            Byte(0x01)
            0x02
            [UInt8(0x03)]
            if clause {
                [UInt8](repeating: 0x04, count: 1)
            }
    }
    
    enhancement 
    opened by DrAma999 0
Releases(0.0.3)
  • 0.0.3(Feb 8, 2022)

    What's Changed

    • DSL Style for Byte Array Creation by @DrAma999 in https://github.com/DrAma999/BitWiser/pull/4
    • Use of result builders to create a DSL for byte arrays and data objects by @DrAma999 in https://github.com/DrAma999/BitWiser/pull/5

    Full Changelog: https://github.com/DrAma999/BitWiser/compare/0.0.2...0.0.3

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Jan 14, 2022)

    What's Changed

    • Computed properties to convert integers to bytes by @codingspark in https://github.com/DrAma999/BitWiser/pull/1
    • A little bit of lint for Code Factor by @DrAma999 in https://github.com/DrAma999/BitWiser/pull/2

    New Contributors

    • @codingspark made their first contribution in https://github.com/DrAma999/BitWiser/pull/1
    • @DrAma999 made their first contribution in https://github.com/DrAma999/BitWiser/pull/2

    Full Changelog: https://github.com/DrAma999/BitWiser/compare/0.0.1...0.0.2

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Dec 30, 2021)

Owner
Andrea Finollo
S.O.: https://stackoverflow.com/story/andreafinollo TW: https://twitter.com/DrAma78
Andrea Finollo
Simple and secure hashing in Swift with the SipHash algorithm

SipHash ⚠️ WARNING This package has been obsoleted by the Hasher type and the Hashable.hash(into:) requirement introduced in Swift 4.2. Using this pac

null 262 Dec 19, 2022
A wrapper for Apple's Common Crypto library written in Swift.

IDZSwiftCommonCrypto A Swift wrapper for Apple's CommonCrypto library. IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on

idz 472 Dec 12, 2022
Demonstration library for using the Secure Enclave on iOS

SecureEnclaveCrypto This project shows you how to create a keypair where as the private key is stored in the secure enclave sign a string / some data

Trail of Bits 272 Jan 7, 2023
Safe and easy to use crypto for iOS and macOS

Swift-Sodium Swift-Sodium provides a safe and easy to use interface to perform common cryptographic operations on macOS, iOS, tvOS and watchOS. It lev

Frank Denis 483 Jan 5, 2023
A tiny and easy to use Swift class to encrypt strings using HMAC algorithms.

#Sweet HMAC SweetHMAC is a tiny and easy to use Swift class to encrypt strings using HMAC algorithms. A special thanks to jernejstrasner for shared HM

Jan Cássio 37 Jul 27, 2022
RSA public/private key generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X

SwCrypt Create public and private RSA keys in DER format let (privateKey, publicKey) = try! CC.RSA.generateKeyPair(2048) Convert them to PEM format l

soyer 695 Dec 8, 2022
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Dec 30, 2022
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift

CryptoSwift Crypto related functions and helpers for Swift implemented in Swift. (#PureSwift) Note: The main branch follows the latest currently relea

Marcin Krzyzanowski 9.4k Jan 9, 2023
CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

null 3.3k Jan 7, 2023
An easy way for hashing and encryption.

CatCrypto include a series of hashing and encryption functions and more functions in progress! CatCrypto also contains Swift bindings of Argon2, the p

Kcat 62 Sep 27, 2022