Package squidpony

Class LZSPlus

java.lang.Object
squidpony.LZSPlus

public final class LZSPlus
extends Object
LZ-String compression, taking Strings and compressing them to other Strings, optionally with some encryption. This role was performed by the BlazingChain library, which was a dependency of squidlib-extra, but recent developments have allowed all dependencies to be removed other than SquidLib, while also probably reducing memory usage by a fair amount. The actual implementation of this class is very unusual, with the LZ-String encoding part derived from rufushuang's lz-string4java (which is a port of pieroxy's lz-string), while the encryption-like part (which is not very strong) was added in SquidLib. This uses Garbler to do the encryption and LZSEncoding to do the compression; LZSEncoding uses the original JavaScript lz-string library almost verbatim when run on GWT, so it performs better than code that has been compiled to JavaScript from Java by GWT, and it performs like Java when run on a real JVM.
Created by Tommy Ettinger on 7/13/2017.
  • Constructor Summary

    Constructors 
    Constructor Description
    LZSPlus()  
  • Method Summary

    Modifier and Type Method Description
    static String compress​(String uncompressedStr)
    Compresses the given text using LZ-String compression; does not encrypt the result.
    static String compress​(String uncompressedStr, long[] keys)
    Compresses the given text using LZ-String compression and encrypts (somewhat) the compressed result so it can't be read back without the same keys as a long array.
    static String decompress​(String compressed)
    Decompresses text that was compressed with LZ-String compression; does not reverse decryption so it can only decompress Strings produced by compress(String), or compress(String, long[]) with an empty or null keys parameter.
    static String decompress​(String compressed, long[] keys)
    Decompresses text that was compressed with LZ-String compression, reversing any encryption if the keys long array matches the long array passed to compress(String, long[]) (keys can be null if no array was passed).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • compress

      public static String compress​(String uncompressedStr)
      Compresses the given text using LZ-String compression; does not encrypt the result.
      Parameters:
      uncompressedStr - text to compress
      Returns:
      a compressed version of the given text
    • compress

      public static String compress​(String uncompressedStr, long[] keys)
      Compresses the given text using LZ-String compression and encrypts (somewhat) the compressed result so it can't be read back without the same keys as a long array. Shorter long arrays give less security to encryption, though there isn't much security to begin with. You can produce a decent-quality array for this purpose with Garbler.makeKeyArray(int, String); the size parameter could reasonably be anywhere from 2 to 32. If the keys array is null or empty, this only compresses and does not perform an additional encryption step.
      Parameters:
      uncompressedStr - text to compress and optionally encrypt
      keys - the long array that will be used to encrypt the output, and will be required to decrypt the result; may be null
      Returns:
      a compressed and optionally encrypted version of the given text
    • decompress

      public static String decompress​(String compressed)
      Decompresses text that was compressed with LZ-String compression; does not reverse decryption so it can only decompress Strings produced by compress(String), or compress(String, long[]) with an empty or null keys parameter.
      Parameters:
      compressed - text that was compressed by compress(String)
      Returns:
      the original text, decompressed from the given text
    • decompress

      public static String decompress​(String compressed, long[] keys)
      Decompresses text that was compressed with LZ-String compression, reversing any encryption if the keys long array matches the long array passed to compress(String, long[]) (keys can be null if no array was passed).
      Parameters:
      compressed - text that was compressed by compress(String, long[])
      keys - the long array that was used to encrypt the output, and must match to decrypt the result; may be null
      Returns:
      the original text, decompressed and decrypted from compressed