THM — RUST — [task 13] challenge -writeup

Before starting this you must get familiar with all the previous tasks and run some code in the tasks and get familiar with error handling and using crates.

If you have difficulty completing the previous tasks here is a walkthrough video of them.

TryHackMe — learn Rust — [Task 13]:

So as given the string is already encrypted and all you have to do is to decrypt in the order of rot13 -> base64 -> ROT13 -> plaintext and find the flag.

To do that you can head to https://crates.io/ to find external packages which will decrypt the text for you out of the box, so search for packages such as base64 and rot13 to make use of them to use them in our code.

So here are some packages which I used

cipher-crypt = “0.17.0”
base64 = “0.12.3”

will use cipher-crypt for rot13 and base64 for base 64 decryption.

So now you can add them to your dependencies in Cargo.toml file(as below)

Now you are all set to use the packages it in your code. Then you can import these packages in your code as below

extern crate cipher_crypt;
extern crate base64;
use base64::{decode};
use cipher_crypt::{Rot13};

Here is the complete code to get decrypt.

extern crate cipher_crypt;
extern crate base64;
use base64::{decode};
use cipher_crypt::{Rot13};
use std::str;fn main(){
let in_string = "M3I6r2IbMzq9";
let rot13_decrypt1 = Rot13::decrypt(in_string);
let unicode_decrypt = decode(rot13_decrypt1).unwrap();
let bytes_to_string = str::from_utf8(&unicode_decrypt).unwrap();
let final_string = Rot13::decrypt(bytes_to_string);
println!("{:?}",final_string);
}

Rust always recommends using snakecase so all the variables must be initialized in such format.

As Rot13::decrypt(“xxx”) returns a string we can directly pass it to base64 decode but the return type fo base64~decode is bytes we have to convert that to a string so we are using str::from_utf8. This could be done in several different ways I suppose I would be glad if could share with me your way of approaching the same in the comments.

Finally, you could use cargo run to run the code.

There you get the flag 🤩.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store