I am trying to encrypt some text messages using mcrypt from php and the cipher Rijndael, but I am not sure about the MCRYPT\_MODE\_modename (according to PHP's manual these are available "ecb", "cbc", "cfb", "ofb", "nofb" or "stream" but I read there are actually a few more). I have no idea what each one do or how to use them.

I read two things, that ECB mode should not be used and MCRYPT\_RAND neither. They didn't explain why. For the ECB mode I guess it's because it always generate the same encrypted output for the same plain text (maybe this could be used for an attack), no idea about MCRYPT\_RAND (mentioned by @azz [here](https://stackoverflow.com/questions/5108408/php-mcrypt-which-mode)).

My question is, *what mcrypt mode should I use, and it would be great to see an example of php code using* it because all the examples I found use ECB. The strings I am trying to encrypt will contain only ascii text, and variable length, not bigger than 500 chars.