Trait BaconCodec

Source
pub trait BaconCodec {
    type ABTYPE;
    type CONTENT;

    // Required methods
    fn encode_elem(&self, elem: &Self::CONTENT) -> Vec<Self::ABTYPE>;
    fn decode_elems(&self, elems: &[Self::ABTYPE]) -> Self::CONTENT;
    fn a(&self) -> Self::ABTYPE;
    fn b(&self) -> Self::ABTYPE;
    fn encoded_group_size(&self) -> usize;
    fn is_a(&self, elem: &Self::ABTYPE) -> bool;
    fn is_b(&self, elem: &Self::ABTYPE) -> bool;

    // Provided methods
    fn encode(&self, input: &[Self::CONTENT]) -> Vec<Self::ABTYPE> { ... }
    fn decode(&self, input: &[Self::ABTYPE]) -> Vec<Self::CONTENT> { ... }
}
Expand description

A codec that enables encoding and decoding based on the Bacon’s cipher

Required Associated Types§

Source

type ABTYPE

The type of the substitution characters A and B that produce a cipher output like ABABBBABBABAAABAABAAAAABABAAAAAABAABAABAABABBAABAABAAABBAAABAAAAAAABBAAABAA

Can be char, bool or whatever

Source

type CONTENT

The type of the content to be encoded to or decoded.

Required Methods§

Source

fn encode_elem(&self, elem: &Self::CONTENT) -> Vec<Self::ABTYPE>

Encodes a single emenent of Self::CONTENT to a Vec of Self::ABTYPE.

Source

fn decode_elems(&self, elems: &[Self::ABTYPE]) -> Self::CONTENT

Decode an array of elements to produce one element of Self::CΟΝΤΕΝΤ

Source

fn a(&self) -> Self::ABTYPE

Returns the A substitution element.

Source

fn b(&self) -> Self::ABTYPE

Returns the B substitution element.

Source

fn encoded_group_size(&self) -> usize

Returns the the size of the group of elements that represent a content encoding.

E.g.: For the default Bacon’s cipher, this is 5.

Source

fn is_a(&self, elem: &Self::ABTYPE) -> bool

Tests whether an element equals with the A substitution element.

Source

fn is_b(&self, elem: &Self::ABTYPE) -> bool

Tests whether an element equals with the B substitution element.

Provided Methods§

Source

fn encode(&self, input: &[Self::CONTENT]) -> Vec<Self::ABTYPE>

Encode an array of some type Self::CONTENT

E.g. For CONTENT=char, ABTYPE=char, a='A' and b='B', the encoding of ['M','y',' ','s','e','c','r','e','t'] is ABABBBABBABAAABAABAAAAABABAAAAAABAABAABA

Source

fn decode(&self, input: &[Self::ABTYPE]) -> Vec<Self::CONTENT>

Decode an array of some type Self::ABTYPE.

E.g. For CONTENT=char, ABTYPE=char, a='A' and b='B', the decoding of ABABBBABBABAAABAABAAAAABABAAAAAABAABAABA is ['M','Y','S','E','C','R','E','T']

Implementors§