Struct CharCodec

Source
pub struct CharCodec<T> { /* private fields */ }
Expand description

A codec that encodes data of type char.

The encoding is done by substituting with two given elements (elem_a and elem_b) of type T.

The substitution is done using the first version of the Bacon’s cipher.

Implementations§

Source§

impl<T> CharCodec<T>

Source

pub fn new(elem_a: T, elem_b: T) -> CharCodec<T>

Create a new CharCodec using elements elem_a and elem_b for substitution.

Trait Implementations§

Source§

impl<T: PartialEq + Clone> BaconCodec for CharCodec<T>

Source§

type ABTYPE = T

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

type CONTENT = char

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

fn encode_elem(&self, elem: &char) -> Vec<T>

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

fn decode_elems(&self, elems: &[T]) -> char

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

fn a(&self) -> T

Returns the A substitution element.
Source§

fn b(&self) -> T

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. Read more
Source§

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

Tests whether an element equals with the A substitution element.
Source§

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

Tests whether an element equals with the B substitution element.
Source§

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

Encode an array of some type Self::CONTENT Read more
Source§

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

Decode an array of some type Self::ABTYPE. Read more
Source§

impl<T: Clone> Clone for CharCodec<T>

Source§

fn clone(&self) -> CharCodec<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for CharCodec<char>

Source§

fn default() -> CharCodec<char>

A CharCodec with CONTENT=char, A='A' and B='B'

It encodes the following secret: ['M', 'y', ' ', 's', 'e', 'c', 'r', 'e', 't'] is

To: [‘a’, ‘b’, ‘a’, ‘b’, ‘b’, ‘b’, ‘a’, ‘b’, ‘b’, ‘a’, ‘b’, ‘a’, ‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘b’, ‘a’, ‘b’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘a’]

Source§

impl<T: PartialEq> PartialEq for CharCodec<T>

Source§

fn eq(&self, other: &CharCodec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for CharCodec<T>

Auto Trait Implementations§

§

impl<T> Freeze for CharCodec<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for CharCodec<T>
where T: RefUnwindSafe,

§

impl<T> Send for CharCodec<T>
where T: Send,

§

impl<T> Sync for CharCodec<T>
where T: Sync,

§

impl<T> Unpin for CharCodec<T>
where T: Unpin,

§

impl<T> UnwindSafe for CharCodec<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.