title: how to encode/decode a simple string
body: <p>I'm very new to encryption, I need to encode a simple string like <code>'ABC123'</code> into  something similar to that <code>'3d3cf25845f3aae505bafbc1c8f16d0bfdea7d70f6b141c21726da8d'</code>.</p>
  <p>I first tried this:</p>
  <pre><code>&gt;&gt;&gt; import base64
  &gt;&gt;&gt; q = 'ABC123'
  &gt;&gt;&gt; w = base64.encodestring(q)
  &gt;&gt;&gt; w
  'QUJDMTIz\n'
  </code></pre>
  <p>But it's to short, I need something longer, than I tried this:</p>
  <pre><code>&gt;&gt;&gt; import hashlib
  &gt;&gt;&gt; a = hashlib.sha224(q)
  &gt;&gt;&gt; a.hexdigest()
  '3d3cf25845f3aae505bafbc1c8f16d0bfdea7d70f6b141c21726da8d'
  </code></pre>
  <p>This is good, but now I don't know how to convert it back. If some one can help me eather with this example or suggest something else, how I can encode/decode a small string into a something longer, would be great.</p>
  <h1>UPDATE</h1>
  <p>based on <code>plockc</code> answer I did this, and it seems to work:</p>
  <pre><code>from Crypto.Cipher import AES # encryption library
  
  BLOCK_SIZE = 32
  
  # the character used for padding--with a block cipher such as AES, the value
  # you encrypt must be a multiple of BLOCK_SIZE in length.  This character is
  # used to ensure that your value is always a multiple of BLOCK_SIZE
  PADDING = '{'
  
  # one-liner to sufficiently pad the text to be encrypted
  pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
  
  # one-liners to encrypt/encode and decrypt/decode a string
  # encrypt with AES, encode with base64
  EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
  DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
  
  # create a cipher object using the random secret
  cipher = AES.new('aaaaaaaaaa123456')
  
  # encode a string
  encoded = EncodeAES(cipher, 'ABC123')
  print 'Encrypted string: %s' % encoded
  
  # decode the encoded string
  decoded = DecodeAES(cipher, encoded)
  print 'Decrypted string: %s' % decoded
  </code></pre>