Skip to content

Commit 7309629

Browse files
committed
Fuck
0 parents  commit 7309629

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
index.php

composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "exan/phpfuck",
3+
"description": "PHP Fuck",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Exan\\PhpFuck\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "exanlv"
14+
}
15+
],
16+
"require": {}
17+
}

readme.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# PHPFuck
2+
3+
Fuck up your PHP
4+
5+
## Install
6+
7+
```
8+
composer require exan/phpfuck
9+
```
10+
11+
## Usage
12+
13+
```php
14+
use Exan\PhpFuck\Fucker;
15+
16+
require './vendor/autoload.php';
17+
18+
$fucker = new Fucker();
19+
20+
echo $fucker->fuckCode(<<<PHP
21+
echo "Hello, world!", PHP_EOL;
22+
PHP), PHP_EOL; // roughly 17kb
23+
```
24+
25+
### Reference
26+
27+
```php
28+
Exan\PhpFucker\Fucker::fuckInt(int $num)
29+
```
30+
Return a fucked version of any int
31+
32+
```php
33+
Exan\PhpFucker\Fucker::fuckString(string $input)
34+
```
35+
Return a fucked version of any(TM) UTF-8 string
36+
37+
```php
38+
Exan\PhpFucker\Fucker::fuckFunction(string $fn, array $args)
39+
```
40+
Return a fucked version of a function call, args are not automatically fucked
41+
42+
```php
43+
Exan\PhpFucker\Fucker::fuckCode(string $fn, array $args)
44+
```
45+
Return a fucked version of code. Input should not have PHP opening/closing tags
46+
47+
## Used characters
48+
- `(`
49+
- `)`
50+
- `[`
51+
- `]`
52+
- `@`
53+
- `!`
54+
- `,`
55+
- `"`
56+
- `.`
57+
- `+`
58+
- `^`

src/Fucker.php

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Exan\PhpFuck;
4+
5+
class Fucker
6+
{
7+
private array $alphabet;
8+
9+
public function __construct()
10+
{
11+
$this->alphabet['A'] = '@("".[])[' . $this->fuckInt(0) . ']';
12+
$this->alphabet['r'] = '@("".[])[' . $this->fuckInt(1) . ']';
13+
$this->alphabet['a'] = '@("".[])[' . $this->fuckInt(3) . ']';
14+
$this->alphabet['y'] = '@("".[])[' . $this->fuckInt(4) . ']';
15+
16+
$this->alphabet['q'] = $this->alphabet['A'] . '^' . $this->fuckInt(0) . '.' . '@([][' . $this->fuckInt(0) . '])';
17+
$this->alphabet['p'] = $this->alphabet['A'] . '^' . $this->fuckInt(1) . '.' . '@([][' . $this->fuckInt(0) . '])';
18+
$this->alphabet['s'] = $this->alphabet['A'] . '^' . $this->fuckInt(2) . '.' . '@([][' . $this->fuckInt(0) . '])';
19+
$this->alphabet['r'] = $this->alphabet['A'] . '^' . $this->fuckInt(3) . '.' . '@([][' . $this->fuckInt(0) . '])';
20+
$this->alphabet['t'] = $this->alphabet['A'] . '^' . $this->fuckInt(5) . '.' . '@([][' . $this->fuckInt(0) . '])';
21+
$this->alphabet['w'] = $this->alphabet['A'] . '^' . $this->fuckInt(6) . '.' . '@([][' . $this->fuckInt(0) . '])';
22+
$this->alphabet['v'] = $this->alphabet['A'] . '^' . $this->fuckInt(7) . '.' . '@([][' . $this->fuckInt(0) . '])';
23+
$this->alphabet['y'] = $this->alphabet['A'] . '^' . $this->fuckInt(8) . '.' . '@([][' . $this->fuckInt(0) . '])';
24+
$this->alphabet['x'] = $this->alphabet['A'] . '^' . $this->fuckInt(9) . '.' . '@([][' . $this->fuckInt(0) . '])';
25+
26+
$this->alphabet['Q'] = $this->alphabet['a'] . '^' . $this->fuckInt(0) . '.' . '@([][' . $this->fuckInt(0) . '])';
27+
$this->alphabet['S'] = $this->alphabet['a'] . '^' . $this->fuckInt(2) . '.' . '@([][' . $this->fuckInt(0) . '])';
28+
29+
$this->alphabet['c'] = $this->alphabet['Q'] . '^' . $this->fuckInt(2) . '.' . '@([][' . $this->fuckInt(0) . '])';
30+
$this->alphabet['b'] = $this->alphabet['Q'] . '^' . $this->fuckInt(3) . '.' . '@([][' . $this->fuckInt(0) . '])';
31+
$this->alphabet['e'] = $this->alphabet['Q'] . '^' . $this->fuckInt(4) . '.' . '@([][' . $this->fuckInt(0) . '])';
32+
$this->alphabet['d'] = $this->alphabet['Q'] . '^' . $this->fuckInt(5) . '.' . '@([][' . $this->fuckInt(0) . '])';
33+
$this->alphabet['g'] = $this->alphabet['Q'] . '^' . $this->fuckInt(6) . '.' . '@([][' . $this->fuckInt(0) . '])';
34+
$this->alphabet['f'] = $this->alphabet['Q'] . '^' . $this->fuckInt(7) . '.' . '@([][' . $this->fuckInt(0) . '])';
35+
$this->alphabet['i'] = $this->alphabet['Q'] . '^' . $this->fuckInt(8) . '.' . '@([][' . $this->fuckInt(0) . '])';
36+
$this->alphabet['h'] = $this->alphabet['Q'] . '^' . $this->fuckInt(9) . '.' . '@([][' . $this->fuckInt(0) . '])';
37+
$this->alphabet['`'] = $this->alphabet['Q'] . '^' . $this->fuckInt(10) . '.' . '@([][' . $this->fuckInt(0) . '])';
38+
39+
$this->alphabet['j'] = $this->alphabet['S'] . '^' . $this->fuckInt(9) . '.' . '@([][' . $this->fuckInt(0) . '])';
40+
41+
$this->alphabet['Z'] = $this->alphabet['j'] . '^' . $this->fuckInt(0) . '.' . '@([][' . $this->fuckInt(0) . '])';
42+
$this->alphabet['['] = $this->alphabet['j'] . '^' . $this->fuckInt(1) . '.' . '@([][' . $this->fuckInt(0) . '])';
43+
$this->alphabet['X'] = $this->alphabet['j'] . '^' . $this->fuckInt(2) . '.' . '@([][' . $this->fuckInt(0) . '])';
44+
$this->alphabet['Y'] = $this->alphabet['j'] . '^' . $this->fuckInt(3) . '.' . '@([][' . $this->fuckInt(0) . '])';
45+
$this->alphabet['^'] = $this->alphabet['j'] . '^' . $this->fuckInt(4) . '.' . '@([][' . $this->fuckInt(0) . '])';
46+
$this->alphabet['_'] = $this->alphabet['j'] . '^' . $this->fuckInt(5) . '.' . '@([][' . $this->fuckInt(0) . '])';
47+
$this->alphabet['\\'] = $this->alphabet['j'] . '^' . $this->fuckInt(6) . '.' . '@([][' . $this->fuckInt(0) . '])';
48+
$this->alphabet[']'] = $this->alphabet['j'] . '^' . $this->fuckInt(7) . '.' . '@([][' . $this->fuckInt(0) . '])';
49+
$this->alphabet['R'] = $this->alphabet['j'] . '^' . $this->fuckInt(8) . '.' . '@([][' . $this->fuckInt(0) . '])';
50+
51+
$this->alphabet['k'] = $this->alphabet['['] . '^' . $this->fuckInt(0) . '.' . '@([][' . $this->fuckInt(0) . '])';
52+
$this->alphabet['o'] = $this->alphabet['['] . '^' . $this->fuckInt(4) . '.' . '@([][' . $this->fuckInt(0) . '])';
53+
$this->alphabet['n'] = $this->alphabet['['] . '^' . $this->fuckInt(5) . '.' . '@([][' . $this->fuckInt(0) . '])';
54+
$this->alphabet['m'] = $this->alphabet['['] . '^' . $this->fuckInt(6) . '.' . '@([][' . $this->fuckInt(0) . '])';
55+
$this->alphabet['l'] = $this->alphabet['['] . '^' . $this->fuckInt(7) . '.' . '@([][' . $this->fuckInt(0) . '])';
56+
}
57+
58+
public function fuckInt(int $num): string
59+
{
60+
if ($num === 0) {
61+
return '+!![]';
62+
}
63+
64+
if ($num < 0) {
65+
return '+!![]' . str_repeat('-![]', abs($num));
66+
}
67+
68+
return str_repeat('+![]', $num);
69+
}
70+
71+
function fuckString(string $input): string
72+
{
73+
$chars = [];
74+
$split = str_split($input);
75+
76+
foreach ($split as $char) {
77+
$chars[] = isset($this->alphabet[$char])
78+
? $this->alphabet[$char]
79+
: $this->getCodePointReplacement($char);
80+
}
81+
82+
$chars = array_map(fn (string $char) => '(' . $char . ')', $chars);
83+
84+
return implode('.', $chars);
85+
}
86+
87+
public function fuckFunction(string $fn, array $args, bool $pretty = false): string
88+
{
89+
return '(' . $this->fuckString($fn) . ')' . '(' . implode(',', $args) . ')';
90+
}
91+
92+
private function getCodePointReplacement(string $char): string
93+
{
94+
$codePoint = mb_ord($char);
95+
96+
return $this->fuckFunction('mb_chr', [$this->fuckInt($codePoint)]);
97+
}
98+
99+
public function fuckCode(string $code): string
100+
{
101+
return '<?php eval(' . $this->fuckString($code) . ');';
102+
}
103+
}

0 commit comments

Comments
 (0)