-
Notifications
You must be signed in to change notification settings - Fork 0
/
getcoord.php
96 lines (84 loc) · 2.25 KB
/
getcoord.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
<?php
require_once 'core/init.php';
//if(!Tokens::check(Input::get('hashCheck')))
//{
// if(Input::get('hashCheck') === Session::get('token_main'))
// Session::delete('token_main');
// elseif(Input::get('hashCheck') === Session::get('token_side'))
// Session::delete('token_side');
// else
// {
// header('Content-Type: application/json');
// echo json_encode(array('status' => 'error', 'data' => 'No direct Script Access Allowed'));
// die();
// }
//}
function caeser($value, $key){
$ciphertext = "";
$value = str_split($value);
for($i=0; $i<count($value); $i++)
$ciphertext .= ((ord($value[$i]) - ord("0") + $key)%10);
return $ciphertext;
}
$db = DB::getInstance();
$row = $db->get("coords", array('id', '=', 1))->first();
header('Content-Type: application/json');
if( !$db->error() && isset($_GET['test']))
{
$res = '[';
$res .= $row->coordside1.',';
$res .= $row->coordside2.',';
$res .= $row->coordside3.',';
$res .= $row->coordside4.',';
$res .= $row->coordside5.',';
$res .= $row->coordside6.']';
echo $res.PHP_EOL;
$obj = (object) array('x' => '366', 'y' => '548');
for($i=0; $i<count(json_decode($res)); $i++)
if(in_array($obj,json_decode($res)[$i]))
print_r(json_decode($res));
}
elseif(isset($_GET['coordside']))
{
$res = '[';
$res .= $row->coordside1.',';
$res .= $row->coordside2.',';
$res .= $row->coordside3.',';
$res .= $row->coordside4.',';
$res .= $row->coordside5.',';
$res .= $row->coordside6.']';
$decoded = json_decode($res);
$encrypted = array();
$ckey = mt_rand(1,8);
foreach ($decoded as $key => $value) {
$encrypted[$key] = array();
foreach ($value as $itemkey => $itemval) {
$encrypted[$key][$itemkey] = array(
'x' => caeser($itemval->x,$ckey),
'y' => caeser($itemval->y,$ckey)
);
}
}
$encrypted[count($decoded)] = md5($ckey);
echo json_encode($encrypted);
}
elseif(isset($_GET['main']))
{
$decoded = json_decode($row->coordinates);
$encrypted = array();
$ckey = mt_rand(1,8);
foreach($decoded as $key => $value){
$encrypted[$key] = array(
'x' => caeser($value->x,$ckey),
'y' => caeser($value->y,$ckey)
);
}
$encrypted[count($decoded)] = md5($ckey);
echo json_encode($encrypted);
}
else
{
$res = json_encode(array('status' => 'error', 'data' => "Some error occured!"));
echo $res;
}
?>