ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snacks

Encode/decode cipher/decipher crypter/decrypter ASCII HEX Binary Base64 URL etc.

<< < (3/5) > >>

ashecorven:
You mentioned malware.  However, please keep in mind that whatever I come up with isn't going to handle any sort of binary file input (if that's what you envisioned).
-skwire (February 05, 2015, 03:48 PM)
--- End quote ---

Hehehe, no, that would be a BIG ask. I'm more than happy with the programmes I use and one day hope I know how to use half of the functionality they provide.

Good to hear.  I like the way that app turned out.  If you're brave, feel free to try the beta.
-skwire (February 05, 2015, 03:48 PM)
--- End quote ---

Trying it out now.

ashecorven:
Hey how's it going?

skwire:
Hey how's it going?-ashecorven (April 02, 2015, 12:11 AM)
--- End quote ---

Unfortunately, my regular job hasn't left me with much coding time lately.  Apologies.

ashecorven:
Hello again, any progress?

lifeweaver:
Hi ashecorven,

Seeing as Skywire has been busy I decided to attempt your request.

Note: Autohotkey is need to run this script, although you could compile it and merely have an .exe.
Script runs on: Windows 7 Professional, AutoHotkey 1.1.15.04 Unicode build

SpoilerNote: a lot of these functions I found posted by AutoHotkey community members, when so I documented it with a url or name.

--- ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance ignore

Help(wParam, lParam, Msg)
{
  MouseGetPos,,,, OutputVarControl

  IfEqual, OutputVarControl, Button1
Help := "Will try to convert the input multiple times if detected as Hex/Binary."
  else IfEqual, OutputVarControl, Button2
Help := "Will replace your current clipboard"

  ToolTip % Help
}

determineEncoding(string)
{
  BINARY_REGEX := "^(\d{8}\s?)*$"
  ;~ BASE64_REGEX := "^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$"
  HEX_REGEX := "^([0-9A-Fa-f]{2}\s?)+$"
  ;~ DECIMAL_REGEX := "^([0-9]{2,3}\s?)+$"
  
  if(RegExMatch(string, BINARY_REGEX))
    return "Binary"
  else if(RegExMatch(string, HEX_REGEX))
    return "Hex"
  else
    return false
}

StrPutVar(string, ByRef var, encoding)
{
    ; Ensure capacity.
    VarSetCapacity( var, StrPut(string, encoding)
        ; StrPut returns char count, but VarSetCapacity needs bytes.
        * ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
    ; Copy or convert the string.
    return StrPut(string, &var, encoding)
}

determineEncodingFlag(encoding, crypt)
{
  if(crypt = "encrypt")
  {
    if(encoding = "Binary")
      return 0x00000002
    else if(encoding = "BASE64")
      return 0x40000001
    else if(encoding = "Hex")
      return 0x00000004
  }
  else if (crypt = "decrypt")
  {
    if(encoding = "Binary")
      return 0x00000002
    else if(encoding = "BASE64")
      return 0x00000006
    else if(encoding = "Hex")
      return 0x00000008
  }
}

encodeUTF8( ByRef OutData, InData, inputEncoding)
{
  if(inputEncoding = "Binary")
  {
    OutData := TxtToBin(InData)
    return StrLen(OutData)
  }
  
  encoding := determineEncodingFlag(inputEncoding, "encrypt")
  InDataLen := StrPutVar(InData, InData, "UTF-8") - 1
  DllCall( "Crypt32.dll\CryptBinaryToStringW", UInt,&InData, UInt,InDataLen, UInt,encoding, UInt,0, UIntP,TChars, "CDECL Int" )
  VarSetCapacity( OutData, Req := TChars * ( A_IsUnicode ? 2 : 1 ), 0 )
  DllCall( "Crypt32.dll\CryptBinaryToStringW", UInt,&InData, UInt,InDataLen, UInt,encoding, Str,OutData, UIntP,Req, "CDECL Int" )
  
  if(inputEncoding = "Hex")
  {
    StringReplace, OutData, OutData, %A_Space%%A_Space%, %A_Space%, All
    
    ; Not sure if I really want to remove the newlines for hex
    StringReplace, OutData, OutData, `r`n,,All
  }
  
  Return TChars
}

decodeUTF8( ByRef OutData, InData, inputEncoding)
{
  if(inputEncoding = "Binary")
  {
    OutData := BinToTxt(InData)
    return StrLen(OutData)
  }
  
  encoding := determineEncodingFlag(inputEncoding, "decrypt")
  DllCall( "Crypt32.dll\CryptStringToBinaryW", UInt,&InData, UInt,StrLen(InData), UInt,encoding, UInt,0, UIntP,Bytes, Int,0, Int,0, "CDECL Int" )
  VarSetCapacity( OutData, Req := Bytes * ( A_IsUnicode ? 2 : 1 ), 0 )
  DllCall( "Crypt32.dll\CryptStringToBinaryW", UInt,&InData, UInt,StrLen(InData), UInt,encoding, Str,OutData, UIntP,Req, Int,0, Int,0, "CDECL Int" )
  OutData := StrGet(&OutData, "cp0")
  Return Bytes
}

TxtToBin(txt)
{ ; http://www.autohotkey.com/board/topic/7835-ascii-binary-converter/?p=48740
  Loop Parse, txt
  {
    Loop 8
    {
      bin := bin (Asc(A_LoopField) >> (8 - A_Index) & 1)
    }
    bin .= " "
  }
   Return bin
}

BinToTxt(bin)
{ ; http://www.autohotkey.com/board/topic/7835-ascii-binary-converter/?p=48740
   StringReplace, bin, bin, %A_Space%,,All
   Loop Parse, bin
   {
      x += x + (A_LoopField = "1")

      If !Mod(A_Index,8)
      {
         txt := txt Chr(x)
         x = 0
      }
   }
   Return txt
}

Rot13(string)
{ ; from LinearSpoon's Translation of The Worlds Shortest C Implementation of Rot13 http://rosettacode.org/wiki/Rot-13#AutoHotkey
  Output := ""
  Loop, Parse, string
  {
    a := ~Asc(A_LoopField)
    Output .= Chr(~a-1//(~(a|32)//13*2-11)*13)
  }
  return Output
}

ascii2Decimal(string)
{
  encoding := ""
  Loop, Parse, string
  {
    encoding .= Asc(A_LoopField) . " "
  }
  return SubStr(encoding, 1, StrLen(encoding) - 1)
}

decimal2Ascii(string)
{
  decoding := ""
  Loop, Parse, string, %A_Space%
  {
    decoding .= Chr(A_LoopField)
  }
  return decoding
}

uriEncode(str)
{ ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release http://www.autohotkey.com/board/topic/6199-url-encoding/?p=193258
b_Format := A_FormatInteger
data := ""
SetFormat,Integer,H
Loop,Parse,str
if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
Else
data .= A_LoopField
SetFormat,Integer,%b_format%
return data
}

uriDecode(str)
{ ; v 0.1 / (w) 28.06.2008 by derRaphael / zLib-Style release http://www.autohotkey.com/board/topic/6199-url-encoding/?p=193258
Loop,Parse,str,`%
txt := (A_Index=1) ? A_LoopField : txt chr("0x" substr(A_LoopField,1,2)) SubStr(A_LoopField,3)
return txt
}

convertInputToText(string, inputEncoding)
{
  if(inputEncoding = "BASE64")
    decodeUTF8(decoded, string, "Base64")
  else if(inputEncoding = "Binary")
    decodeUTF8(decoded, string, "Binary")
  else if(inputEncoding = "Decimal")
    return decimal2Ascii(string)
  else if(inputEncoding = "Hex")
    decodeUTF8(decoded, string, "Hex")
  else if(inputEncoding = "ROT13")
    return Rot13(string)
  else if(inputEncoding = "URI Encoded")
    return uriDecode(string)
  
  return decoded
}

convertInputToOutputEncoding(inputEncoding, string, outputEncoding)
{
  if(outputEncoding = "BASE64")
    encodeUTF8(encoded, string, "Base64")
  else if(outputEncoding = "Binary")
    encodeUTF8(encoded, string, "Binary")
  else if(outputEncoding = "Decimal")
    return ascii2Decimal(string)
  else if(outputEncoding = "Hex")
    encodeUTF8(encoded, string, "Hex")
  else if(outputEncoding = "ROT13")
    return Rot13(string)
  else if(outputEncoding = "URI Encoded")
    return uriEncode(string)
  else if(outputEncoding = "")
    return convertInputToText(string, inputEncoding)
  else if(outputEncoding = "Text")
    return convertInputToText(string, inputEncoding)
  
  return encoded
}

Gui, Add, Text, x22 y20 w40 h20 , Input:
Gui, Add, DropDownList, x92 y20 w280 h20 vinputEncoding Choose1 R9, Text|BASE64|Binary|Decimal|Hex|ROT13|URI Encoded
;~ Gui, Add, Button, x452 y10 w110 h40 vguessEncoding gguessEncoding , Guess encoding
Gui, Add, Edit, x32 y60 w530 h270 vconverterInput ,

Gui, Add, Text, x22 y340 w40 h20 , Output:
Gui, Add, DropDownList, x92 y340 w280 h20 voutputEncoding goutputEncoding Choose1 R9, Text|BASE64|Binary|Decimal|Hex|ROT13|URI Encoded
Gui, Add, CheckBox, x462 y340 w100 h20 hwndsmartConvertHwnd vsmartConvert , Smart Convert?
Gui, Add, Edit, x32 y370 w530 h270 vconverterOutput ,
Gui, Add, Button, x32 y650 w140 h30 gcopyOutputToClipboard hwndcopyToClipboardHwnd , Copy Output to Clipboard
Gui, Add, Button, x242 y650 w150 h30 gcopyOutputToInput , Copy Output to Input
Gui, Add, Button, x462 y650 w100 h30 vencode gencode , Encode

; Generated using SmartGUI Creator 4.0
Gui, Show, xCenter yCenter h705 w585, Converter
OnMessage(0x200, "Help")
Return

GuiClose:
ExitApp

encode:
Gui, Submit, nohide
GuiControlGet, inputEncoding,, inputEncoding
GuiControlGet, converterInput,, converterInput
GuiControlGet, outputEncoding,, outputEncoding
GuiControlGet, smartConvertEnabled,, smartConvert

outputText := convertInputToOutputEncoding(inputEncoding, converterInput, outputEncoding)

if(smartConvertEnabled)
{
  result := DetermineEncoding(outputText)
  While result != false && result != outputEncoding
  {
    outputText := convertInputToText(outputText, result)
    result := DetermineEncoding(outputText)
  }
}

Guicontrol,, converterOutput, %outputText%
return

copyOutputToClipboard:
GuiControlGet, ClipBoard,, converterOutput
return

copyOutputToInput:
GuiControlGet, currentOutputEncoding,, outputEncoding
GuiControlGet, output,, converterOutput
Guicontrol,, converterInput, %output%
Guicontrol,, converterOutput
GuiControl, ChooseString, inputEncoding, %currentOutputEncoding%
GuiControl, Choose, outputEncoding, 1
GuiControl, Enable, smartConvert
return

outputEncoding:
GuiControlGet, outputEncoding,, outputEncoding
if(outputEncoding != "Text")
{
  GuiControl,, smartConvert, 0
  GuiControl, Disable, smartConvert
}
else if(outputEncoding = "Text")
{
  GuiControl, Enable, smartConvert
}
return


Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version