Use File facade for files manipulation

This commit is contained in:
DariusIII
2019-01-07 15:30:02 +01:00
parent 041c4e2b33
commit 4ef4b2f6a0
5 changed files with 88 additions and 81 deletions
+71 -67
View File
@@ -1,13 +1,15 @@
<?php
use Illuminate\Support\Facades\File;
if (! isset($argv[1]) || ! isset($argv[2])) {
exit(
'Argument 1 is a input string. ie PRE name.'.PHP_EOL.
'Argument 2 is a expected hash or encoding. ie MD5 string. Passing true on Argument 3 ignores this.'.PHP_EOL.
'Argument 3 (optional) False, exit on first match. True, write all matches to text file in current path.'.PHP_EOL.
'ie: php test_hash_algorithms.php Dog.with.a.Blog.S02E16.Love.Loss.and.a.Beanbag.Toss.HDTV.x264-QCF 11506192c6d92e0c9c795b9997d9396226dbdf62'.PHP_EOL.
'ie: php test_hash_algorithms.php Anchorman.2.The.Legend.Continues.2013.UNRATED.WEBRip.x264-FLS false true'.PHP_EOL
);
'Argument 1 is a input string. ie PRE name.'.PHP_EOL.
'Argument 2 is a expected hash or encoding. ie MD5 string. Passing true on Argument 3 ignores this.'.PHP_EOL.
'Argument 3 (optional) False, exit on first match. True, write all matches to text file in current path.'.PHP_EOL.
'ie: php test_hash_algorithms.php Dog.with.a.Blog.S02E16.Love.Loss.and.a.Beanbag.Toss.HDTV.x264-QCF 11506192c6d92e0c9c795b9997d9396226dbdf62'.PHP_EOL.
'ie: php test_hash_algorithms.php Anchorman.2.The.Legend.Continues.2013.UNRATED.WEBRip.x264-FLS false true'.PHP_EOL
);
}
/**
@@ -43,11 +45,11 @@ class HashAlgorithms
{
$this->_inputString = $inputString;
$this->_expectedString = [
$expectedString,
strtolower($expectedString),
strtoupper($expectedString),
strrev($expectedString),
];
$expectedString,
strtolower($expectedString),
strtoupper($expectedString),
strrev($expectedString),
];
$this->_writeToFile = $writeToFile;
$this->_testStrings();
}
@@ -60,7 +62,7 @@ class HashAlgorithms
protected function _testStrings()
{
if ($this->_writeToFile) {
file_put_contents('hash_matches.txt', '');
File::put('hash_matches.txt', '');
}
$firstArray = $this->_hashesToArray($this->_inputString);
@@ -68,20 +70,20 @@ class HashAlgorithms
$secondArray = [];
foreach ($firstArray as $key => $value) {
if (! $this->_writeToFile) {
if (in_array($value, $this->_expectedString)) {
if (\in_array($value, $this->_expectedString, false)) {
exit(
'['.
$this->_inputString.
']=>['.
$key.
']=>'.
$value.
']'.
PHP_EOL
);
'['.
$this->_inputString.
']=>['.
$key.
']=>'.
$value.
']'.
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt', $key."\t\t".$value.PHP_EOL, FILE_APPEND);
File::put('hash_matches.txt', $key."\t\t".$value.PHP_EOL, FILE_APPEND);
}
$secondArray[$key] = $this->_hashesToArray($value);
}
@@ -90,24 +92,24 @@ class HashAlgorithms
foreach ($secondArray as $key => $value) {
foreach ($value as $key2 => $value2) {
if (! $this->_writeToFile) {
if (in_array($value2, $this->_expectedString)) {
if (\in_array($value2, $this->_expectedString, false)) {
exit(
'['.
$this->_inputString.
']=>['.
$key.
']=>['.
$firstArray[$key].
']=>['.
$key2.
']=>['.
$value2.
']'.
PHP_EOL
);
'['.
$this->_inputString.
']=>['.
$key.
']=>['.
$firstArray[$key].
']=>['.
$key2.
']=>['.
$value2.
']'.
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt', $key.' => '.$key2."\t\t".$value2.PHP_EOL, FILE_APPEND);
File::put('hash_matches.txt', $key.' => '.$key2."\t\t".$value2.PHP_EOL, FILE_APPEND);
}
$thirdArray[$key][$key2] = $this->_hashesToArray($value2);
}
@@ -119,28 +121,30 @@ class HashAlgorithms
if (! $this->_writeToFile) {
if (in_array($value3, $this->_expectedString)) {
exit(
'['.
$this->_inputString.
']=>['.
$key.
']=>['.
$firstArray[$key].
']=>['.
$key2.
']=>['.
$value2.
']=>['.
$key3.
']=>['.
$value3.
']'.
PHP_EOL
);
'['.
$this->_inputString.
']=>['.
$key.
']=>['.
$firstArray[$key].
']=>['.
$key2.
']=>['.
$value2.
']=>['.
$key3.
']=>['.
$value3.
']'.
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt',
$key.' => '.$key2.' => '.$key3."\t\t".$value3.PHP_EOL, FILE_APPEND
);
File::put(
'hash_matches.txt',
$key.' => '.$key2.' => '.$key3."\t\t".$value3.PHP_EOL,
FILE_APPEND
);
}
}
}
@@ -157,15 +161,15 @@ class HashAlgorithms
protected function _hashesToArray($string)
{
$strings = [
'input' => $string,
'lower' => strtolower($string),
'lower_reverse' => strtolower(strrev($string)),
'upper_reverse' => strtoupper(strrev($string)),
'upper' => strtoupper($string),
'reverse' => strrev($string),
'reverse_upper' => strrev(strtoupper($string)),
'reverse_lower' => strrev(strtolower($string)),
];
'input' => $string,
'lower' => strtolower($string),
'lower_reverse' => strtolower(strrev($string)),
'upper_reverse' => strtoupper(strrev($string)),
'upper' => strtoupper($string),
'reverse' => strrev($string),
'reverse_upper' => strrev(strtoupper($string)),
'reverse_lower' => strrev(strtolower($string)),
];
$hashTypes = ['md5', 'md4', 'sha1', 'sha256', 'sha512'];
$tmpArray = [];