; ==================================================== ; ============ DataText encoder/decoder ============== ; ==================================================== ; Version: 1.4 ; Language: English ; Author: "sv3ora" ; Info website: http://www.qrp.gr/datatext ; ; ---------------------------------------------------------------------------- ; Script Start ; ---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include _Main() Func RestartScript() If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc Func SetTime() Local $time = _TicksToTime(Int(TimerDiff($begin)), $hour, $min, $sec) ControlSetText($WinMain, "", $label, StringFormat("%02i:%02i:%02i", $hour, $min, $sec)) EndFunc Func _Main() ; Creates window Global $WinMain = GUICreate('DataText v1.4 by sv3ora', 570, 350) ; Creates main edit Local $idEditText = GUICtrlCreateEdit('', 5, 5, 560, 280) _GUICtrlEdit_SetLimitText($idEditText, 6400000) ; Create the buttons Local $idEncodeButton = GUICtrlCreateButton('Encode', 5, 290, 85, 25) Local $idDecodeButton = GUICtrlCreateButton('Decode', 96, 290, 85, 25) Local $idInfoButton = GUICtrlCreateButton('?', 545, 325, 20, 20) ; Creates the password box with blured and centered input Local $idInputPass = GUICtrlCreateInput('', 187, 290, 100, 24, BitOR($ES_CENTER, $ES_PASSWORD)) ; Pass text label Local $idLabel = GUICtrlCreateLabel(' Password', 191, 294, 91, 17) ; Set the background color of the label Password. GUICtrlSetBkColor($idLabel, $COLOR_WHITE) ; Create the combo to select the crypting algorithm Local $idCombo = GUICtrlCreateCombo("", 291, 290, 88, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($idCombo, "3DES|AES (128bit)|AES (192bit)|AES (256bit)|DES|RC2|RC4", "RC4") ; Create the player buttons Local $playButton = GUICtrlCreateButton('Play', 5, 320, 40, 25) Local $stopButton = GUICtrlCreateButton('Stop', 50, 320, 40, 25) ; SLIDERS Local $volumeSliderLabel = GUICtrlCreateLabel("Volume:", 100, 325) Local $volumeSlider = GUICtrlCreateSlider(150, 320, 110, 25) GUICtrlSetData(-1, 50) ; Create the combo to select the play delay Local $delaySliderLabel = GUICtrlCreateLabel("Delay:", 270, 325) Local $idCombo2 = GUICtrlCreateCombo("", 314, 320, 65, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($idCombo2, "None|0.25 sec|0.5 sec|1 sec|2 sec|3 sec|4 sec|5 sec", "None") Global $fileIsImage ;timer GUICtrlCreateLabel("Elapsed:", 387, 325) Global $hour, $min, $sec, $begin Global $label = GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ; Shows window GUISetState() Local $iAlgorithm = $CALG_RC4 Local $dEncrypted Local $dDecrypted Local $encodedDataZIP Local $iDelay While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCombo ; Check when the combobox is selected and retrieve the correct algorithm. Switch GUICtrlRead($idCombo) ; Read the combobox selection. Case "3DES" $iAlgorithm = $CALG_3DES Case "AES (128bit)" $iAlgorithm = $CALG_AES_128 Case "AES (192bit)" $iAlgorithm = $CALG_AES_192 Case "AES (256bit)" $iAlgorithm = $CALG_AES_256 Case "DES" $iAlgorithm = $CALG_DES Case "RC2" $iAlgorithm = $CALG_RC2 Case "RC4" $iAlgorithm = $CALG_RC4 EndSwitch Case $idEncodeButton ; When you press Encode ;;;;;;;;;;;;;; SELECT FILE TO ENCODE ;;;;;;;;;;;;;;;; ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local $sMessage = "Select file to encode." ; Display an open dialog to select a file. Local $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir&"\DataText_all_files", "Images (*.jpg;*.png;*.gif)|All files (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then ; Display the error message. GUICtrlSetData($idEditText, "Error. No file was selected!") RestartScript() ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog. $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) EndIf ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) ;;;;;;;;;;;;;; COMPRESS SELECTED FILE ;;;;;;;;;;;;;;;; GUICtrlSetData($idEditText, "Wait for data processing. This may take a while...") ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 10) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("10%", 535, 295) ;$sFileOpenDialog2 is the tmp.zip file and its path Local $sFileOpenDialog2 = @TempDir&"\tmp.zip" ;compress the file selected ;First check if tmp.zip file exists Local $iFileExists = FileExists($sFileOpenDialog2) ; Check if file exists or not. If $iFileExists Then ;Delete the temporary tmp.zip file. FileDelete($sFileOpenDialog2) ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) Else ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) EndIf ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) ;;;;;;;;;;;;;; READ COMPRESSED FILE ;;;;;;;;;;;;;;;; ; Open the tmp.zip file for reading and store the handle to a variable. Local $sFileOpen = FileOpen($sFileOpenDialog2, $FO_READ) If $sFileOpen = -1 Then GUICtrlSetData($idEditText, "An error occurred when reading the file.") Return False EndIf ; Read the contents of the tmp.zip file using the handle returned by FileOpen. Local $dataZIP = FileRead($sFileOpen) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 40) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("40%", 535, 295) ;Close the temporary tmp.zip file FileClose($sFileOpen) ; Delete the temporary tmp.zip file. FileDelete($sFileOpenDialog2) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 60) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("60%", 535, 295) ;If the password box is empty, do not use encryption If GuiCtrlRead($idInputPass) = "" Then ;Encode the contents of the non encrypted variable to zbase32 $encodedDataZIP = _Base32_Encode($dataZIP) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) ;If password box is not empty then use encryption Else ; Calls the encryption. $dEncrypted = _Crypt_EncryptData($dataZIP, GUICtrlRead($idInputPass), $iAlgorithm) ; Encrypt the text with the new cryptographic key. ;Encode the contents of the encrypted variable to zbase32 $encodedDataZIP = _Base32_Encode($dEncrypted) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) EndIf ;;;;;;;;;;;;;; DISPLAY ENCODED DATA ;;;;;;;;;;;;;;;; ; Put encoded data to text box GUICtrlSetData($idEditText, $encodedDataZIP) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 100) GUICtrlCreateLabel("Progress:", 387, 295) Local $p1 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p1) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) Case $idCombo2 ; Check when the combobox is selected and retrieve the correct delay. Switch GUICtrlRead($idCombo2) ; Read the combobox selection. Case "None" $iDelay = 0 Case "0.25 sec" $iDelay = 250 Case "0.5 sec" $iDelay = 500 Case "1 sec" $iDelay = 1000 Case "2 sec" $iDelay = 2000 Case "3 sec" $iDelay = 3000 Case "4 sec" $iDelay = 4000 Case "5 sec" $iDelay = 5000 EndSwitch Case $playButton ; When you press Play ; Disable the play and delay buttons GUICtrlSetState($playButton, $GUI_DISABLE) GUICtrlSetState($idCombo2, $GUI_DISABLE) ;Read text from input box Local $readedText = GUICtrlRead($idEditText) Local $char = StringSplit($readedText, "") ;store this to an array of characters Local $num = 0 Local $iRound3 = 0 Local $perc = $num&"%" ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) For $i = 1 to $char[0] Switch GUIGetMsg() Case $stopButton ;if stop button has been clicked ExitLoop ; Exit the loop EndSwitch Local $volume = GUICtrlRead ($volumeSlider, 0) ;read volume slider SoundSetWaveVolume($volume) ; Set the volume Local $play1 = "\alphabet\" Local $play2 = ".wav" SoundPlay(@ScriptDir &$play1&$char[$i]&$play2, 1) $num = ((100*$char[0])/$char[0])-(((100*$char[0])/$char[0])-((100*$i)/$char[0])) $iRound3 = Round($num) $perc = $iRound3&"%" If StringLen($perc) > 3 Then $perc = "99%" ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, $num) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel($perc, 535, 295) Else ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, $num) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel($perc, 535, 295) EndIf Sleep ($iDelay) Next ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, (100*$char[0])/$char[0]) GUICtrlCreateLabel("Progress:", 387, 295) Local $p2 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p2) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ; Enable the play and delay buttons GUICtrlSetState($playButton, $GUI_ENABLE) GUICtrlSetState($idCombo2, $GUI_ENABLE) Case $idDecodeButton ; When you press Decode ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) ;Read text from input box Local $textTodecodeCaps = GUICtrlRead($idEditText) ;if input box is empty If $textTodecodeCaps = "" Then RestartScript() Else ;convert all read text to lower case letters Local $textTodecode = StringLower($textTodecodeCaps) ; Friendly message to the text box GUICtrlSetData($idEditText, 'Wait for data processing. This may take a while...') ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 10) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("10%", 535, 295) ;DECRYPT DECODED DATA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;If the password box is empty, do not use encryption If GuiCtrlRead($idInputPass) = "" Then ;Encode the contents of the non encrypted variable to zbase32 $decodedDataZIP = _Base32_Decode($textTodecode) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) ;If password box is not empty then use decryption Else ;Decode the contents of the variable to zbase32 Local $decodedData = _Base32_Decode($textTodecode) ; Calls the decryption. $decodedDataZIP = _Crypt_DecryptData($decodedData, GUICtrlRead($idInputPass), $iAlgorithm) ; Encrypt the text with the new cryptographic key. ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) EndIf ;;;;;;;;;;;;;; WRITE DECODED AND/OR DECRYPTED DATA TO ZIP FILE ;;;;;;;;;;;;;;;; ;$theTMPfile is the tmp zip file and its path Local $theTMPfile = @TempDir&"\tmp2.zip" ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $rFileOpen = FileOpen($theTMPfile, $FO_OVERWRITE) If $rFileOpen = -1 Then GUICtrlSetData($idEditText, "An error occurred when reading the file.") Return False EndIf ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 40) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("40%", 535, 295) ; Write data to the file using the handle returned by FileOpen. FileWrite($rFileOpen, $decodedDataZIP) ; Close the handle returned by FileOpen. FileClose($rFileOpen) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 60) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("60%", 535, 295) ;;;;;;;;;;;;;; UNZIP THE ZIP FILE ;;;;;;;;;;;;;;;; ;First delete all files from DataText_received_files dir DirRemove(@ScriptDir&"\DataText_received_files",1) DirCreate(@ScriptDir&"\DataText_received_files") Local $DataText_received_files = @ScriptDir&"\DataText_received_files" Local $DataText_all_files = @ScriptDir&"\DataText_all_files" ;Set the parameters of the create zip command Local $param1a = @ScriptDir&"\7z.exe " Local $param3a = "e " Local $param4a = " -o" Local $param2a = " -y" ;Extract zip to DataText_received_files dir. wait for the process to finish RunWait($param1a&$param3a&$theTMPfile&$param4a&$DataText_received_files, "", @SW_HIDE) ;Extract zip to DataText_all_files dir. (if filename already exists, it will be overwritten!!!) RunWait($param1a&$param3a&$theTMPfile&$param4a&$DataText_all_files&$param2a, "", @SW_HIDE) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) ; Delete the temporary tmp.zip file. FileDelete($theTMPfile) ; Put initial encoded data to text box GUICtrlSetData($idEditText, $textTodecode) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 100) GUICtrlCreateLabel("Progress:", 387, 295) Local $p3 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p3) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ;open explorer window to see file Local $DataText_received_files = @ScriptDir & "\DataText_received_files" Local $windowtitle = "DataText_received_files" Run("explorer.exe " & $DataText_received_files);open explorer to see extracted files in folder Local $hExplorer = WinWait("[REGEXPTITLE:(?i)\Q" & $windowtitle & "\E$]") WinWaitClose($hExplorer) DirRemove(@ScriptDir&"\DataText_received_files",1); when files have been viewed, delete the DataText_received_files dir DirCreate(@ScriptDir&"\DataText_received_files");recreate the DataText_received_files dir EndIf Case $idInfoButton ;When you press ? ; Info message to the text box GUICtrlSetData($idEditText, "DataText by sv3ora"&@crlf&"Conversion of file to text and text to file."&@crlf&@crlf&"This program can be used to transfer data through any radio amateur digital mode "&@crlf&"(including CW), that supports text-only transmission"&@crlf&@crlf&"TO ENCODE A FILE:"&@crlf&"1. Click 'Encode' to select the file to encode."&@crlf&"2. Select all encoded text (right click) and copy it."&@crlf&"3. Paste this text to your favorite sending program."&@crlf&"If you want to password protect your file, enter a password and select the"&@crlf&"encryption algorithm from the drop down list, prior to clicking the encode button."&@crlf&@crlf&"TO DECODE A TEXT:"&@crlf&"1. Copy the text to decode from your favorite receiving"&@crlf&" program and paste it into this text box."&@crlf&"2. Click 'Decode' to decode this text."&@crlf&"3. The decoded file is automatically displayed in a new explorer window."&@crlf&"If the received data has been password protected, then you have to enter the"&@crlf&"password and select the encryption algorithm from the drop down list,"&@crlf&"prior to clicking the decode button. "&@crlf&@crlf&"Note that DataText keeps all your previously decoded files into the 'DataText_all_files' "&@crlf&"directory, inside the folder where the DataText program is."&@crlf&"If your newly received filename matches a filename in this directory, the old file"&@crlf&"will be overwritten!"&@crlf&@crlf&"EMBEDDED PLAYER: "&@crlf&"The embedded player, can be used to play any text (encoded or not) in the text area "&@crlf&"into phonetic alphabet. Set the delay between letters and click 'Play' to play the text."&@crlf&"The playback volume can be set at any time and the playback can be stopped "&@crlf&"by clicking 'Stop'."&@crlf&@crlf&"PROGRESS:"&@crlf&"The progress bar, shows the encoding, decoding and playback progress."&@crlf&"The elapsed time is also displayed during encoding, decoding and playback."&@crlf&@crlf&"More info about DataText at: http://www.qrp.gr/datatext"&@crlf&"Comments and suggestions at: sv3ora@qrp.gr") EndSwitch WEnd EndFunc ;==>_Main