When going on reddit looking to download some shady stuff, you've probably encountered some strange code like this:
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGkgbG92ZSB5b3UgPDMu
This cryptic junk - it's base64, and is commonly used to easily encrypt MEGA drive links and keeping them from being flagged, so you can continue to watch shitty romcoms for nada.
So how does it work?
Let's take a string, ROACH
for example, and split it into UTF-8 characters:
R; // U+0052
O; // U+004F
A; // U+0041
C; // U+0043
H; // U+0048
And then convert them to 8-bit binary:
R; // 01010010
O; // 01001111
A; // 01000001
C; // 01000011
H; // 01001000
Now divide them into 6 bit characters, and match them to the base64 alphabet.
Oh wait.
Because 8 * 5 doesn't divide perfectly by 3s, We'll have to pad it with 0s.
R | O | A | C | H | |||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ||||||
010100 | 100100 | 111101 | 000001 | 010000 | 110100 | 100000 | padding | ||||||||||||||||||||||||||||||||||||||||
U | k | 9 | B | Q | 0 | g | = |
And that's it. We have successfully converted ROACH
into Uk9BQ0g=
.
If you want to try converting it without having to do it manually, you can go here.