title: Decode sessiondata of Django user which is encoded into base64 in Lua
body: <p>I am using redis with Lua to fetch <code>sessiondata</code> of any admin from Django project .In Django project <code>sessiondata</code> is encoded into base64 form.<br>
  sessiondata  value is :<pre>
  session_data = "NzlmZjZmNWQxMGIzNTQzMDZhNDZjNzJiZGQ4OWZiY2NjNDg0NDVlZTqAAn1xAShVEl9hdXRoX3VzZXJfYmFja2VuZHECVSlkamFuZ28uY29udHJpYi5hdXRoLmJhY2tlbmRzLk1vZGVsQmFja2VuZHEDVQ1fYXV0aF91c2VyX2lkcQSKAgEKdS4="
  </pre>
  My Lua code to decode session data is    </p>
  
  <pre>
  -- decode base64 code fetch from django session data
  local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  local function dec(data)
      data = string.gsub(data, '[^'..b..'=]', '')
      return (data:gsub('.', function(x)
          if (x == '=') then return '' end
          local r,f='',(b:find(x)-1)
         for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
          return r;
      end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
          if (#x ~= 8) then return '' end
          local c=0
          for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
          return string.char(c)
      end))
  end
  </pre>
  
  <p>when I am running <code>print(dec(session_data))</code> I am getting   </p>
  
  <pre>
  output = 79ff6f5d10b354306a46c72bdd89fbccc48445ee:�}q(U_auth_user_backendqU)django.contrib.auth.backends.ModelBackendqU _auth_user_idq� u. 
  </pre>
  
  <p>while output suppose to be <pre>
  {'_auth_user_id': 2561L, '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend'}
  </pre> like Django we had.</p>
  
  <p>Please let me know what I am doing wrong . </p>