I'm trying to extract some string from a file using python re, then MD5ing this string using something like:
#MD5er.py
salt = extract_salt(file_foo)
print 'salt: %s' % salt
from md5 import md5
print 'hash: %s' % md5(salt).hexdigest()
$python MD5er
salt: \0001\072\206\277\354\107\134\061\361\076\150\047\010\124\200\315\100
hash: ce24166858853dfb12a86d7d602b0638
BUT, using iPython like that:
In [40]: salt = '\0001\072\206\277\354\107\134\061\361\076\150\047\010\124\200\315\100'
In [41]: salt
Out[41]: "\x001:\x86\xbf\xecG\\1\xf1>h'\x08T\x80\xcd@"
In [42]: print salt
1:���G\1�>hT��@
In [43]: from md5 import md5
In [44]: md5(salt).hexdigest()
Out[44]: 'ebae47a953591f7448ff7079837fb534'
Any clues why the MD5 is different in the 2 scenarios? and why in ipython when I typed the variable name it appeared in a different format from the original string, and print() output was a third format!?
Hint:
In [53]: import sys
In [54]: sys.getdefaultencoding()
Out[54]: 'ascii'