You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Michele Sessa 31e7b8dcd6 docs(cipher): fix typos and remove useless notions 2 years ago
..
README.md docs(cipher): fix typos and remove useless notions 2 years ago

README.md

cipher

Instructions

The Atbash cipher is an encryption method in which each letter of a word is replaced by its mirror letter in the alphabet.

Your objective is to create a function named cipher which must return a Result wrapped in an Option. The Result should contain either a boolean or an Error based on the CipherError structure. This structure should be the error type for the function cipher.

cipher should compare the original String with the ciphered String. It should return true if the cipher is correct. If the cipher is incorrect it should return the error type CipherError with a boolean and the expected atbash cipher String.

Expected Function and structure


#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CipherError {
    // expected public fields
}
impl CipherError {
    pub fn new(validation: bool, expected: String) -> CipherError {

    }
}
pub fn cipher(original: &str, ciphered: &str) -> Option<Result<bool, CipherError>> {

}

Usage

Here is a program to test your function:

use cipher::*;

fn main() {
    println!("{:?}", cipher("1Hello 2world!", "1Svool 2dliow!"));
    println!("{:?}", cipher("1Hello 2world!", "svool"));
    println!("{:?}", cipher("", "svool"));
}

And its output:

$ cargo run
Some(Ok(true))
Some(Err(CipherError { validation: false, expected: "1Svool 2dliow!" }))
None
$