Jump to content

Base64 Converter


mikeytown2
 Share

Recommended Posts

  • 1 year later...

Just looking at theis encoder stuff... Has this evolved into something else? Does not seem to work with current versionm 3.2.4.9 - Gets an error about BinaryString. Did a search and replace to reflect it being renamed to Binary. Then I got another error:

C:\autoit_stuff\_Base64.au3 (258) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Would be useful if it worked again....

Thanks,

Shane

Link to comment
Share on other sites

Just looking at theis encoder stuff... Has this evolved into something else? Does not seem to work with current versionm 3.2.4.9 - Gets an error about BinaryString. Did a search and replace to reflect it being renamed to Binary. Then I got another error:

Would be useful if it worked again....

Thanks,

Shane

It is my belief that BinaryString was changed??
Link to comment
Share on other sites

  • 1 month later...

BinaryToString() and StringToBinary()

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Hmmm.....I find that function in the help file, but Scite doesn't recognize it when I type it. Do I need some kind of #include to use it?

When I run the script with BinaryToString() replacing BinaryString() I get an unknown function error.

Link to comment
Share on other sites

Link to comment
Share on other sites

wow, never would have thought AutoIt would change that much.... anyway i fixed the example and core files.

Download New Files From Second Post

Incase anyone is looking for the old BinaryString() function i found this post...

http://www.autoitscript.com/forum/index.ph...mp;#entry367545

Wow, good job!

I once wrapped my head around a base64 converter ... honestly that took a lot of effort to stay focused. Now I think I'm ready for the fifth dimension :whistle:

Be seeing you

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Link to comment
Share on other sites

  • 4 weeks later...

Hi, I wanted to use mikeytown2's _base64.au3 (from the latest "second post") but I found some preblems. Look, I am not a programmer and I appologise for some stupid things I may have said in this post. It was said that this .au3 supports binary files. Yes, but _Base64Encode() supports only input not containing null "charrachters" (#00). The problem is that this function (_Base64Encode()) uses '$as_Input = StringSplit($s_Input, "")' and when strigsplit() encounters a #00 it ends sudenly, resulting in a partial array. I tryed to encode a rar file, but because it included "null" bytes it ended prematuraly. Therefore , for my purposes I changed _base64.au3 so it could read directly from a file , byte by byte, in the array $as_Input. Then everything went OK.

I mean - found this problem, but if it is is discussed before or if what I say is a total scrap - please, don't mind it.

Link to comment
Share on other sites

  • 3 weeks later...

Minor Update to Code

_Base64: Code Cleanup, I left in 2 ConsoleWrite functions and #include <Array.au3>. They are now removed. Updated documentation inside the file as well.

Grab files from second post.

keed what was your solution for reading binary files? This is what i came up with, just wondering if you had something different.

$file = "binaryfile.dat"

_Base64Encode (BinaryToString(FileRead(FileOpen($file, 16), FileGetSize($file))))

If you look in the example file that goes along with _base64.au3, it has the same solution as above.

Link to comment
Share on other sites

My solution was not a "solution" at all. I just wanted to see whether the function encodes correctly arbitrary binary files. (It does it of course.) I changed the _Base64Encode itself by adding this code:

;Break the input up into bytes
    
;startofmycode
    

    Local $filesize = FileGetSize($filename)

    Local $filearray[$filesize]
          
    $filearray[0] = $filesize -1
    $fhand = FileOpen($filename, 0)
    
    for $i = 1 to $filesize - 1
        
        $filearray[$i] = FileRead($fhand, 1)
    Next    
    
    Fileclose($fhand)
    
    
;endofmycode
;Local $as_Input = StringSplit($s_Input, "")   &^(*&^(*&(*&(*UYO*&Y)
    
    Local $as_Input = $filearray

And I added a parameter for the function called $filename.

As you see - it is very clumsy and it is only for testing purposes. Your solution is very fine.

Link to comment
Share on other sites

  • 3 months later...

GREAT UDF - WORKS LIKE A CHARM, THANKS!!

[why am i yelling ?!]

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

  • 2 weeks later...

I've seen many base64 decoder here and almost all of them are either too slow, too big, or decode incorrectly so I decided to write my own. Take a look for yourself and hopefully it'll help save you some time on base64 decoder. Any feedback is welcome. Happy programming...

Func Base64Decode($s)

Local $key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', _

$t = '', $p = -8, $a = 0, $c, $d, $len = StringLen($s)

For $i = 1 to $len

$c = StringInStr($key, StringMid($s,$i,1), 1) - 1

If $c < 0 Then ContinueLoop

$a = BitOR(BitShift($a, -6), BitAND($c, 63))

$p = $p + 6

If $p >= 0 Then

$d = BitAND(BitShift($a, $p), 255)

If $c <> 64 Then $t = $t & Chr($d)

$a = BitAND($a, 63)

$p = $p - 8

EndIf

Next

Return $t

EndFunc

Link to comment
Share on other sites

I've seen many base64 decoder here and almost all of them are either too slow, too big, or decode incorrectly so I decided to write my own. Take a look for yourself and hopefully it'll help save you some time on base64 decoder. Any feedback is welcome. Happy programming...

Func Base64Decode($s)
    Local $key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', _
    $t = '', $p = -8, $a = 0, $c, $d, $len = StringLen($s)
    For $i = 1 to $len      
        $c = StringInStr($key, StringMid($s,$i,1), 1) - 1
        If $c < 0 Then ContinueLoop     
        $a = BitOR(BitShift($a, -6), BitAND($c, 63))
        $p = $p + 6
        If $p >= 0 Then
            $d = BitAND(BitShift($a, $p), 255)
            If $c <> 64 Then $t = $t & Chr($d)
            $a = BitAND($a, 63)
            $p = $p - 8
        EndIf
    Next    
    Return $t
EndFunc
This is a fairly simple decoder (i like), its slow though. It runs the for loop for every character. To decode a 155kb base64 file this took 12.763 seconds. With the decoder that me and blindwig made, it takes 0.767 seconds.

For our encoder/decoder, code size wasn't an issue; all we cared about was speed. This might be useful for someone who is trying to keep their code base very small.

Link to comment
Share on other sites

  • 1 month later...

I think the line marked ;BUG?: is wrong (_INetSmtpMail.au3). My suggestion is in the code.

;Close Message and Connection
    ;BUG?: For $i_Count = 0 To (UBound($as_Body) - 1) Step + 1
    For $i_Count = 0 To (UBound($as_End) - 1) Step + 1
        _SmtpSend($v_Socket, $as_End[$i_Count], $f_trace)
        $s_Receive = _GetLastReplyMsg($v_Socket, $as_EndReplyCode[$i_Count], $f_trace)
        If @error Then
            SetError(60 + $i_Count)
            Return False
        EndIf
    Next

I have noticed that the loop ain't the same as in the _INetSmtpMail with login support

Thanks for the nice work..:)

EDIT: You dont need my dbg lines..

Edited by Uten
Link to comment
Share on other sites

Uten, Thanks for your help! I know my SMTP code is quite messy. If you could take the first step and post a new version of the SMTP code, i would greatly appreciate it. As you suggested in your PM, there is code in the example file that should be in the UDF file. The ultimate goal would be for both files to be included as part of the official UDF's. I believe the base64 code is ready, the SMTP is not. I haven't played with the SMTP code for years.

Thanks for your Time!

Link to comment
Share on other sites

  • 8 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...