Advertisement
diabliyo

artur

Jan 1st, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <head>
  2.     <title>Convertidor</title>
  3.     </head>
  4.     <body>
  5.     <?php
  6.     //error_reporting(0);
  7.     /* convert a string of hex values to an ascii string */
  8.   function hex2str($hex) {
  9.         $str='';
  10.     for($i=0;$i<strlen($hex);$i+2)
  11.     $str .= chr(hexdec(substr($hex,$i,2)));
  12.  
  13.     return $str;
  14.   }
  15.  
  16.   function ascii2hex($ascii) {
  17.     $hex = '';
  18.     for ($i = 0; $i < strlen($ascii); $i++) {
  19.     $byte = dechex(ord($ascii{$i}));
  20.     $byte = str_repeat('0', 2 - strlen($byte)).$byte;
  21.     $hex.=$byte;
  22. }
  23. return $hex;
  24. }
  25.     $cifrar = htmlentities($_POST['cifrar'],ENT_QUOTES);
  26.     $datos = htmlentities($_POST['datos'],ENT_QUOTES);
  27.     $send = htmlentities($_POST['enviar'],ENT_QUOTES);
  28.     $semilla = htmlentities($_POST['semilla'],ENT_QUOTES);
  29.     if(!empty($cifrar) && !empty($datos)){
  30.      
  31.             if( $cifrar==1 )
  32.                                     echo 'Resultado: '.base64_encode($datos);
  33.             else if( $cifrar==2 )
  34.                                     echo 'Resultado: '.base64_decode($datos);
  35.             else if( $cifrar==3 )
  36.                                 echo 'Resultado: '.ascii2hex($datos);
  37.             else if( $cifrar==4 )
  38.                                 echo 'Resultado: '.hex2str($datos);
  39.             else if( $cifrar==5 )
  40.                             echo 'Resultado: '.urlencode($datos);
  41.             else if( $cifrar==6 )
  42.                             echo 'Resultado: '.urldecode($datos);
  43.             else
  44.                                     echo 'No seleccionaste ninguno';
  45.     }else{
  46.             echo isset($send) ?  '<script>alert("Campos vacios!")</script>' : NULL;
  47.             ?>
  48.             <script>
  49.             function comprobaroption(){
  50.                 var opcion= document.frm.cifrar.options.value;
  51.                 if (opcion == 7) document.frm.semilla.disabled=false;
  52.                 }
  53.             </script>
  54.             <form name="frm" action="" method="POST">
  55.      
  56.                     <textarea name="datos" rows="4" cols="50">Cifrar</textarea> <br>
  57.      
  58.                     <select name="cifrar" size="0" onchange="comprobaroption()">
  59.                             <option value="1" selected>Ascci a Base64</option>
  60.                             <option value="2">Base64 a Ascci</option>
  61.                             <option value="3">Ascii a Hex</option>
  62.                             <option value="4">Hex a Ascii</option>
  63.                             <option value="5">Urlencode</option>
  64.                             <option value="6">Urldecode</option>
  65.                             <option value="7">Cifrar Caesar</option>
  66.                     </select><br>
  67.                     <input type="text" name="semilla" size="3" disabled="true">
  68.                     <input type="submit" name="enviar" value="Enviar datos!"  />
  69.             </form>
  70.             <?
  71.            
  72.     }
  73.      
  74.     ?>
  75. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement