-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcrypt.php
60 lines (50 loc) · 1.25 KB
/
crypt.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
<?php
function encrypt($sData, $sKey){
$sResult = '';
for($i=0;$i<strlen($sData);$i++){
$sChar = substr($sData, $i, 1);
$sKeyChar = substr($sKey, ($i % strlen($sKey)) - 1, 1);
$sChar = chr(ord($sChar) + ord($sKeyChar));
$sResult .= $sChar;
}
return encode_base64($sResult);
}
function decrypt($sData, $sKey){
$sResult = '';
$sData = decode_base64($sData);
for($i=0;$i<strlen($sData);$i++){
$sChar = substr($sData, $i, 1);
$sKeyChar = substr($sKey, ($i % strlen($sKey)) - 1, 1);
$sChar = chr(ord($sChar) - ord($sKeyChar));
$sResult .= $sChar;
}
return $sResult;
}
function encode_base64($sData){
$sBase64 = base64_encode($sData);
return strtr($sBase64, '+/', '-_');
}
function decode_base64($sData){
$sBase64 = strtr($sData, '-_', '+/');
return base64_decode($sBase64);
}
// DOCUMENTATION
//To Decrypt a string
//
// decrypt(Encrypted_String, Password);
//
// Output: Decrypted String
//
// Example
//
// echo decrypt('qJzXqw==', 'mySuperSecretPassword');
// To Encrypt a string
//
// encrypt(String, Password);
//
// Output: Encrypted String
//
// Example
//
// echo encrypt('test','mySuperSecretPassword');
?>