Views: 10
Most commonly used text encoding methods:
base64
hex
rot13
Base64
Identifying Base64:
base64
encoded strings are easily spotted since they only contain alpha-numeric characters. However, the most distinctive feature of base64
is its padding using =
characters. The length of base64
encoded strings has to be in a multiple of 4. If the resulting output is only 3 characters long, for example, an extra =
is added as padding, and so on.
Encode:
echo https://netwerklabs.com | base64
aHR0cHM6Ly93d3cubmV0d2Vya2xhYnMuY29tCg==
Decode:
echo aHR0cHM6Ly93d3cubmV0d2Vya2xhYnMuY29tCg== | base64 -d
Hex
Another common encoding method is hex
encoding, which encodes each character into its hex
order in the ASCII
table. For example, a
is 61
in hex, b
is 62
, c
is 63
, and so on. You can find the full ASCII
table in Linux using the man ascii
command.
Identifying Hex:
Any string encoded in hex
would be comprised of hex characters only, which are 16 characters only: 0-9 and a-f. That makes spotting hex
encoded strings just as easy as spotting base64
encoded strings.
Hex Encode:
To encode any string into hex
in Linux, we can use the xxd -p
command:
echo https://netwerklabs.com/ | xxd -p
68747470733a2f2f7777772e6e65747765726b6c6162732e636f6d2f0a
Hex Decode:
To decode a hex
encoded string, we can use the xxd -p -r
command:
echo 68747470733a2f2f7777772e6e65747765726b6c6162732e636f6d2f0a | xxd -p -r
Caesar/Rot13
ROT13 Encode:
There isn’t a specific command in Linux to do rot13
encoding. However, it is fairly easy to create our own command to do the character shifting:
echo https://netwerklabs.com/ | tr 'A-Za-z' 'N-ZA-Mn-za-m'
ROT13 Decode:
echo uggcf://jjj.argjrexynof.pbz/ | tr 'A-Za-z' 'N-ZA-Mn-za-m'
Online tool for ROT:
Misc
Some tools can help us automatically determine the type of encoding, like Cipher Identifier.