Simple base64 encoder/decoder in command-line with D
1 2 import std.base64; 3 import std.stdio; 4 import std.array; 5 void main(string[] args) 6 { 7 try { 8 string action = args[1]; 9 string source = args[2]; 10 string dest; 11 if(action == "encode") { 12 dest = std.base64.encode(source); 13 } 14 else if(action == "decode") { 15 dest = std.base64.decode(source); 16 } 17 else { 18 writeln("Error: Bad Action"); 19 return 1; 20 } 21 writeln(dest); 22 return 0; 23 } 24 catch(ArrayBoundsError err) { 25 writefln("Error: Missing argument (%s action string)", args[0]); 26 } 27 } 28
Usage: b64utils [de/en]code mytext