minEntropy = $minEntropy; $this->minStrLength = $minStrLength; $upperChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $lowerChars = 'abcdefghijklmnopqrstuvwxyz'; $digits = '0123456789'; $special = '!"£$%^&*()_+-={}[]:@~;\'#<>,.?|\\'; $hex = 'ABCDEF0123456789abcdef'; $this->chars['upper'] = str_split($upperChars); $this->chars['lower'] = str_split($lowerChars); $this->chars['digits'] = str_split($digits); $this->chars['special'] = str_split($special); $this->chars['hex'] = str_split($hex); return $this; } public function loadFile($file) { if(strtolower(substr($file, 0, 4)) === 'http') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $file); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $this->fileContents[] = $data; } else { $this->fileContents[] = file_get_contents($file); } return $this; } public function findEntropy() { $final = []; if(!empty($this->fileContents)) { foreach($this->fileContents as $data) { $matches = []; preg_match_all('/([a-zA-Z0-9=._+-\/]{'.$this->minStrLength.',})/i', $data, $matches); if(!empty($matches)) { foreach($matches[0] as $match) { $entropy = 0; $charEntropyArr = str_split($match); foreach($charEntropyArr as $key => $char) { $idx = ($key == 0 ? 0 : $key - 1); $prev = $charEntropyArr[$idx]; foreach($this->chars as $key => $charGroup) { if(in_array($char, $this->chars[$key])) { $entropy += $this->plusWeight; // Check if it was in the same as the previous character's group if(!in_array($prev, $this->chars[$key])) { if($prev == $char) { $entropy -= $this->prevChar; } else { $entropy -= $this->prevGroup; } } } } } $this->found[] = ['string' => $match, 'entropy' => $entropy]; } } } } $return = []; if(!empty($this->found)) { foreach($this->found as $found) { if($found['entropy'] >= $this->minEntropy) { $return[] = $found; } } } return $return; } } $entropy = new Entropy(220, 20); $found = $entropy->loadFile('http://writing-backend.playground.easybib.com/config')->findEntropy(); foreach($found as $f) { printf("%s has the entropy of %d\n", $f['string'], $f['entropy']); }