Esempio n. 1
0
/**
 * This function takes some text and replaces about half of the characters
 * with HTML entity equivalents.   Return string is obviously longer.
 *
 * @param string $plaintext The text to be obfuscated
 * @return string The obfuscated text
 */
function obfuscate_text($plaintext)
{
    $i = 0;
    $length = textlib::strlen($plaintext);
    $obfuscated = '';
    $prev_obfuscated = false;
    while ($i < $length) {
        $char = textlib::substr($plaintext, $i, 1);
        $ord = textlib::utf8ord($char);
        $numerical = $ord >= ord('0') && $ord <= ord('9');
        if ($prev_obfuscated and $numerical) {
            $obfuscated .= '&#' . $ord . ';';
        } else {
            if (rand(0, 2)) {
                $obfuscated .= '&#' . $ord . ';';
                $prev_obfuscated = true;
            } else {
                $obfuscated .= $char;
                $prev_obfuscated = false;
            }
        }
        $i++;
    }
    return $obfuscated;
}
 /**
  * Tests the static utf8ord method
  * @return void
  */
 public function test_utf8ord()
 {
     $this->assertSame(textlib::utf8ord(''), ord(''));
     $this->assertSame(textlib::utf8ord('f'), ord('f'));
     $this->assertSame(textlib::utf8ord('α'), 0x3b1);
     $this->assertSame(textlib::utf8ord('й'), 0x439);
     $this->assertSame(textlib::utf8ord('𯨟'), 0x2fa1f);
     $this->assertSame(textlib::utf8ord('Ž'), 381);
 }
Esempio n. 3
0
 /**
  * Tests the static utf8ord method
  * @return void
  */
 public function test_utf8ord() {
     $this->assertSame(textlib::utf8ord(''), ord(''));
     $this->assertSame(textlib::utf8ord('f'), ord('f'));
     $this->assertSame(textlib::utf8ord('α'), 0x03B1);
     $this->assertSame(textlib::utf8ord('й'), 0x0439);
     $this->assertSame(textlib::utf8ord('𯨟'), 0x2FA1F);
     $this->assertSame(textlib::utf8ord('Ž'), 381);
 }