2012.06.26 22:12

//정은이(Scar) 가 쓴 인코딩 디코딩 페이지 php 소스.



<?php 

//error_reporting(E_ALL); 
//ini_set('display_errors','1'); 

if ($_POST['value']){ 
    
$value=$_POST['value']; 
    
$select=$_POST['select']; 

else{ 
    
$value=''
    
$select=''


switch (
$select){ 
    case 
'URL encode'
        
$result=urlencode($value); 
        break; 
    case 
'BASE64 encode'
        
$result=base64_encode($value); 
        break; 
    case 
'URL decode'
        
$result=urldecode($value); 
        break; 
    case 
'BASE64 decode'
        
$result=base64_decode($value); 
        break; 
    case 
'MD5 hash'
        
$result=md5($value); 
        break; 
    case 
'SHA1 hash'
        
$result=sha1($value); 
        break; 
    default: 
        
$array=1
        
$size=1
        
$div[0]=$value
        if (
strstr($value,' ')){ 
            
$div=explode(' ',$value); 
            
$size=count($div); 
        } 
        switch (
$select){ 
            case 
'Hex to Dec'
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=' '.hexdec($div[$i]); 
                } 
                break; 
            case 
'Hex to Ascii'
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=chr(hexdec($div[$i])); 
                } 
                break; 
            case 
'Dec to Hex'
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=' '.dechex($div[$i]); 
//                    if($result[$i]==7fffffff) 
                

                
$result[0]=dechex($div[0]); 
                break; 
            case 
'Dec to Ascii'
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=chr($div[$i]); 
                } 
                break; 
            case 
'Ascii to Hex'
                
$size=strlen($value); 
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=' '.dechex(ord($value[$i])); 
                } 
                break; 
            case 
'Ascii to Dec'
                
$size=strlen($value); 
                for (
$i=0;$i<$size;$i++){ 
                    
$result[$i]=' '.ord($value[$i]); 
                } 
                break; 
            default: 
                
$result=''
        } 


?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
    <HEAD> 
        <TITLE> encode/decode </TITLE> 
        <link type='text/css' rel='stylesheet' href='../style.css'> 
    </HEAD> 
    <BODY> 
        <form action='index.php' method='POST'> 
            <div class='crypto_input'> 
                <textarea class='crypto_input' name='value'><? 
                
if ($array==1){ 
                    
$result[0]=trim($result[0]); 
                    for (
$i=0;$i<count($result);$i++){ 
                        echo (
$result[$i]); 
                    } 
                } 
                else{ 
                    echo (
$result); 
                } 
                
?></textarea> 
                dec, hex는 공백 기호로 분리됩니다. 
            </div> 
            <br><br> 
            <div class='crypto_menu'> 
                <div class='crypto_content_box encode'> 
                    <input class='button' type='submit' name='select' value='URL encode'><br> 
                    <input class='button' type='submit' name='select' value='BASE64 encode'><br> 
                </div> 
                <div class='crypto_content_box decode'> 
                    <input class='button' type='submit' name='select' value='URL decode'><br> 
                    <input class='button' type='submit' name='select' value='BASE64 decode'><br> 
                </div> 
                <div class='crypto_content_box hash'> 
                    <input class='button' type='submit' name='select' value='MD5 hash'><br> 
                    <input class='button' type='submit' name='select' value='SHA1 hash'> 
                </div> 
                <div class='crypto_content_box hex'> 
                    <input class='button' type='submit' name='select' value='Hex to Dec'><br> 
                    <input class='button' type='submit' name='select' value='Hex to Ascii'> 
                </div> 
                <div class='crypto_content_box dec'> 
                    <input class='button' type='submit' name='select' value='Dec to Hex'><br> 
                    <input class='button' type='submit' name='select' value='Dec to Ascii'> 
                </div> 
                <div class='crypto_content_box ascii'> 
                    <input class='button' type='submit' name='select' value='Ascii to Hex'><br> 
                    <input class='button' type='submit' name='select' value='Ascii to Dec'> 
                </div> 
            </div> 
        </form> 
    </BODY> 
</HTML> 

Posted by k1rha