Base 64
Another common encoding scheme is Base64, which allows us to represent binary data as an ASCII string using an alphabet of 64 characters. One character of a Base64 string encodes 6 binary digits (bits), and so 4 characters of Base64 encode three 8-bit bytes.
Base64 is most commonly used online, so binary data such as images can be easily included into HTML or CSS files.
challenge : Take the below hex string, decode it into bytes and then encode it into Base64.72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf
Solution : We have to perform 2 steps -
- Hex to bytes
- Bytes to base64
Below is python script to get the flag :
Code python
import base64
hx ="72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf"
byt = bytes.fromhex(hx)
b64ed = byt.b64encode()
print(b64ed) # output : b'crypto/Base+64+Encoding+is+Web+Safe/'
Above python script gives output : b'crypto/Base+64+Encoding+is+Web+Safe/'
Flag is : crypto/Base+64+Encoding+is+Web+Safe/
Bash :
Code bash
echo "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf" | xxd -r -p | base64
Rust :
Code rust
use hex;
use base64::{Engine as _, engine:: general_purpose};
fn main(){
let hx = "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf";
match hex::decode(hx) {
Ok(byt) => {
let ab = general_purpose::STANDARD.encode(byt);
println!("{}",&ab);
},
Err(_) => println!("Hex to bytes faild")
}
}