sm-encode-lib
Code (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class SM_EncodeLib
{
function SM_Encode( $string )
{
$a = array( );
$r = array( );
$l = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' );
$t = array( );
$x = array( );
for( $i = 0; $i < strlen( $string ); $i++ )
if( $i & 1 )
$a[] = $string[ $i ];
for( $j = 0; $j < strlen( $string ); $j++ )
if( ~$j & 1 )
$a[] = $string[ $j ];
for( $k = 0; $k < count( $a ); $k++ )
$r[] = ord( $a[ $k ] );
$s = implode( '', $r );
for( $m = 0; $m < strlen( $s ); $m++ )
$t[ $m ] = $l[ $s[ $m ] ];
$b = strrev( strlen( $string ) );
$t = implode( '', $t ) . '-' . $b;
return $t;
}
function SM_Decode( $string )
{
$a = strpos( $string, '-' );
$s = substr( $string, 0, $a );
$b = array( );
$c = array( );
$d = array( );
$l = array( 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7, 'i' =>8, 'j' => 9 );
for( $i = 0; $i < strlen( $s ); $i++ )
$b[ $i ] = $l[ $s[ $i ] ];
$b = implode( '', $b );
for( $m = 0; $m < strlen( $b ); $m++ )
if( substr( $b, $m, 3 ) > 127 )
{
$c[] = chr( substr( $b, $m, 2 ) );
$m++;
}
else
{
$c[] = chr( substr( $b, $m, 3 ) );
$m += 2;
}
$z = implode( '', $c );
$x = floor( strrev( substr( $string, $a + 1 ) ) ) / 2;
$on = substr( $z, 0, $x );
$ev = substr( $z, $x );
for( $g = 0; $g < ( $x + $x + 1 ); $g++ )
{
if( ~$g & 1 )
{
if( !$w )
$w = 0;
$d[ $g ] = $ev[ $w ];
$w++;
}
if( $g & 1 )
{
if( !$v )
$v = 0;
$d[ $g ] = $on[ $v ];
$v++;
}
}
$z = implode( '', $d );
return $z;
}
}
?>
class SM_EncodeLib
{
function SM_Encode( $string )
{
$a = array( );
$r = array( );
$l = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' );
$t = array( );
$x = array( );
for( $i = 0; $i < strlen( $string ); $i++ )
if( $i & 1 )
$a[] = $string[ $i ];
for( $j = 0; $j < strlen( $string ); $j++ )
if( ~$j & 1 )
$a[] = $string[ $j ];
for( $k = 0; $k < count( $a ); $k++ )
$r[] = ord( $a[ $k ] );
$s = implode( '', $r );
for( $m = 0; $m < strlen( $s ); $m++ )
$t[ $m ] = $l[ $s[ $m ] ];
$b = strrev( strlen( $string ) );
$t = implode( '', $t ) . '-' . $b;
return $t;
}
function SM_Decode( $string )
{
$a = strpos( $string, '-' );
$s = substr( $string, 0, $a );
$b = array( );
$c = array( );
$d = array( );
$l = array( 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7, 'i' =>8, 'j' => 9 );
for( $i = 0; $i < strlen( $s ); $i++ )
$b[ $i ] = $l[ $s[ $i ] ];
$b = implode( '', $b );
for( $m = 0; $m < strlen( $b ); $m++ )
if( substr( $b, $m, 3 ) > 127 )
{
$c[] = chr( substr( $b, $m, 2 ) );
$m++;
}
else
{
$c[] = chr( substr( $b, $m, 3 ) );
$m += 2;
}
$z = implode( '', $c );
$x = floor( strrev( substr( $string, $a + 1 ) ) ) / 2;
$on = substr( $z, 0, $x );
$ev = substr( $z, $x );
for( $g = 0; $g < ( $x + $x + 1 ); $g++ )
{
if( ~$g & 1 )
{
if( !$w )
$w = 0;
$d[ $g ] = $ev[ $w ];
$w++;
}
if( $g & 1 )
{
if( !$v )
$v = 0;
$d[ $g ] = $on[ $v ];
$v++;
}
}
$z = implode( '', $d );
return $z;
}
}
?>