Simple String Compression Functions

Hi all !
I need two simple String compression functions, like
String compress(String what)
and
String decompress(String what)
myString.equals(decompress(compress(myString)))
should result in true.
Primarily I want to encode some plain text Strings so they are not too easy to read, and compression would be a nice feature here.
I already tried the util.zip package, but that one seems to need streams, I simply need Strings.
Any ideas ??
thx
Skippy

It does not do any compression, in fact it does
expansion to better encrypt the string (about 50%).How does that work? You want encryption to
decrease entropy.Why in the world do you say that, pjt33? What a very odd statement indeed. I sure hope you don't work in security, or I do hope you work in security if I'm a bad guy, or a competitor.
Let's say you had a 6-character string you wanted to encrypt.
Well, if you didn't increase the entropy, any 6-character plaintext string would have a 6-character encoded equivalent. And if you decreased entropy (e.g. coding the most commonly used words to shorter strings,) it gets even easier to decrypt.
Presumably there would be no hash collisions, after all, you want this to be reversible.
Hash collisions decrease entropy too, and, by doing so, make it easier to find a plaintext string that happens to hash to a certain value. This is a Bad Thing.
Now, to decode this, the Bad Guy only has to consider the set of 6-character strings and their hash values. You could even precalculate all of the common dictionary words, and everything with common letters and punctuation, making decryption virtually instantaneous. Especially if you had decreased the entropy in the signal, making fewer things I had to try.
But somebody who increased the entropy of their signal by adding random bits and increasing the encrypted size of the message to, say, 64 characters, would make it a lot harder to decrypt.
The ideal encryption system is pure noise; pure randomized entropy. An indecipherable wall of 0 and 1 seemingly generated at random. Statistical methods can't be used against it; nothing can be deciphered from it; it's as decipherable and meaningless as radio hiss. Now that's encryption!

Similar Messages

  • Simple button not functioning?

    I've been staring at this code for an hour. Maybe I need a break? This is a very simple button that just won't accept my touch events.
    I have a movie clip. It's instance name is "boardA." The name of the symbol is "letterA" and it is linked to a class file called "Letters" (which is properly linked, I checked).
    This is the code in the class file:
    public function Letters() {
                this.addEventListener(TouchEvent.TOUCH_BEGIN, createLetter);
                trace (this.letter);
            public function createLetter(e:TouchEvent): void {
                trace ("You clicked it!");
                trace ("eName = " + e.target.letter);
    Yet nothing happens when I click the button. The constructor for the file never executes.
    I even moved the touch event to the main frame "boardA.addEventListener(TouchEvent.TOUCH_BEGIN, createLetter)" and it still didn't work. Nothing when I touch the button.
    What am I missing here?
    Thanks
    Amber

    No. Letters.as is in com/freerangeeggheads/spellmaster. It's linked as such - here is the text.
    The base class is: com.freerangeeggheads.spellwhiz.Letters
    The class is: letterA
    When I click the green check box it tell me it can find the class, and when I click the edit class button it takes me to the proper script file.
    I also have the file imported into my main frame.
    This is the Letters.as file:
    package  com.freerangeeggheads.spellwhiz {
        import flash.display.*;
        import flash.events.*;
        import com.freerangeeggheads.spellwhiz.*;
        public class Letters extends MovieClip {
            public var letter:String = "";
            public function Letters(): void {
                this.addEventListener(TouchEvent.TOUCH_BEGIN, createLetter);
                trace (this.letter);
            public function createLetter(e:TouchEvent): void {
                trace ("You clicked it!");
                trace ("eName = " + e.target.letter);
    Thanks!

  • Simple LZW Compression Algorithm

    I have to write a very simple LZW algorithm based on the following psuedocode as part of my final year thesis.
    1. word=" ";
    2. while not end_of_file
    x=read_next_character;
    if word + x is in the dictionary
    word = word + x
    else
    output the dictionary index for word;
    add word + x to the dictionary;
    word = x;
    3. end_of_file now true;
    output the dictionary number for word;
    I have implemented this in Java (code follows)
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class LZWencode
         public static void main (String [] args) throws IOException
              String original = "ACBBAAC";
              String compressed = "";
              String word = "";
              char x;
              Vector dictionary = new Vector ();
              BufferedReader in = new BufferedReader(new FileReader("dictionary.txt"));
              String t=in.readLine();
              while (t!=null)
                   dictionary.addElement(t);
                   t=in.readLine();
              for(int i=0;i<original.length();i++)
                   x=original.charAt(i);
                   for(int k=1;k<=dictionary.size();k++)
                        if((word + x).equals(dictionary.elementAt(k)))
                             word = word + x;
                             System.out.println(word);
                        else
                             compressed = compressed + dictionary.indexOf(word) ;
                             dictionary.add(word + x);
                             System.out.println(dictionary.indexOf(word+x));
                             word = x + "";
                   break;
              System.out.println(compressed);
    }but it seems to skip the if word is in dictionary bit and go straight to else each time through the for loop. The dictionary is a .txt file with three entries A, B
    and C which is read into a vector which is then updated. The vector is updated with new dictionary entries but the program can't seem to find them!
    Sorry for the poor description of my problem - hope someone can help!

    Thanks a lot. Works absolutly fine except for one small change. When it gets to the end of file it misses out the code for the last word. I've managed to fix this by making a slight change to include a clause when the word is in the dictionary and is at the end of the file - if(i==(original.length()-1))..............
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class LZWencode
         public static void main (String [] args) throws IOException
              String original = "ACBBAAC";
              String compressed = "";
              String word = "";
              char x;
              Vector dictionary = new Vector();
              BufferedReader in =     new BufferedReader(new FileReader("dictionary.txt"));
              String t = in.readLine();
              while (t != null)
                   dictionary.addElement(t);
                   t = in.readLine();
              for (int i = 0; i < original.length(); i++)
                   x = original.charAt(i);
                   boolean found = false;
                   for (int k = 0; k < dictionary.size(); k++)
                        if ((word + x).equals(dictionary.elementAt(k)))
                             word = word + x;
                             found = true;
                             if(i==(original.length()-1))
                                  compressed = compressed + dictionary.indexOf(word);
                             break;
                   if (!found)
                        compressed = compressed + dictionary.indexOf(word);
                        dictionary.add(word + x);
                        word = x + "";
              System.out.println(compressed);
    }

  • Error in simple user defined function

    Hi all,
    I have seen one simple user defined function on scenario. Now it is working fine. Same code I have used another place. But it is giving some errors
    D:/usr/sap/C08/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc6fa0c70297511dbaf7e00c09f4504e7/source/com/sap/xi/tf/_ST_MM_.java:3: package javax.mail.internet does not exist
    import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import javax.mail.internet.;import javax.mail.;import java.util.;import java.util.Date;import javax.activation.;import java.lang.reflect.;import javax.mail.event.*;
    Like that it has shown 13 errors. I have given the package names in imports field what previous function has.

    Hi,
    Please see this from SAP help
    <i>a.      You can import Java packages to your methods from the Imports input field, by specifying them separated by a comma or semi-colon:
    You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since all message mappings require these packages and therefore import them. You should be able to access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the package under Import. In other words, you do not have to import it as an archive into the Integration Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
    In addition to the standard packages, you can also specify Java packages that you have imported as archives and that are located in the same, or in an underlying software component version as the message mapping.
    b.      Create your Java source text in the editor window or copy source text from another editor.</i>
    http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
    Regards
    Vijaya

  • Simple Javascript date() function not executing.

    If I open the javascript input window from a button and enter a simple js date function:
    vDate = new Date();
    alert(vDate();
    This code executes flawlessly when the button is clicked.
    However,  if I place the exact same code in the Execute Advacned Actions javascript window "on enter frame" Action, the alert popup code not exdecute/appear, it will fail silently.
    I'm simple trying to get a javascript funtion to execute on... the On Enter Action.
    Any suggestions?
    Thanks

    Hello,
    I just tried the scenario and I can see that JS code is executing properly. I used the same JS as you have given (just corrected the syntax in the second line). So, I create an Advanced action that has this JS, and I assigned that to "On Slide Enter" action of the slide. Other thing that I did is that I chose "current" as the window in the Execute Javascript options.
    Ashish

  • Help with compress function--file sizes not substantially reduced

    I've tried to use the compress function (right click "compress" or Finder/File/Compress) a few times on files from a variety of different programs. While this results in creating a zip file, the file size is not substantially reduced (e.g., from 43.4 MB to 42.9 MB). Is there a way to change how much a file is compressed?
    Thanks in advance for your help.
    Eric

    Not all material is very compressible. Text files and word processor documents usually compress very well. Photos and movies don't compress much if at all due to the nature of their structure (in some cases, using a general-purpose compressor can actually make a file larger). So it will depend on what it is you're compressing.

  • How to know the no. of bytes in a String Control Function?

    Hi,
    I would like to know the no. of bytes for a certain String Control Data.
    For instance, if i have a String Length Function, on the left is a String Control and on the right is a Length Indicator.
    If i will type coordinates, i.e. 9.25,4.25 on the String Control it will show 9 on the Length Indicator. I think 9 do not mean 9 bytes but
    only a length. Is there any function in LV that will tell me the total bytes of the data on the string control?
    Appreciate for any advise.
    Thanks a lot.

    Thanks tst for your kind reply.
    Here is what i am trying to find/goal.
    I will be using wireless receiver for my system. The wireless receiver have some signal strength ranges; 95dbm @ 1Mbps (mega bit per sec), 90dbm @ 11Mbps, 82 dbm @ 24 Mbps and 75dbm @ 54 Mbps. Ofcourse i prefer to have lower data transfer rate so that my signal strength is best.
    I will be sending coordinate data/s via wireless communication using string controls. But i do not know how big/heavy is my coordinate data
    If i can know how many bytes or mega bytes the data i want to send then i will be able to transfer it to bits or mega bits(8 bits = 1 byte) thus i will know which setting i can use for the wireless receiver. And if the data is too big then i have a basis to redesign my data transfer to suite a better signal strength.
    Thanks for your help.

  • Pad leading zeros in a string.Format function

    How could use the string.Format function and in the format text pad a leading zero? 
    Pseudo code is:
    string parm = “5”;
    string format = “Some number formatted as 3 dig: Format({0}, 000)”;
    string output = string.Format(format, parm);
    Where the output would look like this:
    “Some number formatted as 3 dig: 005”
    Thanks.

    Thanks everyone. Unfortuantly there's a constraint where the padding operation needs to be embedded in the format string. This entire operatin is being put together dynamically where the format strings are being pulled from a library of format strings stored
    in a database. at runtime we don't know how which format will be used and how many parameters will be passed in. we have logic to handle the unknown number of paramters as there is metadata which helps us with that.
    the need for leading zeros needs to be part of the overall format defined in the format string.  for example, a real format string stored in the database looks like this:
    "LINE_NO = '{0}',  AND GEO_LOCATION = 'T{1}, {2},  R{3}, {4}, , Sec. {5}'"
    and its output from the string.Function is:
    "LINE_NO = 'TG-G2469',  AND GEO_LOCATION = 'T155, N,  R93, W, , Sec. 5'"
    the last parameter (param 5) had a value of 5.  In another case the output requirement might need to look like this:
    "LINE_NO = 'TG-G2469',  AND GEO_LOCATION = 'T155, N,  R93, W, , Sec. 05'"
    note the "05" at the end...
    the logic of using the leading zero needs to be embedded in the overall format string text.
    Thank you.

  • Simple string question

    I want to compare two strings, suppose that:
    first string = "-Hello"
    second string = " -Hello"
    I want that both return same result.
    A lot of thanks!

    i would filter out all whitespaces first and the use the string.compare() function.
    write a open methode that allows you to filer out any char in any string and returns the filtered string. you can do so by building a while (indexOf(char)) loop and cutting out the unwanted chars with the subString() command.

  • Help with a simple pause-code function

    For a week I've been trying to figure out a simple pause-code
    function fror AS 3.0. I need something that pauses AS code for set
    amounts of time. People have tried to help me on this forum, but
    I've still not been able to make the code work.
    Here is what I have at the moment for pause-code (not
    working):
    var intID;
    intID = setInterval(delay, 3000); //this tells flash to wait
    3 seconds
    function delay(){
    clearInterval(intID);
    _root.gotoAndPlay(1); // or do something else...
    The person who supplied me with this code did not include the
    first line "var intID", but as a new flash user, I wasn't sure how
    else to declare intID. Could someone with some flash experience
    walk me through the steps of creating a pause-code function or add
    to the one I have already provided. When I use the above code in my
    flash document, the pause feature does not work at all. It
    essentially skips over the setInterval and clearInterval functions
    and plays the root clip in delay(). I need code meant for AS 3.0
    and I'm becoming increasingly desperate for a response.
    I hope this is understandable and thank you for taking a
    look,
    Sam

    Hello KGlad,
    Thankyou for that information. I had no idea lol. Could you
    please clarify and explain a little more about using the timer
    class to delay execution of code? Possibly provide an example? I
    would be very grateful.
    Thanks,
    Sam

  • Determine length of string without function module

    hai experts,
    i need to know how to determine length of string without function module strlen'
    regards,
    karthik

    Please SEARCH in SCN before posting.

  • Typecasting String to Function in AS3

    Hi,
    I would like to typecast a String to Function. The following is the code snippet,
    var  
    var funcionVar:Function = functionName as Function;
    bt.addEventListener(MouseEvent.CLICK,funcionVar);
    public function onSearch(event:MouseEvent) {
    // Code here
    While converting String to Function, it is returning null value. Is there any possible ways to achieve this?
    Thanks,
    Srinivasan S
      functionName:String = "onSearch" ; 

    This is the code snippet,
    var functionName:String = "onSearch";
    var funcionVar:Function = functionName as Function;
    bt.addEventListener(MouseEvent.CLICK,funcionVar);
    public function onSearch(event:MouseEvent) {
    // Code here
    Could you please help to resolve this?
    Thanks,
    Srinivasan S

  • [SOLVED]handy compress function similar to extract in Core Utilities?

    Hi!
    I was wondering if there is a similar, easy, compress-function to be added to .basrc, like the the extract function at:
    https://wiki.archlinux.org/index.php/Core_Utilities
    Would be cool to just write:
    compress archive.tar.gz [files]
    compress archive.zip [files]
    Maybe I should learn some bash scripting?
    Last edited by penguin (2011-02-24 17:12:26)

    thayer wrote:# roll - archive wrapper
    # usage: roll <foo.ext> ./foo ./bar
    roll()
    FILE=$1
    case $FILE in
    *.tar.bz2) shift && tar cjf $FILE $* ;;
    *.tar.gz) shift && tar czf $FILE $* ;;
    *.tgz) shift && tar czf $FILE $* ;;
    *.zip) shift && zip $FILE $* ;;
    *.rar) shift && rar $FILE $* ;;
    *) echo "'$1' is not a valid archive type"
    esac
    Yes, this was what I had in mind, thanks, I'll try it out.
    falconindy wrote:compress is a real thing. It uses LZW compression.
    Oh, yes, you're quite right, I did not think of that.

  • Sequential Saving with Images (Perhaps just simple string functions)

    Hello, I'm trying to save an image sequentially but in a specific format. Currently, I choose a folder path (the folder all the images will be saved under), the image name, and then the iteration number causes the image to change sequentially with each capture. As of now, the images are labelled "Image1.jpg", "Image2.jpg", etc. Unfortunately, this causes a problem with some of the other software I run the images through afterwards. In order to interpret the images correctly, the file names all have to be under the form "Image0001", "Image0002", etc. While I could (and have) change the Image Name path to "Image000", this adds to later iterations, causing a problem where the file name is now "Image0001000".
    Is there some way to change the path structure so that the images save as "Image0001",...,"Image0010",...,"Image0100",...,"I​mage1000", etc?
    Solved!
    Go to Solution.
    Attachments:
    Example.vi ‏8 KB

    Something that might work is just starting the for loop at iteration 1000. That way, I'd have a long time in the 4-digit iteration file name. DOes anyone know how to change the iteration number to 1000 to start with?

  • Unflatten From String Not Functioning in Mobile Module 2011

    Mobile Module does not get updated since version 2011. I am not sure my question will be solved. 
    I have been using Simple Messaging Reference Library (STM) for a couple of years. I use them in my Mobile Module code too. It has been working fine until lately I updated to the latest version of STM.
    I noticed that 'Read Message (TCP).vi' was not functioning properly in the Mobile Module code. After a long debugging, I found the source of the problem. 'Unflattern From String.vi' does not work in Mobile Module any more. I did a test as shown above. 
    My questions are
    1). 'Unflattern From String' was changed so it is not supported in Mobile Module 2011?
    2) Why the same code worked before, but not now?
    I use LabVIEW 2011 and Mobile Module 2011. Thanks. 

    MengHuiHanTang wrote:
    Mobile Module does not get updated since version 2011. I am not sure my question will be solved. 
    I have been using Simple Messaging Reference Library (STM) for a couple of years. I use them in my Mobile Module code too. It has been working fine until lately I updated to the latest version of STM.
    I noticed that 'Read Message (TCP).vi' was not functioning properly in the Mobile Module code. After a long debugging, I found the source of the problem. 'Unflattern From String.vi' does not work in Mobile Module any more. I did a test as shown above. 
    My questions are
    1). 'Unflattern From String' was changed so it is not supported in Mobile Module 2011?
    2) Why the same code worked before, but not now?
    I use LabVIEW 2011 and Mobile Module 2011. Thanks. 
    Is that the real code or just a mockup to demonstrate the issue?  I'm asking because the code is set up to run once and then wait until the stop button is pressed.  Then the VI will complete and exit.  Is the the desired behavior?
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Maybe you are looking for

  • Problem with JBoss startup in a zone

    Hi! I try to run JBoss inside a sparse-root zone, but encounter a problem during startup, it simply stucks always at a certain point. This is how the zone is configured: root@mantis:/usr/local/Dtrace # zonecfg -z setam-test zonecfg:setam-test> info z

  • How do I migrate my extensive ipad files and apps from my old iMac to my new windows machine?

    I had to go to a windows machine. All of my stuff, apps, books, music, pictures, etc. is on my iMac. Is there any way to gracefully move the information  from the iMac to the windows machine? It's about 60 GB.

  • How do you display the SQL that BEx uses?

    All, I would like to display the SQL that is submitted to BEx.  I understand you can perform a SQL Trace (ST05), but I want to see the SQL before is submitted to BEx.  Can anyone help me. Thanks.

  • Can't install new flash using winetricks

    I am not able to install any newer Flash then the default Flash 7 which can be found inside bin32-wine. When I ran a program which opens a Flash animation and I right-click it, I get "About Macromedia Flash Player7" I tried using winetricks: [warnec@

  • How can i turn off my laptop display when connected to an external monitor

    Hi, How can I make my laptop monitor turn off when connected to the 27 inch cinema disply? When connected to the Cinema display and the Laptop is open,the display on the laptop shows my wallpaper screen.  Is there a way to have the laptop display tur