title: Algorithm for generating a unique (constant) code for a string which should be reversible
body: <p>The requirement:</p>
  
  <p>We have values in DB like</p>
  
  <pre><code>Chennai
  Baroda
  Bangalore
  New Delhi
  São Paulo, Lisboa
  San Jose
  </code></pre>
  
  <p>etc...</p>
  
  <p>So I want to convert these string to a unique short string. For example</p>
  
  <pre><code>Chennai –&gt; xy67kr
  
  San Jose –&gt; iuj73d
  </code></pre>
  
  <p>basically something similar to URL shortner.</p>
  
  <p>And the algorithm to convert this should be reversible.. i.e when I pass "xy67kr" to a decode function it should give me back "Chennai".</p>
  
  <p>Looking forward for help.</p>