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

Popular posts from this blog

BdsDex: failed to load Boot0001 "UEFI BHYVE SATA DISK BHYVE-OABE-20A5-E582" from PciRoot(0x0)/Pci (0x2, 0x0)/Stat(0x0,0xFFFF,0x0) : Not Found

How To Install Nginx, MySQL and PHP (FEMP) Stack on FreeBSD 13.0

Install samba on FreeBSD(on VMware Workstation) to share files with Window.