title: Efficient compression and representation of key value pairs to be read from 1D barcodes
body: <p>I'm currently writing an application for Windows Mobile which needs to be able to pick up key value pairs from 1D barcodes (configuration settings). The less barcodes need to be scanned, the better. Sample input:</p>
  
  <pre><code>------------------------------
  | Key | Value                |    
  ------------------------------
  | 12  | Söme UTF-8 Strîng    |
  |  9  | &amp; another string     |
  ------------------------------
  </code></pre>
  
  <p>I thought of the following algorithm:</p>
  
  <p><strong>1. Concat the key value pairs and encode the values with Base64</strong></p>
  
  <p>So we would get something like <code>12=U8O2bWUgVVRGLTggU3Ryw65uZw==&amp;9=JiBhbm90aGVyIHN0cmluZw==</code></p>
  
  <p><strong>2. Use Huffman encoding to compress the data</strong></p>
  
  <p>I'd use a fixed Huffman tree for this, with the following information that helps me to compress the data:</p>
  
  <pre><code>-------------------------------------------
  | Enties                       | Priority |    
  -------------------------------------------
  | =, &amp;                         | High     |
  | 0-9                          | Medium   |
  | 5-bit Base64 Words (w/o 0-9) | Low      |
  -------------------------------------------
  </code></pre>
  
  <p><strong>3. Generate Code 128B barcodes from the encoded data</strong></p>
  
  <p>Apply Base96 encoding to the bit stream generated by the Huffman algorithm to get ASCII chars which can be used within a Code 128B barcode. Split the resulting string into multiple barcodes as required.</p>
  
  <p>Coding this steps won't be a problem for me, but I would like to have some feedback about the efficiency and the design of the algorithm.</p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li>Am I losing some potential for better compression/shorter strings somewhere?</li>
  <li>Is there a better way to compress the random UTF8 encoded data?</li>
  <li>Should I embed a dynamic Huffman table into the encoded data?</li>
  <li>How can I take the compression of Code 128B into account (a <code>0</code> requires less space than a <code>&amp;</code>)?</li>
  </ul>