Base64 Command line Utility

Thrown together in PHP.

Usage:

Encode /path/to/base64 -e 'The quick brown fox'


/path/to/base64 'The quick brown fox'
Decode /path/to/base64 -d VGhlIHF1aWNrIGJyb3duIGZveA==
Help /path/to/base64 -h

Note that the script output is not succeeded by a newline, the reason being that I don't want to have to trim a newline every time I call this script from somewhere else.

Download source code

#!/usr/bin/php -q
<?php
  /* 
   * Simple Base64 encode/decode shell utility written in PHP
   * (C) 2004 by Andy Chase (achase@greyledge.net)
   * http://sundown.greyledge.net
   *
   * Feel free to use and redistribute this code in any way you see fit,
   * provided this notice remains in place.
   */

$action = '';
$string = '';
switch($_SERVER['argv'][1]){

 case '-e':
   $action = 'encode';
   $string = $_SERVER['argv'][2];
   break;
 case '-d':
   $action = 'decode';
   $string = $_SERVER['argv'][2];
   break;

 case '-h':
   $action = 'help';
   break;

 case '':
   $action = 'help';
   break;
 default:
   $action = 'encode';
   $string = $_SERVER['argv'][1];

}

switch($action){
 case 'encode':
   echo base64_encode($string);
   break;
 case 'decode':
   echo base64_decode($string);
   break;
 case 'help':
   echo "Usage: base64 [-edh] [string]\n\t-e\tBase64-encode [string]\n\t-d\tBase64-decode [string]\n \t-h\tDisplay this message.\n";

}

?>
Syndicate content

Twitter

  • RT @Crell An obituary for an old friend: http://bit.ly/gNdVIl #Drupal #Git #CVS 3 years 21 weeks ago
  • (That is to say, in hook_views_data(). #views #drupal) 3 years 21 weeks ago
  • #drupal #views3 gurus: Is it possible to declare a relationship with an intederminate base table & field? (TBD by the handler?) 3 years 21 weeks ago
  • I wrote a module and someone else figured out how to use it to pull Webform data into #Drupal views. http://bit.ly/hGDGGi 3 years 27 weeks ago
  • RT @nquabbinlodge Meeting tonight in Athol MA! Work of the evening: confer the 3rdº on 1 candidate. Dinner at 6, lodge opens at 7. 3 years 32 weeks ago

Older

Contact

Andy Chase
(978) 297-6402
andychase [at] gmail.com
GPG/PGP Public Key