Encode and Decode on FreeBSD
Base64
Encode
% echo -n "Hello World!" | base64 -e
SGVsbG8gV29ybGQh
- -n Do NOT print the trailing newline character.
- | The output(stdout) text of echo -n "Hello World!" is passed to base64 -e directly as input(stdin).
- -e Encode
Decode
% echo "SGVsbG8gV29ybGQh" | base64 -d
Hello World!
- -d Decode
URI
Encode
% echo -n "http://google.com/index.php?id=1'" | python3 -c "import sys;import urllib.parse; print(urllib.parse.quote(sys.stdin.read()));"
http%3A//google.com/index.php%3Fid%3D1%27
Decode
% echo "http%3A//google.com/index.php%3Fid%3D1%27" | unvis -eh
http://google.com/index.php?id=1'
- -e Don't decode \ escaped sequences.
- -h Decode using the URI encoding from RFC 1808. (VIS_HTTP1808)
Hexadecimal
% echo -n "Hello" | od -A n -t x1
48 65 6c 6c 6f
- The echo program will provide the string to the next command.
- The -n flag tells echo to NOT generate a new line at the end of the "Hello".
- The od program is the "octal dump" program. (We will be providing a flag to tell it to dump it in hexadecimal instead of octal.)
- The -A n flag is short for --address-radix=n, with n being short for "none". Without this part, the command would output an ugly numerical address prefix on the left side. This is useful for large dumps, but for a short string it is unnecessary.
- The -t x1 flag is short for --format=x1, with the x being short for "hexadecimal" and the 1 meaning 1 byte.
References:
Comments
Post a Comment