-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiki64.php
77 lines (62 loc) · 1.94 KB
/
iki64.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
<?php
// https://www.programmingalgorithms.com/algorithm/caesar-cipher?lang=PHP
function ___iki64_Cipher($ch, $key)
{
if (!ctype_alpha($ch))
return $ch;
$offset = ord(ctype_upper($ch) ? 'A' : 'a');
return chr(fmod(((ord($ch) + $key) - $offset), 26) + $offset);
}
function ___iki64_Encipher($input, $key)
{
$output = "";
$inputArr = str_split($input);
foreach ($inputArr as $ch)
$output .= ___iki64_Cipher($ch, $key);
return $output;
}
function ___iki64_Decipher($input, $key)
{
return ___iki64_Encipher($input, 26 - $key);
}
// iki64
function ___iki64_abc($data){
$md5 = md5("$data" . 'iki64');
$az = implode(range('a', 'z'));
$base64 = strtolower(base64_encode($md5)) . "$az";
$final = preg_replace('([0-9|\=])', '', "$base64");
$arr = array_unique(str_split($final));
return implode($arr);
};
function ___iki64_ABCD($data){
$md5 = md5("$data" . '_iki64');
$az = implode(range('A', 'Z'));
$base64 = strtoupper(base64_encode($md5)) . "$az";
$final = preg_replace('([0-9|\=])', '', "$base64");
$arr = array_unique(str_split($final));
return implode($arr);
};
function iki64_encode($data, $key){
$keyLen = strlen($key);
$az = implode(range('a', 'z'));
$AZ = implode(range('A', 'Z'));
$rand = ___iki64_abc($key);
$rand2 = ___iki64_ABCD($key);
$one = base64_encode($data);
$two = ___iki64_Encipher($one, $keyLen);
$three = strtr($two, $az, $rand);
$four = strtr($three, $AZ, $rand2);
return $four;
};
function iki64_decode($data, $key){
$keyLen = strlen($key);
$az = implode(range('a', 'z'));
$AZ = implode(range('A', 'Z'));
$rand = ___iki64_abc($key);
$rand2 = ___iki64_ABCD($key);
$four = strtr($data, $rand2, $AZ);
$three = strtr($four, $rand, $az);
$two = ___iki64_Decipher($three, $keyLen);
$one = base64_decode($two);
return $one;
};