Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head>
- <title>Convertidor</title>
- </head>
- <body>
- <?php
- //error_reporting(0);
- /* convert a string of hex values to an ascii string */
- function hex2str($hex) {
- $str='';
- for($i=0;$i<strlen($hex);$i+2)
- $str .= chr(hexdec(substr($hex,$i,2)));
- return $str;
- }
- function ascii2hex($ascii) {
- $hex = '';
- for ($i = 0; $i < strlen($ascii); $i++) {
- $byte = dechex(ord($ascii{$i}));
- $byte = str_repeat('0', 2 - strlen($byte)).$byte;
- $hex.=$byte;
- }
- return $hex;
- }
- $cifrar = htmlentities($_POST['cifrar'],ENT_QUOTES);
- $datos = htmlentities($_POST['datos'],ENT_QUOTES);
- $send = htmlentities($_POST['enviar'],ENT_QUOTES);
- $semilla = htmlentities($_POST['semilla'],ENT_QUOTES);
- if(!empty($cifrar) && !empty($datos)){
- if( $cifrar==1 )
- echo 'Resultado: '.base64_encode($datos);
- else if( $cifrar==2 )
- echo 'Resultado: '.base64_decode($datos);
- else if( $cifrar==3 )
- echo 'Resultado: '.ascii2hex($datos);
- else if( $cifrar==4 )
- echo 'Resultado: '.hex2str($datos);
- else if( $cifrar==5 )
- echo 'Resultado: '.urlencode($datos);
- else if( $cifrar==6 )
- echo 'Resultado: '.urldecode($datos);
- else
- echo 'No seleccionaste ninguno';
- }else{
- echo isset($send) ? '<script>alert("Campos vacios!")</script>' : NULL;
- ?>
- <script>
- function comprobaroption(){
- var opcion= document.frm.cifrar.options.value;
- if (opcion == 7) document.frm.semilla.disabled=false;
- }
- </script>
- <form name="frm" action="" method="POST">
- <textarea name="datos" rows="4" cols="50">Cifrar</textarea> <br>
- <select name="cifrar" size="0" onchange="comprobaroption()">
- <option value="1" selected>Ascci a Base64</option>
- <option value="2">Base64 a Ascci</option>
- <option value="3">Ascii a Hex</option>
- <option value="4">Hex a Ascii</option>
- <option value="5">Urlencode</option>
- <option value="6">Urldecode</option>
- <option value="7">Cifrar Caesar</option>
- </select><br>
- <input type="text" name="semilla" size="3" disabled="true">
- <input type="submit" name="enviar" value="Enviar datos!" />
- </form>
- <?
- }
- ?>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement