-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.php
More file actions
54 lines (50 loc) · 1.04 KB
/
encrypt.php
File metadata and controls
54 lines (50 loc) · 1.04 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
<?php
$tmp = json_decode(file_get_contents('php://input'), true);
function shift($char,$sh)
{
$arr=array('a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z');
$arr2=array('A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$n=count($arr);
while($sh>$n-1)
$sh-=$n;
$index=-1;
for($i=0;$i<$n;$i++)
if($arr[$i]==$char)
{
$index=$i;
{
$shift=$index+$sh;
while($shift>$n-1)
$shift-=$n;
return $arr[$shift];
}
}
else if($arr2[$i]==$char)
{
$index=$i;
{
$shift=$index+$sh;
while($shift>$n-1)
$shift-=$n;
return $arr2[$shift];
}
}
if($index==-1)
{
return $char;
}
}
function encrypt_message($str,$sh)
{
$length=strlen($str);
for ($i=0;$i<$length;$i++)
{
$res[$i]=shift($str[$i],$sh);
}
$tmp['result']=implode($res);
echo json_encode($tmp);
}
encrypt_message($tmp['source'],$tmp['shift']);
?>