#Include #Include ;change to console app. #AutoIt3Wrapper_Res_Description=Base32 Encoder/Decoder #AutoIt3Wrapper_Res_Fileversion=0.1.0.17 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p #AutoIt3Wrapper_run_after=C:\PROGRA~1\SCINTI~1\AUTOIT~1\MakeCUI.exe "%out%" Local $cmd = $CmdLine _OPT_FIFO($cmd); strip off arg count. ; Put the valid short options into string. ; a colon ":" following a letter indicates that it needs an argument ; A double colon "::" indicates that an argument is optional Local $sShortOpts = "desh?" ; Put the valid long format options into an array. ; An equal sign as the last character of the option indicates that it requires an agrument. Local $aLongOpts[5] = ["help","encode","decode","string","version"] ;parse the command line options into a 2 dim array. Local $options = _OPT_GetOpt($cmd, $sShortOpts, $aLongOpts) If @error Then ShowUsage () Exit EndIf _Base32_BuildTable() main() Func main () Local $iIndex = -1 Local $bFiles = False Select Case _OPT_MatchOption("-h,-?,--help",$options,$iIndex) ShowUsage() Case _OPT_MatchOption("--version",$options,$iIndex) ShowVersion() Case $cmd[0] = "" ShowUsage() Case _OPT_MatchOption("-s,--string",$options,$iIndex) Select Case _OPT_MatchOption("-d,--decode",$options,$iIndex) ConsoleWrite(_Base32_Decode($cmd[0])&@LF) Case _OPT_MatchOption("-e,--encode",$options,$iIndex) ConsoleWrite(_Base32_Encode($cmd[0])&@LF) Case Else ShowUsage() EndSelect Case _OPT_MatchOption("-d,--decode",$options,$iIndex) If UBound($cmd) = 1 Then If FileExists ($cmd[0]) Then ConsoleWrite(_Base32_Decode(FileRead($cmd[0]))&@LF) Else ConsoleWrite(_Base32_Decode($cmd[0])&@lf) EndIf Else If FileExists($cmd[0]) Then Local $hf = FileOpen($cmd[1],18) FileWrite($hf,_Base32_Decode(FileRead($cmd[0]))) FileClose($hf) Else ConsoleWrite(StringFormat("%s does not exist.\n",$cmd[0])) EndIf EndIf Case _OPT_MatchOption("-e,--encode",$options,$iIndex) If UBound($cmd) = 1 Then If FileExists ($cmd[0]) Then ConsoleWrite(_Base32_Encode(FileRead($cmd[0]))&@LF) Else ConsoleWrite(_Base32_Encode($cmd[0])&@lf) EndIf Else If FileExists($cmd[0]) Then Local $hf = FileOpen($cmd[1],18) FileWrite($hf,_Base32_Encode(FileRead($cmd[0]))) FileClose($hf) Else ConsoleWrite(StringFormat("%s does not exist.\n",$cmd[0])) EndIf EndIf Case Else ConsoleWrite(_Base32_Encode($cmd[0])&@LF) EndSelect ;ConsoleWrite(encode("Ok this is a test") & @LF) ;ConsoleWrite(decode("J5VSA5DINFZSA2LTEBQSA5DFON2A")& @LF) EndFunc Func ShowUsage() $usage = "\n" & _ "base32 -- Encode/decode file or string as base32. Call:\n" & _ " base32 [-e / -d] [options] [infile] [outfile]\n\n" & _ "Options:\n" & _ " -d, --decode Decode base32 encoded file/string\n" & _ " -e, --encode Encode file/string into base32\n" & _ " -s, --string Argument is a string value \n" & _ " -h, --help Print this message\n" & _ " --version Print version number\n\n" & _ "Stephen Podhajecki\n" & _ "http://ocotillo.sytes.net\n" & _ "\nOriginal Java version Author: Frederik Zimmer Copyright © 2001\n" & _ "tristian@users.sourceforge.net" ConsoleWrite(StringFormat($usage)) EndFunc Func ShowVersion() $version = "\n"& _ "base32 -- %s\n" & _ "Copyright © 2007 Stephen Podhajecki (This port.)\n" & _ "Copyright © 2001 Frederik Zimmer (Java implementation)\n" & _ "This is free software; see the source for copying conditions. There is NO\n" & _ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" ConsoleWrite(StringFormat($version,FileGetVersion(@ScriptFullPath))) EndFunc