Scripts

SM Encode Lib

Hoe gebruik ik de SM Encode Lib?

sm-encode-lib
<?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;
	}
}
?>

Reacties

0
Nog geen reacties.