Wednesday, December 3, 2008

Gems from Glibc

Today while browsing the (extensive) Glibc documentation, something caught my eye. A function named strfry. Now the expression 'frying a string' conjures up varied images, so I decided to check what it is. Basically it takes a string and replaces it with a pseudorandom anagram of itself in place. I can imagine a few uses for that. But more interesting is what the documentation has to say..
The function addresses the perennial programming quandary: “How do I take good data in string form and painlessly turn it into garbage?". ..for programs based on the GNU C library, the strfry function is the preferred method for destroying string data.
A standard way of destroying data? I mean, these guys are really meticulous. (Thank God for that).

Another interesting one is memfrob. The prototype is similar to memset, but instead of setting everything to 0, it ex-ors each byte with a constant (00101010b). Do it again and you get your original data back. ROT13 for binary data. Nice..

And I am sure there are many gems still hidden, just need to keep looking. But wait, doesn't that also apply to life?

No comments: