TheDcoder Posted April 5, 2016 Share Posted April 5, 2016 (edited) I am really having a headache with this one... expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _Base64_Encode ; Description ...: Encode the $vData in Base64 ; Syntax ........: _Base64_Encode($vData) ; Parameters ....: $vData - $vData to Encode. ; Return values .: Success: Base64 encoded $vData in the form of a string. ; Failure: False and @error set to: ; 1 - If "error calculating the length of the buffer needed" ; 2 - If "error encoding" ; Author ........: trancexx ; Modified ......: Damon Harris (TheDcoder) ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Base64_Encode($vData) $vData = Binary($vData) Local $tByteStruct = DllStructCreate("byte[" & BinaryLen($vData) & "]") DllStructSetData($tByteStruct, 1, $vData) Local $tIntStruct = DllStructCreate("int") Local $aDllCall = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($tByteStruct), _ "int", DllStructGetSize($tByteStruct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($tIntStruct)) If @error Or Not $aDllCall[0] Then Return SetError(1, 0, False) ; error calculating the length of the buffer needed EndIf Local $tCharStruct = DllStructCreate("char[" & DllStructGetData($tIntStruct, 1) & "]") $aDllCall = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($tByteStruct), _ "int", DllStructGetSize($tByteStruct), _ "int", 1, _ "ptr", DllStructGetPtr($tCharStruct), _ "ptr", DllStructGetPtr($tIntStruct)) If @error Or Not $aDllCall[0] Then Return SetError(2, 0, False) ; error encoding EndIf Return DllStructGetData($tCharStruct, 1) EndFunc ConsoleWrite(_Base64_Encode("jilles" & Null & "jilles" & Null & "sesame")) ; It should be "amlsbGVzAGppbGxlcwBzZXNhbWU=" Sleep(1000) Thanks in Advance, TD. Edited April 5, 2016 by TheDcoder Changed Title EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 I see you started a second topic with "the Null" question. In C++ any regular string is terminated with a Null character, as explained in the other thread. This means with the example you posted I guess the only characters encoded to Base64 are the characters before the first Null? So what is it you are really trying here as a string in general never contains a Null character, only Binary data does? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 @Jos I am aware, but I was confused while deciding the Topic Title, will correct it... But this didn't work either: ConsoleWrite(_Base64_Encode("jilles" & Binary(Null) & "jilles" & Binary(Null) & "sesame")) EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 Did you read my whole post and do you have any questions after reading it? Also try answering the questions asked. Might help if you first understand things before trying other similar things that wil also fail! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Danyfirex Posted April 5, 2016 Share Posted April 5, 2016 NULL in AutoIt like a null ptr not null character. YOu should do this _Base64_Encode("jilles" & chr(0) & "jilles" & chr(0) & "sesame") Saludos TheDcoder 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 @Danyfirex Its "amlsbGVzAGppbGxlcwBzZXNhbWU=", that is not what I wanted... @Jos Thanks for locking the topic, still reading your previous posts. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 17 minutes ago, Jos said: This means with the example you posted I guess the only characters encoded to Base64 are the characters before the first Null? No, all the characters are encoded in Base64. (expect the Null) I also changed the topic EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 Let me see I understand this: So you want all characters except the Asc(0) characters encoded with Base64 and have leave the Asc(0) characters as is? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 Just now, Jos said: So you want all characters except the Asc(0) characters encoded with Base64 and have leave the Asc(0) characters as is? No, that is not what I want... What I want is: jilles<NULL>jilles<NULL>sesame encoded in Base64... EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 Ok, so what is wrong with the result from the code shown by Danyfirex as that looks close? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 Its looks close but that is not what I wanted, I want it to be exactly "amlsbGVzAGppbGxlcwBzZXNhbWU=" EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 3 minutes ago, TheDcoder said: I want it to be exactly "amlsbGVzAGppbGxlcwBzZXNhbWU=" Try this: ConsoleWrite(_Base64_Encode("jilles" & chr(0) & "jilles" & Chr(0) & "sesame")) ; It should be "amlsbGVzAGppbGxlcwBzZXNhbWU=" Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 @Jos ConsoleWrite(_Base64_Encode("jilles" & chr(0) & "jilles" & Chr(0) & "sesame") = 'amlsbGVzAGppbGxlcwBzZXNhbWU=') EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 $x = _Base64_Encode("jilles" & chr(0) & "jilles" & Chr(0) & "sesame") $x = StringReplace($x,@crlf,"") ConsoleWrite($x & ":" & stringLen($x) & @CRLF) ; It should be "amlsbGVzAGppbGxlcwBzZXNhbWU=" if $x == 'amlsbGVzAGppbGxlcwBzZXNhbWU=' then ConsoleWrite("Yes!!!!" & @CRLF) Else ConsoleWrite("No!!!!" & @CRLF) EndIf TheDcoder 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted April 5, 2016 Author Share Posted April 5, 2016 @Jos Ummm... Must change my glasses . So that is what it was then... Thanks! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2016 Developers Share Posted April 5, 2016 First thought my glasses weren't functioning properly as the consolewrite showed the correct string, but the additional @crlf was making your test fail. Not sure why that is returned by the UDF. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2016 Share Posted April 6, 2016 (edited) I apologize for a typo I made in the other thread: I typed Asc(0) but meant Chr(0). Can't edit it after lockdown. (Jos did it, thanks) @TheDcoder You really should start using NUL for the ASCII control char 0x00 and Null for the AutoIt (and SQL) "I don't know" keyword. Edited April 6, 2016 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
TheDcoder Posted April 6, 2016 Author Share Posted April 6, 2016 @jchd Ah, understood EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted April 6, 2016 Developers Share Posted April 6, 2016 1 hour ago, jchd said: Can't edit it after lockdown. Fixed it. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now