Archive for category code

If programming languages were religions

Posted by on Saturday, 27 December, 2008

It would be like that

mcrypt leaving garbage at end of decoded string

Posted by on Thursday, 6 November, 2008

I stumbled upon a problem with the mcrypt library – when decoding (using DES and ECB mode) the encoded string is trailed with leading non-printalbe ASCII characters.  So an encoded “mysecret1” becomes “mysecret1”.

Not shure what causes it, but i found a hack to get rid of those nasty low ASCII chars:


$password = preg_replace("/[\\x00-\\x1F]/", "", $password);

PHP bin2hex

Posted by on Monday, 27 October, 2008

In the hope to serve more people the pain of fiddling with this, I’ll keep some programming-snipplets in english.

Situation: you have HEX codes and need binary

Solution:

function hex2bin ($hex) {
    return pack("H*", $hex);
}