fxms

package module
v0.0.0-...-019a9d9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: AGPL-3.0 Imports: 5 Imported by: 1

README

FNV-XOR-Mask-Shuffle Symmetric Encryption Algorithm

This is a Go package that implements the FNV-XOR-Mask-Shuffle symmetric encryption algorithm. This algorithm is a combination of several cryptographic techniques that make it difficult for an attacker to decrypt the data.

Installation

To use this package, you can install it using go get command:

go get -u github.com/NIR3X/fxms

Usage

Here is an example of how to use this package:

package main

import (
	"fmt"
	"github.com/NIR3X/fxms"
)

func main() {
	// Generate a random key
	key := fxms.GenKey()

	// Data to encrypt
	data := []uint8("Hello, World!")

	// Encrypt the data
	encrypted, err := fxms.Encrypt(key, data, fxms.OptimizeDecryption)
	if err != nil {
		panic(err)
	}

	// Decrypt the data
	decrypted, ok, err := fxms.Decrypt(key, encrypted, fxms.OptimizeDecryption)
	if err != nil {
		panic(err)
	}

	if !ok {
		panic("Decryption failed")
	}

	// Print the decrypted data
	fmt.Printf("%s\n", decrypted)
}

License

GNU AGPLv3 Image

This program is Free Software: You can use, study share and improve it at your will. Specifically you can redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Documentation

Index

Constants

View Source
const (
	// HashLen represents the length of the hash.
	HashLen = 8
	// MaskLen represents the length of the mask.
	MaskLen = 16
	// KeyLen represents the length of the key.
	KeyLen = 256

	// OptimizeEncryption is used to optimize encryption.
	OptimizeEncryption Mode = 0
	// OptimizeDecryption is used to optimize decryption.
	OptimizeDecryption Mode = 1
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, src []uint8, mode Mode) ([]uint8, bool, error)

Decrypt decrypts the given source data using the provided key and mode. It returns the decrypted data, a boolean indicating whether the decryption was successful, and an error if any occurred. The key must be a byte slice with a length between 1 and 256. The source data must have a length greater than or equal to MaskLen + HashLen. If the mode is OptimizeEncryption, the source data is unshuffled using the key. If the mode is not OptimizeEncryption, the source data is shuffled using the key.

func Encrypt

func Encrypt(key, src []uint8, mode Mode) ([]uint8, error)

Encrypt encrypts the source data using the provided key and mode. It returns the encrypted data and an error if any. The key must be a byte slice with a length between 1 and 256. The source data must be a byte slice. The mode parameter determines the encryption mode. If mode is OptimizeEncryption, the key and result will be shuffled. If mode is not OptimizeEncryption, the key and result will be unshuffled.

func GenKey

func GenKey() []uint8

GenKey generates a random key of type []uint8. It uses the crypto/rand package to generate a secure random key. The length of the key is determined by the constant KeyLen. Returns the generated key.

Types

type Mode

type Mode uint8

Mode represents the different modes of operation.

Jump to

Keyboard shortcuts

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