Jhonjhon_123

DePoli Reto 177 Yashira - By Jhonjhon_123

Jun 16th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. function DePoli($texto)
  2. {
  3.     $texto = str_replace( " ", "", strtoupper( $texto ) );
  4.  
  5.     //creamos el diccionario de letras segun su posicion (grupo de 5)
  6.     $dic = array();
  7.     $letters = explode(",", "a,b,c,d,e,f,g,h,i,j,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
  8.     foreach ($letters as $value) {
  9.         $tmp = Poli($value.$value.$value.$value.$value);
  10.         $dic[$value] = array(
  11.             1 => substr( $tmp, 0, 1 ),
  12.             2 => substr( $tmp, 1, 1 ),
  13.             3 => substr( $tmp, 2, 1 ),
  14.             4 => substr( $tmp, 3, 1 ),
  15.             5 => substr( $tmp, 4, 1 )
  16.         );
  17.     }
  18.  
  19.     $ret = '';
  20.     for ( $o = 0; $o < strlen( $texto ) - 1; $o += 5 )
  21.     {
  22.         $grupo = substr( $texto, $o, 5 );
  23.  
  24.         for ($i=1; $i <= 5 ; $i++) {
  25.             // sacamos la letra del grupo
  26.             $letra = substr( $grupo, $i - 1, 1 );
  27.             // sacamos la letra original por su posision unica en el alfabeto de letras
  28.             foreach ($dic as $key => $value) {
  29.                 if ($letra == $dic[$key][$i])
  30.                 {
  31.                     $ret .= $key;
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.     }
  37.  
  38.     return $ret;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment