mixer

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2020 License: MIT Imports: 3 Imported by: 6

README

mixer

go-doc-img travis-img go-report-card-img Coverage Status

Mixer is a very simple encrypt and decrypt golang library for short strings such as id or hash.

Features

  • Security - Support for password(salt) encryption.
  • Symmetrical Support decrypt from the encrypted string.
  • Equal length - The length of the encrypted string is equal to the length of the original string.
  • Simple - The encryption algorithm works by replacing and mixing characters.
  • Custom Support for custom replacement characters.

Install

go get -u github.com/foolin/mixer

Or get the specified version:

go get github.com/foolin/mixer@{version}

The {version} release list: https://github.com/foolin/mixer/releases

Docs

See Mixer

Usage


package main

import (
	"fmt"
	"github.com/foolin/mixer"
)

func main() {

	//password
	salt := "a1b2c3d4"

	//the source to be encrypted
	sources := []string{
		"1234456",
		"12345abcedf",
		"48656c6c6f204d69786572",
	}

	//NewHex(salt string, upper bool) create a new Mixer
	mix := mixer.NewHex(salt, false)

	for _, source := range sources {

		//Encode source data
		encodeData := mix.EncodeString(source)

		//Decode source data
		decodeData := mix.DecodeString(encodeData)

		//Output result
		fmt.Printf("-------\nsource: %v\nencode: %v\ndecode: %v\n-------\n", source, encodeData, decodeData)
	}
}



Run output:


-------
source: 1234456
encode: 72e2308
decode: 1234456
-------
-------
source: 12345abcedf
encode: 47e235f9d0c
decode: 12345abcedf
-------
-------
source: 48656c6c6f204d69786572
encode: 7827858a8629541806bb08
decode: 48656c6c6f204d69786572
-------


Documentation

Index

Constants

View Source
const (
	//CharsCaseAlphanumeric the alphanumeric include upper and lower:`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`
	CharsCaseAlphanumeric = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

	//CharsUpperAlphanumeric the alphanumeric include upper:`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`
	CharsUpperAlphanumeric = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	//CharsLowerAlphanumeric the alphanumeric include lower:`0123456789abcdefghijklmnopqrstuvwxyz`
	CharsLowerAlphanumeric = "0123456789abcdefghijklmnopqrstuvwxyz"

	//CharsUpperAlphabet the upper alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`
	CharsUpperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	//CharsLowerAlphabet the lower alphabet:`abcdefghijklmnopqrstuvwxyz`
	CharsLowerAlphabet = "abcdefghijklmnopqrstuvwxyz"

	//CharsUpperHex the hex alphabet and numeric:`0123456789abcdef`
	CharsUpperHex = "0123456789ABCDEF"

	//CharsLowerHex the hex alphabet and numeric:`0123456789abcdef`
	CharsLowerHex = "0123456789abcdef"

	//CharsNumeric the numeric:`0123456789abcdef`
	CharsNumeric = "0123456789"
)
View Source
const (
	//AlphanumericCase alphanumericType is CharsCaseAlphanumeric
	AlphanumericCase = iota

	//AlphanumericUpper alphanumericType is CharsUpperAlphanumeric
	AlphanumericUpper

	//AlphanumericLower alphanumericType is CharsLowerAlphanumeric
	AlphanumericLower
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mixer

type Mixer struct {
	// contains filtered or unexported fields
}

Mixer a mixer instance for encode/decode

func MustNew

func MustNew(salt string, chars string, candidateChars ...string) *Mixer

MustNew must create a new mixer

func New

func New(salt string, chars string, candidateChars ...string) (*Mixer, error)

New create a new mixer

func NewAlphanumeric

func NewAlphanumeric(salt string, alphanumericType int) *Mixer

NewAlphanumeric must create a new mixer with alphanumeric

func NewHex

func NewHex(salt string, upper bool) *Mixer

NewHex must create a new mixer with hex

func NewNumeric

func NewNumeric(salt string) *Mixer

NewNumeric must create a new mixer with numeric

func (Mixer) Decode

func (m Mixer) Decode(data []rune) []rune

Decode decode char array

func (Mixer) DecodeString

func (m Mixer) DecodeString(data string) string

DecodeString decode string

func (Mixer) Encode

func (m Mixer) Encode(data []rune) []rune

Encode encode char array

func (Mixer) EncodeString

func (m Mixer) EncodeString(data string) string

EncodeString encode string

Directories

Path Synopsis
_examples
basic command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL