MD4 and DES for unicode strings (samba passwd file manipulation)

Arcady Genkin agenkin at
Wed Sep 4 00:17:05 EDT 2002

I'd like to manipulate on Samba's password file from Python in order
to set/change samba passwords.  Samba stores the password encrypted
two ways: with DES algorithm, and hashed with MD4[1].  I found and
installed 'pycrypto' module[2], which provides the above algorithms.
And yet I can't create the right crypted strings:

  >>> from Crypto.Hash import MD4
  >>> m =
  >>> m.update( u'111222333' )
  >>> m.hexdigest().upper()
  >>> # SAMBA-encoded password "111222333":
  >>> samba

Perhaps the problem lies with Unicode encoding?  Samba's man page (see
the link below) says that the string is obtained by taking MD4 hash on
the password, represented as a string of 16-bit little-endian unicode

Any other ideas?  Any help greatly appreciated.


Arcady Genkin : CDF sysadmin :

guilt is the cause of more disauders
than history's most obscene marorders                       (E.E. Cummings)

More information about the Python-list mailing list