Skip to content

Instantly share code, notes, and snippets.

@levelsio
Last active May 5, 2023 12:33
Show Gist options
  • Save levelsio/537eb719733da685e538a8078ae0d4b8 to your computer and use it in GitHub Desktop.
Save levelsio/537eb719733da685e538a8078ae0d4b8 to your computer and use it in GitHub Desktop.
WordPress plugin to progressively obfuscate text like MAKEbook.io
/*
--PIETZ OBFUSCATE CODE--
2019-06-01
from MAKEbook.io
Instructions:
1) put this in your functions.php file
2) add this to the post you want to obfuscate, on top
3) [obfuscate]
4) to start obfuscating, add a HTML code or HTML block with <start></start>
5) to end obfuscating, add a HTML code or HTML block with <stop></stop>
6) it starts obfuscating from character 30,000, to change that, find this and change 30000 to something more or less: if($y<30000 ||
7) .....
8) PROFIT!
MIT licensed, no liability: u break ur site, ur problem not mine love ya <3
*/
function obfuscate() {
if(!is_single()) return;
ob_start("progressivelyObfuscateText");
}
add_shortcode('obfuscate', 'obfuscate');
$obfuscating='off';
function progressivelyObfuscateText($text) {
$constant=0;
$exponent=2;
$multiplier=10;
srand('1232993237');
$chars=str_split($text);
$alphabet='abcdefghijklmnopqrstuvwxyz';
$alphabet=str_split($alphabet);
$vowels='aeiouy';
$vowels=str_split($vowels);
$consonants='bcdfghjklmnpqrstvwxzw';
$consonants=str_split($consonants);
$obfuscatedText='';
$i=0;
$y=-1;
$insideHTMLTag=false;
foreach($chars as $char) {
$i++;
$y++;
$progress=$i/1500*$multiplier + pow($i/1500,$exponent) -$constant;
if($chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='<h1>') {
// reset progress if we find <h1> because it means new chapter
// so we progressively obfuscate again
$i=0;
}
if($chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='<h2>') {
// reset progress if we find <h2> because it means new head
// so we progressively obfuscate again
$i=0;
}
if($chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='<h3>') {
// reset progress if we find <h3> because it means new head
// so we progressively obfuscate again
$i=0;
}
if($chars[$y-5].$chars[$y-4].$chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='<stop>') {
// stop altogether with obfuscating if we get stop code
$i=0;
$obfuscating='off';
$obfuscatedText.=$char;
continue;
}
if($chars[$y-6].$chars[$y-5].$chars[$y-4].$chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='<start>') {
$obfuscating='on';
}
if($obfuscating=='off') {
$obfuscatedText.=$char;
continue;
}
if($chars[$y-2].$chars[$y-1].$chars[$y]=='<b>') {
$insideBoldTag=true;
$obfuscatedText.=$char;
// $obfuscatedText.='<hr>entering<hr>';
continue;
}
if($chars[$y-3].$chars[$y-2].$chars[$y-1].$chars[$y]=='</b>') {
$insideBoldTag=false;
$obfuscatedText.=$char;
// $obfuscatedText.='<hr>exiting<hr>';
continue;
}
if($char=='<') {
$insideHTMLTag=true;
$obfuscatedText.=$char;
continue;
}
if($char=='>') {
$insideHTMLTag=false;
$obfuscatedText.=$char;
continue;
}
if($insideHTMLTag || $insideHeaderTag || $insideBoldTag || $insideLinkTag) {
$obfuscatedText.=$char;
continue;
}
if($y<30000 || !ctype_alnum($char) || $char==' ' || $char=='"' || $char=='$' || $char=='/' || $char==',' || $char=='http://' || $char=="'" || $char=="\n" || $char=="\t" || $char=="\r") {
$obfuscatedText.=$char;
continue;
}
if(floor(1-rand(0,$progress))==1) {
$obfuscatedText.=$char;
continue;
}
if(in_array($char,$consonants)) $char=$consonants[array_rand($consonants)];
if(in_array($char,$vowels)) $char=$vowels[array_rand($vowels)];
$obfuscatedText.=$char;
}
return $obfuscatedText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment