This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
/
Crypto.php
71 lines (60 loc) · 1.75 KB
/
Crypto.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
<?php
/*****Encrypting functions*******/
function ascii2hex($ascii) {
$hex = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte;
}
return $hex;
}
function encrypt_text($cleartext) {
$newString = $cleartext;
//Break down into html characters twice
$newString = str_replace("","",htmlentities($newString));
$newString = strrev($newString);
$newString = str_replace("","",htmlentities($newString));
$newString = strrev($newString);
//encode 4 times with base64, reverse, and converted to hex
for($i=0;$i<3;$i++) {
$newString = base64_encode($newString);
$newString = strrev($newString);
$newString = ascii2hex($newString);
}
//and encode with base 64 (reversed) one more time
$newString = base64_encode($newString);
$newString = strrev($newString);
//send it back
return $newString;
}
/*******Decrypting functions*******/
function hex2ascii($hex){
$ascii='';
$hex=str_replace(" ", "", $hex);
for($i=0; $i<strlen($hex); $i=$i+2) {
$ascii.=chr(hexdec(substr($hex, $i, 2)));
}
return($ascii);
}
function decrypt_text($cleartext) {
$newString = $cleartext;
//Do EVERYTHING in REVERSE
//Reverse back to normal and decode base64
$newString = strrev($newString);
$newString = base64_decode($newString);
//Convert back to hex, reverse, and decode base64
for($i=0;$i<3;$i++) {
$newString = hex2ascii($newString);
$newString = strrev($newString);
$newString = base64_decode($newString);
}
//reverse, decode html entities
$newString = strrev($newString);
$newString = html_entity_decode($newString);
$newString = strrev($newString);
$newString = html_entity_decode($newString);
//send it back
return $newString;
}
?>