Randomly obscures a string -- to be effective, must be used in a session environment where it can be re-displayed. Otherwise, someone could just hit reload until each of the letters was randomly revealed.
NOT state-of-the-art security.
function obscure_string($string, $freq=4)
{
// *** DATA
# internal
$_strlen = strlen($string);
$_i = 0;
$_NEW = array();
# return
$new_string = '';
// *** MANIPULATE
# traverse string
while ( $_i < $_strlen )
{
# randomly reveal char
if ( mt_rand(1,$freq) % $freq == 0 )
{
$_NEW[$_i] = $string[$_i];
}
# obscure
else
{
$_NEW[$_i] = '*';
}
# increment index
$_i++;
}
# implode new string
$new_string = implode($_NEW);
// *** RETURN
return $new_string;
}