diff --git a/misc/rust_fixme_2/Cargo.lock b/misc/rust_fixme_2/Cargo.lock new file mode 100644 index 0000000..f719783 --- /dev/null +++ b/misc/rust_fixme_2/Cargo.lock @@ -0,0 +1,70 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "rust_proj" +version = "0.1.0" +dependencies = [ + "xor_cryptor", +] + +[[package]] +name = "xor_cryptor" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72e5adf4efbff008434783ea27dab065d79d4c4eb61d2f6eb1299bec75139209" +dependencies = [ + "rayon", +] diff --git a/misc/rust_fixme_2/Cargo.toml b/misc/rust_fixme_2/Cargo.toml new file mode 100644 index 0000000..69a0629 --- /dev/null +++ b/misc/rust_fixme_2/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "rust_proj" +version = "0.1.0" +edition = "2021" + +[dependencies] +xor_cryptor = "1.2.3" diff --git a/misc/rust_fixme_2/src/main.rs b/misc/rust_fixme_2/src/main.rs new file mode 100644 index 0000000..452e6ee --- /dev/null +++ b/misc/rust_fixme_2/src/main.rs @@ -0,0 +1,36 @@ +use xor_cryptor::XORCryptor; + +fn decrypt(encrypted_buffer:Vec, borrowed_string: &mut String){ // How do we pass values to a function that we want to change? + + // Key for decryption + let key = String::from("CSUCKS"); + + // Editing our borrowed value + borrowed_string.push_str("PARTY FOUL! Here is your flag: "); + + // Create decrpytion object + let res = XORCryptor::new(&key); + if res.is_err() { + return; // How do we return in rust? + } + let xrc = res.unwrap(); + + // Decrypt flag and print it out + let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer); + borrowed_string.push_str(&String::from_utf8_lossy(&decrypted_buffer)); + println!("{}", borrowed_string); +} + + +fn main() { + // Encrypted flag values + let hex_values = ["41", "30", "20", "63", "4a", "45", "54", "76", "01", "1c", "7e", "59", "63", "e1", "61", "25", "0d", "c4", "60", "f2", "12", "a0", "18", "03", "51", "03", "36", "05", "0e", "f9", "42", "5b"]; + + // Convert the hexadecimal strings to bytes and collect them into a vector + let encrypted_buffer: Vec = hex_values.iter() + .map(|&hex| u8::from_str_radix(hex, 16).unwrap()) + .collect(); + + let mut party_foul = String::from("Using memory unsafe languages is a: "); // Is this variable changeable? + decrypt(encrypted_buffer, &mut party_foul); // Is this the correct way to pass a value to a function so that it can be changed? +}