-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidator.php
executable file
·99 lines (83 loc) · 2.67 KB
/
validator.php
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
<?php
//error_reporting(E_ALL ^ E_NOTICE);
//ini_set('display_errors', 1);
require "functions.php";
require "offset.php";
$scriptName = $_SERVER['PHP_SELF'];
$hashtagName = "h";
$hashtagValue = $_GET[$hashtagName];
$codeName = "c";
$codeValue = $_GET[$codeName];
$validString = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
if ($codeValue) {
$hashKey = arrayze($offset); //turns the word of the day into an offset array
$hashtag = arrayze($hashtagValue); //turns the inputted hashtag into an ascii character code array
for ($i = 0; $i < count($hashtag); $i++) { //applies offset and encrypt function to the hashtag array
$encryptor = $functions[$hashKey[$i%count($hashKey)]];
$hashtag[$i] = ($hashtag[$i] + $encryptor)%96 + 32;
if ($hashtag[$i] < 48) {
$hashtag[$i] += 192;
}
else if ($hashtag[$i] < 65 && $hashtag[$i] > 57) {
$hashtag[$i] += 183;
}
else if ($hashtag[$i] < 97 && $hashtag[$i] > 90) {
$hashtag[$i] += 152;
}
else if ($hashtag[$i] > 123 && $hashtag[$i] < 127) {
$hashtag[$i] += 69;
}
}
$firstChar = pickOne($validString);
$lastChar = pickOne($validString);
echo(urlencode($firstChar.reString($hashtag).$lastChar));
}
else {
$hashKey = arrayze($offset); //turns the word of the day into an offset array
$hashtag = substr($hashtagValue, 1);
$hashtag = substr($hashtag, 0, -1);
$hashtag = urldecode($hashtag);
$hashtag = arrayze($hashtag); //turns the inputted hashtag into an ascii character code array
for ($i = 0; $i < count($hashtag); $i++) { //applies offset and encrypt function to the hashtag array
if ($hashtag[$i] < 240 && $hashtag[$i] > 224) {
$hashtag[$i] -= 192;
}
else if ($hashtag[$i] < 248 && $hashtag[$i] > 240) {
$hashtag[$i] -= 183;
}
else if ($hashtag[$i] < 249 && $hashtag[$i] > 242) {
$hashtag[$i] -= 152;
}
else if ($hashtag[$i] > 192 && $hashtag[$i] < 196) {
$hashtag[$i] -= 69;
}
$hashtag[$i] -= 32;
$encryptor = $functions[$hashKey[$i%count($hashKey)]];
$hashtag[$i] = $hashtag[$i] - $encryptor;
while ($hashtag[$i] < 32) {
$hashtag[$i] += 96;
}
}
echo(reString($hashtag));
}
//UTILITY FUNCTIONS
//Takes a string and breaks it into an array of ascii decimal character codes
function arrayze($aString) {
$textArray = str_split($aString);
for ($i = 0; $i < count($textArray); $i++) {
$textArray[$i] = ord($textArray[$i]);
}
return $textArray;
}
//Takes an array of ascii decimal character codes and returns a string
function reString($anArray) {
for ($i = 0; $i < count($anArray); $i++) {
$anArray[$i] = chr($anArray[$i]);
}
$reStrung = implode($anArray);
return $reStrung;
}
function pickOne($string) {
return substr($string, rand(0,strlen($string)-1),1);
}
?>