caesar_cipher_cli 0.1.2

A CLI tool for encode and decode caesar cipher
#[allow(warnings)]
fn main() {
    use doe::*;
    let args =  args!();

    if let Some(e) = args.get(0){
        if e == "encode"{
            if let Some(f) = args.get(1){
                    for i in 1..27{
                        let se = caesar_cipher_cli_encode(f,i);
                        println!("shift:{},{}",i,se);
                    }
            }else{
                println!("Example:");
                println!("caesar_cipher_cli encode <cipher_code>");
                println!("caesar_cipher_cli decode <cipher_code>");
                println!("caesar_cipher_cli decode_uniqe <cipher_code> <shift_value>");
                println!("caesar_cipher_cli decode_uniqe 'lrua1u'  6");
            }
        }else if e== "decode"{
            if let Some(f) = args.get(1){
                    for i in 1..27{
                        let sd = caesar_cipher_cli_decode(f,i);
                        println!("shift:{},{}",i,sd);
                    }
            }else{
                println!("Example:");
                println!("caesar_cipher_cli encode <cipher_code>");
                println!("caesar_cipher_cli decode <cipher_code>");
                println!("caesar_cipher_cli decode_uniqe <cipher_code> <shift_value>");
                println!("caesar_cipher_cli decode_uniqe 'lrua1u'  6");
            }
        }
        else if e== "decode_uniqe"{
            if let Some(f) = args.get(1){
                if let Some(shift_value) = args.get(2){
                    let shift_value = shift_value.parse::<u32>().expect("shift_value must be u32 number");
                    println!("{}",caesar_cipher_cli_decode_uniqe(f,shift_value));
                }
            }else{
                println!("Example:");
                println!("caesar_cipher_cli encode <cipher_code>");
                println!("caesar_cipher_cli decode <cipher_code>");
                println!("caesar_cipher_cli decode_uniqe <cipher_code> <shift_value>");
                println!("caesar_cipher_cli decode_uniqe 'lrua1u'  6");
            }
        }
    }else{
        println!("Example:");
        println!("caesar_cipher_cli encode <cipher_code>");
        println!("caesar_cipher_cli decode <cipher_code>");
        println!("caesar_cipher_cli decode_uniqe <cipher_code> <shift_value>");
        println!("caesar_cipher_cli decode_uniqe 'lrua1u'  6");
    }
    println!("{}",caesar_cipher_cli_decode_uniqe("lrua{1uy3yj9l-yw9u-48j2-uuj8-36h03706y7u7}",6));
}

fn caesar_cipher_cli_encode(text: &str, shift: u32) -> String {
    let mut result = String::new();

    for c in text.chars() {
        match c {
            'a'..='z' => {
                let code = (c as u8 + shift as u8 - b'a') % 26;
                result.push((code + b'a') as char);
            }
            'A'..='Z' => {
                let code = (c as u8 + shift as u8 - b'A') % 26;
                result.push((code + b'A') as char);
            }
            _ => result.push(c),
        }
    }
    result
}
fn caesar_cipher_cli_decode(text: &str, shift: u32) -> String {
    let mut result = String::new();

    for c in text.chars() {
        match c {
            'a'..='z' => {
                let code = (c as u8 + 26 - shift as u8 - b'a') % 26;
                result.push((code + b'a') as char);
            }
            'A'..='Z' => {
                let code = (c as u8 + 26 - shift as u8 - b'A') % 26;
                result.push((code + b'A') as char);
            }
            _ => result.push(c),
        }
    }
    result
}

///Caesar's variation,If ASCII code is even shifts to the right, and shift to the left when it is odd.
#[allow(warnings)]
fn caesar_cipher_cli_decode_uniqe(text: &str, shift: u32) -> String {
    println!("{}",text);
    let mut result = String::new();

    for c in text.chars() {
        match c {
            'a'..='z' => {
                let mut ascii_code = c as u8;
                if ascii_code %2 !=0{
                    ascii_code+=6;
                }else{
                    ascii_code-=6;
                }
                if ascii_code>'z' as u8{
                    ascii_code = ascii_code - ('z' as u8)+('a' as u8)-1;
                }
                result.push((ascii_code) as char);
            }
            'A'..='Z' => {
                let mut ascii_code = c as u8;
                if ascii_code %2 !=0{
                    ascii_code+=6;
                }else{
                    ascii_code-=6;
                }
                if ascii_code>'Z' as u8{
                    ascii_code = ascii_code - ('Z' as u8)+('A' as u8)-1;
                }
                result.push((ascii_code) as char);
            }
            _ => result.push(c),
        }
    }
    println!("{}",result);
    result
}