[][src]Struct csr::Caesar

pub struct Caesar { /* fields omitted */ }

The main type of this crate. Holds a key (u8), and provides the methods to encrypt and decrypt Strings, slices, and more!

Methods

impl Caesar[src]

pub fn new<U: AsPrimitive<u8> + Rem>(shift: U) -> Self[src]

Constructs a new Caesar with the provided shift. If the shift isn't valid, this function will get the remainder and shift by that instead.

Examples

use csr::Caesar;

// value is in between 0 and 26 so it is ok!
let c = Caesar::new(2);
use csr::Caesar;

// gets remainder, returning 22
let c = Caesar::new(100);

pub fn encrypt<S: Deref<Target = str>>(self, buf: S) -> String[src]

Encrypts a buffer and consumes the Caesar.

Example

use csr::Caesar;

let c = Caesar::new(2);
let input = "Attack at dawn!";
assert_eq!(c.encrypt(input), "Cvvcem cv fcyp!")

pub fn encrypt_bytes(self, chars: &mut [u8])[src]

This function takes a mutable slice of bytes and encrypts them in place.

Safety

This function is safe because it only guarantees valid UTF-8 bytes if the input is also valid.

Example

use csr::Caesar;

let c = Caesar::new(2);
// "bruh"
let mut bytes = [98, 114, 117, 104];
// "dtwj"
let output = [100, 116, 119, 106];
c.encrypt_bytes(&mut bytes);
assert_eq!(bytes, output);

pub fn decrypt<S: Deref<Target = str>>(self, buf: S) -> String[src]

Decrypts a buffer and consumes the Caesar.

Example

use csr::Caesar;

let c = Caesar::new(2);
let input = "They are coming from the north!";
assert_eq!(c.encrypt(input), "Vjga ctg eqokpi htqo vjg pqtvj!")

pub fn decrypt_bytes(self, chars: &mut [u8])[src]

This function takes a mutable slice of bytes and decrypts them in place.

Safety

This function is safe because it only guarantees valid UTF-8 bytes if the input is also valid.

Example

use csr::Caesar;

let c = Caesar::new(2);
// "skrrt"
let mut bytes = [115, 107, 114, 114, 116];
// "qippr"
let output = [113, 105, 112, 112, 114];
c.decrypt_bytes(&mut bytes);
assert_eq!(bytes, output);

Trait Implementations

impl Clone for Caesar[src]

impl Copy for Caesar[src]

Auto Trait Implementations

impl RefUnwindSafe for Caesar

impl Send for Caesar

impl Sync for Caesar

impl Unpin for Caesar

impl UnwindSafe for Caesar

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.