zwc

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

ZWC

zwc is a program for encoding arbritary data into zero‐width utf‐8 characters and decoding it back. These zero‐width characters are not rendered as visible chracters. These zero‐width characters are then placed inside a message, hiding the data within the message.

Compiling

Create the executable 'zwc' in the project directory.

make

Alternatively,

go build -o zwc main/main.go

Usage

man ./doc/zwc.1

Copyright (C) 2023 Ethan Cheng <ethanrc0528@gmail.com>
License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Documentation

Overview

Package zwc implements the encoding/decoding of files in the ZWC format

Index

Constants

View Source
const (
	V1DelimChar     = '\u034F'
	V1DelimCharUTF8 = "\xcd\x8f"
)

Variables

View Source
var (
	CRC8 = &crc.Parameters{
		Width:      8,
		Polynomial: 0x07,
		Init:       0x00,
		ReflectIn:  false,
		ReflectOut: false,
		FinalXor:   0x00,
	}

	CRC16 = &crc.Parameters{
		Width:      16,
		Polynomial: 0x1021,
		Init:       0x0000,
		ReflectIn:  false,
		ReflectOut: false,
		FinalXor:   0x0000,
	}

	CRC32 = &crc.Parameters{
		Width:      32,
		Polynomial: 0x04C11DB7,
		Init:       0xFFFFFFFF,
		ReflectIn:  true,
		ReflectOut: true,
		FinalXor:   0xFFFFFFFF,
	}
)

Functions

func CRC2

func CRC2(message byte) byte

CRC2 takes an augmented message (6-bit message + 2-bit CRC) and returns the 2-bit crc

func DecodeHeader

func DecodeHeader(src []byte) (version, encodingType, checksumType int, err error)

DecodeHeader takes an encoded header with or without any delim chars and returns the encoding settings for the payload and checksum. These can then be passed to NewEncoding to create an Encoding.

func DecodeHeaderFromReader

func DecodeHeaderFromReader(r io.Reader) (version, encodingType, checksumType int, err error)

func GuessEncodingType

func GuessEncodingType(p []byte) int

GuessEncodingType uses heuristics to guess the encoding of the payload

func NewCatDecoder

func NewCatDecoder(r io.Reader) io.Reader

func NewCustomDecoder

func NewCustomDecoder(enc *Encoding, r io.Reader) io.Reader

NewCustomDecoder requires an Encoding, meaning the header must be decoded beforehand. r must contain only the data + delim + checksum

func NewDecoder

func NewDecoder(r io.Reader) io.Reader

NewDecoder creates a decoder which decodes the header from r, therefore it doesn't require an Encoding. It takes the entirety of the encoded data and no preprocessing is need. If you want to override the encoding settings use NewCustomDecoder.

func NewEncoder

func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser

func ValidEncoding

func ValidEncoding(version, encodingType, checksumType int) (err error)

Types

type CorruptHeaderError

type CorruptHeaderError struct {
	HeaderLength int  // length of the decoded header in bits
	CRCFail      bool // crc failed
	// contains filtered or unexported fields
}

func (CorruptHeaderError) Error

func (e CorruptHeaderError) Error() string

type CorruptPayloadError

type CorruptPayloadError struct {
	NotValidUTF8        bool // payload contains no utf8 characters
	IncompleteByte      bool // decoding resulted in an incomplete byte
	ShortCRC            bool // decoded crc is too short
	CRCFail             bool // checksum doesn't match calculated crc
	NoDelimChar         bool // no delim char between payload and checksum
	UnexpectedDelimChar bool // delim char after checksum (use NewCatDecoder)
	// contains filtered or unexported fields
}

func (CorruptPayloadError) Error

func (e CorruptPayloadError) Error() string

type Encoding

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

func NewCustomEncoding

func NewCustomEncoding(table [16]string, delimChar rune, version, encodingType, checksumType int) *Encoding

func NewEncoding

func NewEncoding(version, encodingType, checksumType int) *Encoding

func (*Encoding) Checksum

func (enc *Encoding) Checksum() uint64

func (*Encoding) ChecksumType

func (enc *Encoding) ChecksumType() int

func (*Encoding) Decode

func (enc *Encoding) Decode(dst, src []byte) (n, m int, err error)

Decode decodes the data + delim + checksum in src and writes it to dst. This function can only be used after decoding the header with DecodeHeader and creating an Encoding. n is the number of bytes written to dst and m is the number of bytes read from src.

func (*Encoding) DecodeChecksum

func (enc *Encoding) DecodeChecksum(p []byte) (checksum uint64, m int, err error)

DecodeChecksum decodes the checksum in p and returns the checksum. If the checksum is decoded successfully and the checksum matches, err is nil. m is the number of bytes read from p.

func (*Encoding) DecodePayload

func (enc *Encoding) DecodePayload(dst, src []byte) (n, m int, err error)

DecodePayload decodes the payload in src and writes it to dst. n is the number of bytes written to dst and m is the number of bytes read from src.

func (*Encoding) DecodedPayloadMaxLen

func (enc *Encoding) DecodedPayloadMaxLen(n int) int

DecodedPayloadMaxLen returns the maximum length of the decoded payload where n is the length of the encoded payload

func (*Encoding) DelimCharAsUTF8

func (enc *Encoding) DelimCharAsUTF8() []byte

DelimCharAsUTF8 is a convenience function which returns the delimChar as a UTF8 encoded slice of bytes

func (*Encoding) Encode

func (enc *Encoding) Encode(dst, src []byte) int

func (*Encoding) EncodeChecksum

func (enc *Encoding) EncodeChecksum(dst []byte) int

func (*Encoding) EncodeHeader

func (enc *Encoding) EncodeHeader(dst []byte) int

func (*Encoding) EncodePayload

func (enc *Encoding) EncodePayload(dst, src []byte) int

func (*Encoding) EncodedChecksumMaxLen

func (enc *Encoding) EncodedChecksumMaxLen() int

EncodedChecksumLen returns the maximum length in bytes of the encoded ZWC checksum

func (*Encoding) EncodedHeaderLen

func (enc *Encoding) EncodedHeaderLen() int

EncodedHeaderLen returns the length in bytes of the encoded ZWC header

func (*Encoding) EncodedMaxLen

func (enc *Encoding) EncodedMaxLen(n int) int

EncodedLen returns the maximum length in bytes of the encoded ZWC file

func (*Encoding) EncodedPayloadMaxLen

func (enc *Encoding) EncodedPayloadMaxLen(n int) int

EncodedPayloadLen returns the maximum length in bytes of the encoded ZWC payload

func (*Encoding) EncodingType

func (enc *Encoding) EncodingType() int

func (*Encoding) Version

func (enc *Encoding) Version() int

type InvalidEncodingError

type InvalidEncodingError struct {
	InvalidVersion      bool
	InvalidEncodingType bool
	InvalidChecksumType bool
	// contains filtered or unexported fields
}

func (InvalidEncodingError) Error

func (e InvalidEncodingError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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