I am trying to generate same output as http://php.net/manual/en/function.crypt.php crypt function (CRYPT_MD5 flavor).

So for example

$salt=crypt("2Ggaobjb","$1$1a2b3c4d$");

returns $1$1a2b3c4d$Y5tt50CQ12xW2saeYnI43, which is not same as pure MD5 hash (like $SYSTEM.Encryption.MD5Hash).

From documentation it seems that crypt creates derived hash based on MD5, but it is not the same.

Be careful when using ##Unique.

The problems with scope of generated "unique" variable can introduce weird bugs (in some cases it is not as unique as you would expect; WRC problems 879820 and 879901).

Citing ISC support from WRC 879820:

The problem is that the variable name created by ##Unique is only unique among the set of variables 
for that method. However, the variable itself is globally scoped. 

Since the variable name is globally scoped, I think the variable names should be unique for the 
entire class, not just for the method. I will report this to development. Please note, however, 
since the variable is globally scoped, using the preprocessor directive as you are here will leak 
information to any code that calls this class. To prevent this, you should NEW the variable prior 
to using it:
#define A(%x) NEW #Unique(new) SET #Unique(old)=%x 

Also ##Unique directives cannot be used in nested macros (macro calling another macro; WRC 879901).