flat assembler
Message board for the users of flat assembler.

Index > Main > BASE64

Author
Thread Post new topic Reply to topic
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 12 Feb 2007, 17:51
I've had BASE64 masm code on my homepage for some time, but it was just a transcription form C code, and thus just couldn't be really good. There were also some errors.
Finally I rewrote it from scratch. I post here both fasm and masm versions in attachment. There are 3 functions: base64_encode, base64_decode and base64_decode_fast. Two decoding functions, because the first one shares data table with encode func. and the other needs new table of 122 bytes - imho it's worth it, as the second function is significantly faster.
Enjoy! Wink

EDIT:
Newer version in the attachment:
- fixed error when 0 was passed as size
- option to put newline after each n-th character (for example, for MIME encoding)
- only one decoding function (the faster one)
- ignores characters from outside the decoding table


Description: BASE64
Download
Filename: BASE64.ZIP
Filesize: 2.95 KB
Downloaded: 610 Time(s)



Last edited by Reverend on 12 Feb 2007, 19:26; edited 1 time in total
Post 12 Feb 2007, 17:51
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Feb 2007, 18:01
base64 following which standard (there are more of them)?
supports padding?
what does it do if someone passes length=0?
supports breaking base64 data into multiple lines?
ignores all characters on base64_decode, as defined in RFC 2045?

Wink
Post 12 Feb 2007, 18:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 12 Feb 2007, 18:14
Asnwers:
- supports padding (ie. pads with '=')
- length = 0
a) encode will work ok
b) decode will fail - I'll have to change it Smile
- no breaking into multiple lines (may add it as an option - TRUE/FALSE flag will change behaviour)
- decode assumes all characters are ok - will have to change it Smile

Thanks for that post vid.
Post 12 Feb 2007, 18:14
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Feb 2007, 18:27
glad to see you take it seriously. Think about how to report error from procedures (bad base64 data, zero length). If you make these procedures seriously working, i would like to include them to FASMLIB

Quote:
no breaking into multiple lines (may add it as an option - TRUE/FALSE flag will change behaviour)

rather add option for number of chars per line, no breaking if it's zero.
Post 12 Feb 2007, 18:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 12 Feb 2007, 19:30
New version is in the first, edited post.
As for the error reporting:
- eax contains size of encoded/decoded data - so eax = 0 iff size = 0
- characters outside decoding table are not reported, they are just ignored.

I'd be happy if it shows in FASMLIB Smile
Post 12 Feb 2007, 19:30
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Feb 2007, 19:35
Quote:
- characters outside decoding table are not reported, they are just ignored.

not all characters should be ignored, only some of them...
Post 12 Feb 2007, 19:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 12 Feb 2007, 19:54
"Additionally it specifies that any extra-alphabetic characters must be ignored by a compliant decoder" (quote from http://en.wikipedia.org/wiki/Base64)

It was about MIME encoding and generally that was what I wrote BASE64 for.
Post 12 Feb 2007, 19:54
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Feb 2007, 20:29
you are right. But i find it pretty stupid Wink

But do not take wikipedia as reliable source, you must use the RFC next time Wink
Post 12 Feb 2007, 20:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 13 Feb 2007, 02:09
Vintage base64 encoding thread
http://board.flatassembler.net/topic.php?t=3063

The algorithm seems to run very fast on pentiums but it doesn't follow a standard implementation (input is null terminated string not sized buffer). But that can be easily changed.
Post 13 Feb 2007, 02:09
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 13 Feb 2007, 07:37
vid wrote:
you are right. But i find it pretty stupid Wink

But do not take wikipedia as reliable source, you must use the RFC next time Wink


I agree 100% with vid on this. WikiPedia is a great resource and can be used for some initial research, but you shouldn't use use it as an exclusive source of information, and you should always practice source criticism.

_________________
Image - carpe noctem
Post 13 Feb 2007, 07:37
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 13 Feb 2007, 14:47
vid, f0dder, I agree with both of you. And I do not take Wikipedia as a omniscient source Smile

r22, thanks for reminding me of this thread. I even joined discussion then and forgot of it Smile
Post 13 Feb 2007, 14:47
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.