Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 30th, 2005, 6:11 PM   #11
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Quote:
Originally Posted by Cerulean
Gzip does a good job of getting text files waay down. You can then pad the data up to 400. Should be pretty easy.
Here's a template you can use when you code it in C++ - it's written in Python (solely because I got curious).
import zlib

def make400Bytes(s):
    assert len(s) > 400
    compressed = zlib.compress(s)
    if len(compressed) > 400:
        print "Ouch, data size compression problem. Dataset too big, or bad data"
        return None
    compressed = compressed + "#" * (400 - len(compressed))
    return compressed

def make600Bytes(s):
    return zlib.decompress(s.rstrip("#"))


before = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer at purus. Aliquam posuere nibh. Vestibulum vitae turpis non arcu venenatis luctus. Sed at nisi. Aliquam erat volutpat. Sed urna. Quisque sit amet arcu eu tellus luctus mollis. Phasellus rhoncus vulputate sem. Nunc lacinia nibh. Ut fermentum augue nec odio. Duis fringilla tincidunt elit. 
Mauris urna metus, placerat vitae, porttitor non, scelerisque et, libero. Donec nibh quam, mollis eget, placerat quis, sollicitudin in, magna. Nullam non urna. Vestibulum metus arcu, condimentum pellentesque, porttitor in, tempus ac, erat. Pelle"""
 
print "len(before) =", len(before) # 600
after = make400Bytes(before)
print "len(after) =", len(after) # down to 400
afterAfter = make600Bytes(after)
print "len(afterAfter) =", len(afterAfter) # back up to 600
I'm not sure, but I don't think the C zlib library is simple as the standard-library Python one with a "compress" and "decompress" function pair. If so, it should be quite easily to translate.
Hate to say this but I'm using javascript

I'll be sure to look at it though and see if I can apply it to JS.
Eryk is offline   Reply With Quote
Old Aug 30th, 2005, 6:17 PM   #12
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
So you're trying to store compressed text in a database instead of normal text? To make the database smaller?
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Aug 30th, 2005, 6:22 PM   #13
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
I'm writing a script to be used on third party software, which so happens to be a forum system. I creating an RPG, the information for each user will be stored in their signature, limited to 400 characters.

That's where the character limit comes from. It's nothing to do with file/db size.
Eryk is offline   Reply With Quote
Old Aug 30th, 2005, 7:20 PM   #14
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
hate to say this but I'm using javascript
Well, then either implement the zlib compression algorithm in JavaScript and use that, or just call a server-side script via XmlHTTPRequest that sends the data and receives the encrypted/decrypted version.
Cerulean is offline   Reply With Quote
Old Aug 30th, 2005, 7:39 PM   #15
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Thanks a lot for the idea. I can use PHP to implement it.
Eryk is offline   Reply With Quote
Old Aug 30th, 2005, 8:43 PM   #16
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Quote:
Originally Posted by Eryk
I'm writing a script to be used on third party software, which so happens to be a forum system. I creating an RPG, the information for each user will be stored in their signature, limited to 400 characters.

That's where the character limit comes from. It's nothing to do with file/db size.
You should've said that in your first post. Always try to be as descriptive as possible.

You're probably going to have a lot of trouble getting a meaningful display out of echoing compressed data into a signature. I'd suggest writing the information-creation routine so that it creates less data in the first place, or rewrite a whole other compression idea that is lossy (like shorthand) and gives a meaningful display of the data.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Aug 30th, 2005, 8:56 PM   #17
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
I understand the idea that detail is important, but I figured the maximum number of characters would be fine, and not why I wanted it that way.

The signature will be hidden using javascript, it's not meant to display the data directly, but rather to be read by javascript.
Eryk is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC