This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnemoencrypt.php
More file actions
155 lines (128 loc) · 3.67 KB
/
nemoencrypt.php
File metadata and controls
155 lines (128 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// namo's encryption thing
// IT'S PROBABLY A VERY WEAK ENCRYPTION SO DON'T USE IT
// FOR SENSITIVE DATA
namespace N14\Encrypt{
function crypt($str,$key,$prettyPrint=false){
$pk=prepareKey($key);
$sl=strlen($str);
$kl=strlen($key);
for($i=0; $i<$sl;$i++){
$str[$i] = chr(ord($str[$i]) ^ ord($pk[$i%$kl]));
}
return ($prettyPrint?strHex($str,true):$str);
}
function prepareKey($key){
$kseq=array();
$klen=strlen($key);
for($i=0; $i<$klen; $i++){
$kseq[$i] = $i & 255;
}
$prevkc=0;
$prevmp=0;
for($i=0; $i<$klen; $i++){
$kc=ord($key[$i]) ^ $prevkc;
$mischpos = abs(crc32($kc)^$prevmp) % $klen;
$kseq[$mischpos] ^= (crc32($kc) >> 8) & 0xFF;
if($mischpos<$klen-1)
$kseq[$mischpos+1]^=crc32($kc) & 0xFF;
else
$kseq[0]^=crc32($kc) & 0xFF;
$prevkc=$kc;
$prevmp=$mischpos;
}
/*2*/
$kfinal=array();
$kflen=max(hibit($klen-1) << 1,8);
$kops = $kflen << 2;
$pk=0;
for($i=0; $i<$kops; $i++){
if(isset($kfinal[$i])){
$orgpos = ($kfinal[$i%$kflen]&0xFF) % $klen;
$pk = $kfinal[$i%$kflen] ^= $kseq[$orgpos] ^ (crc32($pk+$i)&0xFF);
}else{
$orgpos = ($kseq[$i%$klen]&0xFF) % $klen;
$pk = $kfinal[$i%$kflen] = $kseq[$orgpos] ^ (crc32($pk+$i)&0xFF);
}
}
$ok="";
for($i=0; $i<$kflen; $i++){
$ok.=chr($kfinal[$i]);
}
return $ok;
}
function hibit($n) { // http://stackoverflow.com/a/53184
$n |= ($n >> 1);
$n |= ($n >> 2);
$n |= ($n >> 4);
$n |= ($n >> 8);
$n |= ($n >> 16);
return $n - ($n >> 1);
}
function strHex($str,$linebreaks=false){
$l=strlen($str) ;
$o="";
for($i=0; $i<$l;$i++){
if($linebreaks && $i && $i % 35 == 0) $o.="\r\n";
$o.=sprintf("%02X ",ord($str[$i]));
}
return trim($o);
}
function hexStr($str){
$hx=preg_replace("/([^0-9A-F]*)/i","",$str);
return pack("H*",$hx);
}
function strMoo($str,$linebreaks=false){
static $dict = array("Moo!","Moo.","Moo?","Moo,");
$l=strlen($str) ;
$o="Moo! ";
$mooCount=1;
for($i=0; $i<$l;$i++,$mooCount+=4){
$c=ord($str[$i]);
if($linebreaks && $mooCount && $mooCount % 5 == 0) $o.="\r\n";
$o.= $dict[($c>>6)&0x3] . " " . $dict[($c>>4)&0x3] . " " . $dict[($c>>2)&0x3] . " " . $dict[($c)&0x3] . " ";
}
return trim($o) . " Moo, Moo. Moo moo.";
}
function mooStr($str){
static $dict = array("Moo!"=>0,"Moo."=>1,"Moo?"=>2,"Moo,"=>3,"Moo"=>256);
$toks = explode(" ", $str);
$c=0;
$i=0;
$o="";
if(array_shift($toks)!=="Moo!"){
throw new Exception("Invalid Moo Sequence");
}
foreach($toks as $t){
if(isset($dict[trim($t)])){
$c <<= 2;
$c |= $dict[trim($t)];
if($c>256) break;
if(($i++) % 4 === 3){
$o.=chr($c);
$i = 0;
$c = 0;
}
}
}
return $o;
}
}
namespace{
if ( basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"]) ){
echo "<link rel='stylesheet' href='http://www.mm.pl/~namonaki/n14assets/css/crap.css'><h1>n14enc crappy gui</h1>evil tool for evil people. if you're not namonaki14, go being not-evil somewhere else.<br>";
if(isset($_POST['n14encCT']) && isset($_POST['n14encK'])){
if(strpos($_POST['n14encCT'],"Moo! ")===0){
$str=N14\Encrypt\mooStr($_POST['n14encCT']);
}else{
$str=N14\Encrypt\hexStr($_POST['n14encCT']);
}
$key=$_POST['n14encK'];
echo "result:<br><pre>".N14\Encrypt\crypt($str,$key)."</pre>";
} else{
echo "<form action='' method='POST'>Input hex: <textarea name='n14encCT' rows='10' cols='50'></textarea><br>Key: <input type='text' name='n14encK' size='70'/><br><input type='submit' value='dec'/></form><br>2013 namonaki14";
}
echo "<br><q>Love, love me do, You know I love you, I'll always be true, So please, Love me do.</q> -The Beatles.";
}
}
?>