SHOW:
|
|
- or go back to the newest paste.
| 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 | - | for($i=0;$i<strlen($hex);$i+=2) |
| 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 | - | switch ($cifrar) {
|
| 30 | + | |
| 31 | - | case 1: |
| 31 | + | if( $cifrar==1 ) |
| 32 | echo 'Resultado: '.base64_encode($datos); | |
| 33 | - | break; |
| 33 | + | else if( $cifrar==2 ) |
| 34 | - | case 2: |
| 34 | + | |
| 35 | else if( $cifrar==3 ) | |
| 36 | - | break; |
| 36 | + | |
| 37 | - | case 3: |
| 37 | + | else if( $cifrar==4 ) |
| 38 | echo 'Resultado: '.hex2str($datos); | |
| 39 | - | break; |
| 39 | + | else if( $cifrar==5 ) |
| 40 | - | case 4: |
| 40 | + | |
| 41 | else if( $cifrar==6 ) | |
| 42 | - | break; |
| 42 | + | |
| 43 | - | case 5: |
| 43 | + | else |
| 44 | echo 'No seleccionaste ninguno'; | |
| 45 | - | break; |
| 45 | + | |
| 46 | - | case 6: |
| 46 | + | |
| 47 | ?> | |
| 48 | - | break; |
| 48 | + | |
| 49 | - | default: |
| 49 | + | |
| 50 | var opcion= document.frm.cifrar.options.value; | |
| 51 | - | break; |
| 51 | + | |
| 52 | - | } |
| 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 | - | |
| 60 | + | |
| 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> |