Giter Club home page Giter Club logo

rabbitio's Introduction

rabbitio

rabbitio is a rabbit stream cipher packge based on RFC 4503 for golang
rabbit is a super-fast lightweight stream cipher which uses a 128-bit key and a 64-bit initialization vector, this cipher was designed in 2003 and released in 2008

this is a mirror repository, rabbitio also lives on snix.ir public git service

usage and docs

simple encrypt/decrypting plain text and cipher text with rabbitio
key must be exactly 16 byte len, iv is optional but must be either zero (for nothing) or 8 byte len
you can replace "snix.ir/rabbitio" with "github.com/sina-ghaderi/rabbitio" to use github mirror repository

package main
import (
  "encoding/hex"
  "fmt"
  
  "snix.ir/rabbitio"
)


func main() {
    key := []byte("key-gen-rabbitio")
    ivx := []byte("abcd8795")
    ptx := "plain text -- dummy text to encrypt and decrypt with rabbit"
    str, err := rabbitio.NewCipher(key, ivx)
    if err != nil { panic(err) }
  
    cpt := make([]byte, len(ptx))
    str.XORKeyStream(cpt, []byte(ptx))
    fmt.Println("cipher text ---:", hex.EncodeToString(cpt))
  
    str, err = rabbitio.NewCipher(key, ivx)
    if err != nil { panic(err) }
  
    // decrypt cipher text and print orginal text
    plx := make([]byte, len(cpt))
    str.XORKeyStream(plx, cpt)
    fmt.Println("plain text ----:", string(plx))
}

io interfaces, reader and writer methods: working with writer

package main
import (
	"bytes"
	"encoding/hex"
	"fmt"
	"io"
	"strings"

	"snix.ir/rabbitio"
)

func main() {
	key, ivt := []byte("12345678abcdefgh"), []byte("1234qwer")
	txt := "dummy text to test NewWriterCipher"
	twr := strings.NewReader(txt)
	iw := new(bytes.Buffer)
	cw, err := rabbitio.NewWriterCipher(key, ivt, iw)
	if err != nil {
		panic(err)
	}
	if _, err := io.Copy(cw, twr); err != nil {
		panic(err)
	}
	fmt.Println("cipher-text:", hex.EncodeToString(iw.Bytes()))
	fmt.Println("decrypting cipher text ---")
	ir := new(bytes.Buffer)
	cr, err := rabbitio.NewWriterCipher(key, ivt, ir)
	if err != nil {
		panic(err)
	}
	if _, err := io.Copy(cr, iw); err != nil {
		panic(err)
	}
	fmt.Println(ir.String())
}

io interfaces, reader and writer methods: working with reader

package main
import (
	"bytes"
	"encoding/hex"
	"fmt"
	"io"
	"strings"

	"snix.ir/rabbitio"
)

func main() {
	key, ivt := []byte("12345678abcdefgh"), []byte("1234qwer")
	txt := "test NewReadercipher text dummy tx"
	twr := strings.NewReader(txt)
	iw := new(bytes.Buffer)
	cw, err := rabbitio.NewReaderCipher(key, ivt, twr)
	if err != nil {
		panic(err)
	}
	if _, err := io.Copy(iw, cw); err != nil {
		panic(err)
	}
	fmt.Println("cipher-text:", hex.EncodeToString(iw.Bytes()))
	fmt.Println("decrypting cipher text ---")
	ir := new(bytes.Buffer)
	cr, err := rabbitio.NewReaderCipher(key, ivt, iw)
	if err != nil {
		panic(err)
	}
	if _, err := io.Copy(ir, cr); err != nil {
		panic(err)
	}
	fmt.Println(ir.String())
}

test and benchmarking

unit test and benchmarking provided too, run go test -v or go test -bench=. -benchmem on project root directory

feel free to email me [email protected] if you want to contribute to this project

Copyright 2022 SNIX LLC [email protected] Apache License

rabbitio's People

Contributors

sina-ghaderi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.