Python Octal Escape String
Question: I'm doing a web application login automation. The web app prefix and suffix
few octal escaped character with password , make md5 hash of the password at
client side and send to server.

So when I Md5 encrypt the string using Java Script, I get below result.

The webapp uses <https://ideone.com/2C1b5> JS lib for client side MD5
conversion. **hexMD5()** belongs to that lib.

![enter image description here](http://i.stack.imgur.com/bAIG1.png)

But when I am trying to do the same using python I get different result.

    
    
    import hashlib
    def getMd5(string):
        m = hashlib.md5()
        m.update(string)
        return m.hexdigest()
    prefix = "\051"
    suffix  = "\341\303\026\153\155\271\161\166\030\054\324\011\046\035\344\274"
    
    prefix = unicode(prefix,'unicode-escape')
    suffix = unicode(suffix,'unicode-escape')
    salted = prefix+"HELLO"+suffix
    print getMd5(salted.encode('utf8'))
    

**Result**

    
    
    c7862e873e9bc54a93aec58c199cda37
    

Can any one please explain what I'm doing wrong here ?


Answer: 
    import hashlib
    def getMd5(string):
        m = hashlib.md5()
        m.update(string)
        return m.hexdigest()
    prefix = "\051"
    suffix  ="\341\303\026\153\155\271\161\166\030\054\324\011\046\035\344\274"
    
    
    salted = prefix+"HELLO"+suffix
    print getMd5(salted)
    
    37a0c199850b36090b439c3ac152fd70
    

Not using unicode gives the same output as your Javascript.

If I understand your comment correctly:

    
    
    len(r"\051" == 4 # use raw string r
    len("\051") == 1 
    

