goffx

package module
v0.0.0-...-3dd6032 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 9 Imported by: 0

README

goffx

goffx is a pure go implementation of Format-preserving, Feistel-based encryption (FFX) from https://github.com/emulbreh/pyffx.

Only support sha1 at present. It's no difficult to add other encryption algorithms.

Usage

package main

import (
    "fmt"

    "github.com/Me1onRind/goffx"
)

func main() {
    ie := goffx.Integer("secret-key", 4)
    fmt.Println(ie.Encrypt(1234)) // output 6103 <nil>
    fmt.Println(ie.Decrypt(6103)) // output 1234 <nil>

    se := goffx.String("secret-key", "abc", 6)
    fmt.Println(se.Encrypt("aaabbb")) // output "acbacc" <nil>
    fmt.Println(se.Decrypt("acbacc")) // output "aaabbb" <nil>
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SequenceLengthNoMatch = errors.New("Sequence length is wrong")
	NonAlphabetCharacter  = errors.New("Non Alphabet Character")
)

Functions

This section is empty.

Types

type FFX

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

func NewFFX

func NewFFX(key string, rounds int) *FFX

type IntegerCodecs

type IntegerCodecs struct {
	StringCodecs
}

func Integer

func Integer(ffx string, length int) *IntegerCodecs

func (*IntegerCodecs) Decrypt

func (i *IntegerCodecs) Decrypt(v int) (int, error)

func (*IntegerCodecs) Encrypt

func (i *IntegerCodecs) Encrypt(v int) (int, error)

type StringCodecs

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

func String

func String(ffx, alphabet string, length int) *StringCodecs

func (*StringCodecs) Decrypt

func (s *StringCodecs) Decrypt(v string) (string, error)

func (*StringCodecs) Encrypt

func (s *StringCodecs) Encrypt(v string) (string, error)

Jump to

Keyboard shortcuts

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