Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Compress short fixed length string (52 characters) down to less than 40.

Compress short fixed length string (52 characters) down to less than 40.

Scheduled Pinned Locked Moved C / C++ / MFC
csscomalgorithmsquestionlounge
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hatemtaleb
    wrote on last edited by
    #1

    hello, I tried googling for an algorithm to compress/encrypt a shor fixed size string from 52 characters down to 40 but can't seem to find any. Target strings are random alphanumeric [A-Z0-9] e.g "M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL" I have tried huffman and smaz (https://github.com/antirez/smaz") and both inflated to size of the original string. Does anyone know a good algorith for such purpose? Thanks,

    J J D D 4 Replies Last reply
    0
    • H hatemtaleb

      hello, I tried googling for an algorithm to compress/encrypt a shor fixed size string from 52 characters down to 40 but can't seem to find any. Target strings are random alphanumeric [A-Z0-9] e.g "M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL" I have tried huffman and smaz (https://github.com/antirez/smaz") and both inflated to size of the original string. Does anyone know a good algorith for such purpose? Thanks,

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The characters in the given range are hex 0x30 to 0x5A. When subtracting 0x30, you will get a range from 0 to 0x2A which can be represented by 6 bits (there is also space for handling null when subtracting 0x29). The range can be additionally reduced by subtracting different values for digits and letters. When using 6 bits, you can compress the data to 52 / 8 * 6 = 39 byte. All you have to do is subtracting the offset from each character and shifting the 6 bits into your output buffer.

      1 Reply Last reply
      0
      • H hatemtaleb

        hello, I tried googling for an algorithm to compress/encrypt a shor fixed size string from 52 characters down to 40 but can't seem to find any. Target strings are random alphanumeric [A-Z0-9] e.g "M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL" I have tried huffman and smaz (https://github.com/antirez/smaz") and both inflated to size of the original string. Does anyone know a good algorith for such purpose? Thanks,

        J Offline
        J Offline
        Joe Woodbury
        wrote on last edited by
        #3

        Try LZ4 (http://code.google.com/p/lz4/[^]). It's great, though I don't know how much it would help you since that's a very short string and not very compressible as is.

        1 Reply Last reply
        0
        • H hatemtaleb

          hello, I tried googling for an algorithm to compress/encrypt a shor fixed size string from 52 characters down to 40 but can't seem to find any. Target strings are random alphanumeric [A-Z0-9] e.g "M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL" I have tried huffman and smaz (https://github.com/antirez/smaz") and both inflated to size of the original string. Does anyone know a good algorith for such purpose? Thanks,

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          If your input characters are all 0-127 ASCII, you could store 9 characters in 8 bytes. It only amounts to about a 12.5% savings (which does not meet your requirement), but it's easy enough to code up.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          1 Reply Last reply
          0
          • H hatemtaleb

            hello, I tried googling for an algorithm to compress/encrypt a shor fixed size string from 52 characters down to 40 but can't seem to find any. Target strings are random alphanumeric [A-Z0-9] e.g "M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL" I have tried huffman and smaz (https://github.com/antirez/smaz") and both inflated to size of the original string. Does anyone know a good algorith for such purpose? Thanks,

            D Offline
            D Offline
            dusty_dex
            wrote on last edited by
            #5

            I was just wondering, but have you made any progress with this? :)

            H 1 Reply Last reply
            0
            • D dusty_dex

              I was just wondering, but have you made any progress with this? :)

              H Offline
              H Offline
              hatemtaleb
              wrote on last edited by
              #6

              yes. the answer is base64. (since all characters are alphanumeric, they can be encoded in 6 bits instead of 8) btw, thank you all for your answers.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups