-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.php
More file actions
79 lines (64 loc) · 1.8 KB
/
text.php
File metadata and controls
79 lines (64 loc) · 1.8 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$text = "www.thebugshop.net";
#----------------------------
$hex = bin2hex($text);
//The hex MUST be 20 bytes!!!
//echo strlen($hex);
if (strlen($hex) >= 40) {
echo "You tried to do something more then 20 Bytes!!!!\n";
exit;
}
while (strlen($hex) < 40) {
//add some null
$hex = $hex . "0";
}
$hex = "80".$hex;
$hexbyte = hexStringToByteString($hex);
$hash1 = hash('sha256',$hexbyte);
$hash1 = hexStringToByteString($hash1);
//do our crc
$hash2 = hash('sha256',$hash1);
//need to grab the first 4 bytes of the hex
$checksum = substr($hash2,0,8);
//take our hex plus 0x80 and add our checksum
$hex = $hex . $checksum;
//base58 this
echo encodeBase58($hex) ."\n";
function encodeBase58($hex) {
$orighex=$hex;
$chars='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$hex=decodeHex($hex);
$return='';
while (bccomp($hex,0)==1) {
$dv=(string)bcdiv($hex,'58',0);
$rem=(integer)bcmod($hex,'58');
$hex=$dv;
$return=$return.$chars[$rem];
}
$return=strrev($return);
// Leading zeros
for($i=0;$i<strlen($orighex)&&substr($orighex,$i,2)=='00';$i+=2) {
$return='1'.$return;
}
return $return;
}
function decodeHex($hex) {
$hex=strtoupper($hex);
$chars='0123456789ABCDEF';
$return='0';
for($i=0;$i<strlen($hex);$i++) {
$current=(string)strpos($chars,$hex[$i]);
$return=(string)bcmul($return,'16',0);
$return=(string)bcadd($return,$current,0);
}
return $return;
}
function hexStringToByteString($hexString){
$len=strlen($hexString);
$byteString="";
for ($i=0;$i<$len;$i=$i+2){
$charnum=hexdec(substr($hexString,$i,2));
$byteString.=chr($charnum);
}
return $byteString;
}