picoCTF Writeup: Rust Fixme 1 - Basic Syntax

picoCTFRustCTF WriteupBeginner

picoCTF Writeup: Rust Fixme 1 - Basic Syntax

tar -xzvf fixme1.tar.gz to unzip

use xor_cryptor::XORCryptor;

fn main() {
    // Key for decryption
    let key = String::from("CSUCKS") // How do we end statements in Rust?

    // Encrypted flag values
    let hex_values = ["41", "30", "20", "63", "4a", "45", "54", "76", "01", "1c", "7e", "59", "63", "e1", "61", "25", "7f", "5a", "60", "50", "11", "38", "1f", "3a", "60", "e9", "62", "20", "0c", "e6", "50", "d3", "35"];

    // Convert the hexadecimal strings to bytes and collect them into a vector
    let encrypted_buffer: Vec<u8> = hex_values.iter()
        .map(|&hex| u8::from_str_radix(hex, 16).unwrap())
        .collect();

    // Create decrpytion object
    let res = XORCryptor::new(&key);
    if res.is_err() {
        ret; // How do we return in rust?
    }
    let xrc = res.unwrap();

    // Decrypt flag and print it out
    let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer);
    println!(
        ":?", // How do we print out a variable in the println function?
        String::from_utf8_lossy(&decrypted_buffer)
    );
}

let key = String::from("CSUCKS") // How do we end statements in Rust? Clearly need a ;

ret; // How do we return in rust? return;

":?", // How do we print out a variable in the println function? "{}", ...

┌──(nirmal㉿NirmalsFLOWX16)-[~/CTF/RustFixme_1/fixme1]
└─$ cargo run
   Compiling rust_proj v0.1.0 (/home/nirmal/CTF/RustFixme_1/fixme1)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/rust_proj`
picoCTF{4r3_y0u_4_ru$t4c30n_n0w?}

After all I did learn many things about rust even though this is my first time. : )

I did the challenges from 3 to 1 btw : (