Solved

Shortening Base64 string result

Posted on 2013-05-31
8
1,752 Views
Last Modified: 2013-06-01
Hi,  I just converted the bytes I've read from a file with the Base64 type encryption so to make the bytes look ASCII string.  But the result is a very very very long string,  how can I do to encrypt this string again to make it shorter?
0
Comment
Question by:AlexMert
  • 3
  • 3
  • 2
8 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
If you want it to be shorter then, don't use Base64. If you do need it to be an ASCII string, then compress the data (using gzip or any other compression scheme) and then encode the compressed file as Base64. That is as short as you will be able to get it. If it's still too long, then you'll have to refactor something (What is in the file?).
0
 

Author Comment

by:AlexMert
Comment Utility
I don't want in no way to change the extension of the file or to depend by anything( cause only gzip can decompress it back so... ) And I don't do this for a specific file, it can be anything, and yes, I need at the final the result to be ASCII text
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
I need at the final the result to be ASCII text
Does that mean you can use any of the 128 ASCII characters rather than the 64 characters in the Base64 character set?  If so, you can reduce the size by 6/7
Does ASCII text mean you can use any of the 95 printable ASCII characters?
If so, you can, with a little more difficulty, reduce the size by not quite 21/23
0
 

Author Comment

by:AlexMert
Comment Utility
Yes any ASCII symbol :) anything ! But to be ASCII ! And short ! Thanks !
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
In order to get it much shorter, you will need to have some kind of compression. Adding the other 31 printable ASCII characters (as Ozo mentions) is only going to save you less than 10%.

What is the data representing? Do you control both the sender and the receiver? If so, you should be able to develop your own system for compressing the data.

You shouldn't be afraid of gzip or other third party utilities. You can build them into your application so you don't need to use them separately.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
I'm also wondering about the exact requirements here.
NUL and DEL are technically ASCII characters, but most situations that would allow their arbitrary use would also be able to handle 8 bit character sets.
What exactly is the cause for the need to restrict the character set?  This might clarify which symbols can be allowed and which cannot.
What makes dependence on a Base64 encoder (and I'm presuming you mean encoding and not encryption) acceptable, but dependence on gzip not acceptable?  What are the acceptable options we have to work with to construct a more compact representation?
And what is the nature of the source file?   Compression methods that are tuned to the particular characteristics of particular sets of data can usually do better than general purpose compression.
0
 

Author Comment

by:AlexMert
Comment Utility
Look. For example I want to read all the bytes from a Video File Type. Then I want to turn them into text , or ASCII to send them as that over the internet, then who receives this 'very long string' to take it back and transform or decrypt it back to the exact same bytes that that video had, basically I transfered the video to that person, but not in a binary format but in characters .

 The problem is that it must work with ANY file type and the string resulting after transforming the bytes into ASCII via Base64 is very very long ! I need somehow to encrypt or encode ( don't know whats the difference ) again that string to a more compact string .
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
The internet is an 8 bit medium, so the requirement for ASCII is still unexplained.
If the Base64 encoding is very very long, that means that the original file was very very long, and an 8 bit encoding, while 6/8 smaller than a Base64 encoding, would also be very very long.
If the purpose is to send over the internet, perhaps a URL to the file can be sent rather than an encoding of the file.
Compact URLs can be generated, for example, here http://tinyurl.com/
Another option may be to break up one very very long string into many very long strings,
or into many many long strings.
To compact by more than 6/8 or 6/7 or 21/23, it would be better to do video compression on the original file before ASCII encoding,
Then you might try a slightly more compact encoding such as Base85 http://en.wikipedia.org/wiki/Ascii85  or basE91 http://base91.sourceforge.net/ or yEnc http://www.yenc.org/yenc-draft.1.3.txt
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

You cannot be 100% sure that you can protect your organization against crypto ransomware but you can lower down the risk and impact of the infection.
This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now