-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipher.php
48 lines (46 loc) · 968 Bytes
/
cipher.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
<?php
// caesar cipher
// offset changes every 100 seconds
function encrypt($string,$timestamp){
$x = (string)$timestamp;
$salt = intval($x[7]);
$hash = array();
for($i = 0;$i<strlen($string);$i++){
$ascii_val = ord($string[$i]);
if($ascii_val<65){
$sum = ((int)$string[$i] + $salt)%10;
}else{
$sum = $salt + $ascii_val;
if($sum>91){
$sum+=64;
}
$sum = chr($sum);
}
array_push($hash,$sum);
}
return implode($hash);
}
function decrypt($string,$timestamp){
$x = (string)$timestamp;
$salt = intval($x[7]);
$hash = array();
for($i = 0;$i<strlen($string);$i++){
$ascii_val = ord($string[$i]);
if($ascii_val<65){
$sum = (int)$string[$i] - $salt;
if($sum < 0){
$sum = 10 + $sum;
}
}else{
$sum = $ascii_val - $salt;
if($sum<65){
$sum=92-$salt;
}
$sum = chr($sum);
}
array_push($hash,$sum);
}
return implode($hash);
}
// echo encrypt("3BDA79",$_SERVER['REQUEST_TIME']);
// echo "\n".$_SERVER['REQUEST_TIME'];