Показать сообщение отдельно

  #8  
Старый 09.10.2009, 17:09
L I G A
Постоянный
Регистрация: 27.07.2008
Сообщений: 614
С нами: 9362947

Репутация: 1196


По умолчанию

2-е простые функции для за/расшифровки паролей.
Писал для своего блога т.к. хранить пасы в чистом виде - небезопасно.
Алгоритм действий :
1. base64_encode;
2. убираем "=" ,чтоб не спалили;
3. добавляем base64_encode первых 3-х символов;
4. Переворачиваем.
функии:
PHP код:
function code($pass)
{
$hash=base64_encode($pass);
$hash=str_replace('=','',$hash);
$center=base64_encode(substr($hash,0,3));
$center=str_replace('=','',$center);
$count=strlen($hash);
$cn=round($count/2);
$first=substr($hash,0,$cn);
$second=substr($hash,$cn,$count);
$hash=$first.$center.$second;
$hash=strrev($hash);
return 
$hash;
}

function 
decode($pass)
{
$pass=strrev($pass);
$count=(strlen($pass))-4;
$cn=round($count/2);
$first=substr($pass,0,$cn);
$second=substr($pass,$cn+4,$count+4);
$pass=$first.$second;
$pass=$pass.'==';
$hash=base64_decode($pass);
return 
$hash;

релиз:
PHP код:
 <html>

<head>
  <title>приветы от liga</title>
<style>
body{
    background:#333;
    color:#888;
    font-family:Verdana, Arial;
    font-size:11px;
    padding:0px;
    margin:0px;
    }
 .form {
     background:#232323;
     color:#626262;
     border:1px solid #4e4e4e;
      padding:2px;
      color:#999;
      font-family:Verdana, Arial;
      font-size:11px;
      font-color:green;
      color:#727272;
      }
 h2{
     font-size:11px;
     padding:0px 0px;
     color:#777;
     font-size:18px;
     font-weight:200;
     text-align:center;
     }
</style>
</head>
<body bgcolor="black">
<center><h2>[Code-decodE]</h2></center>
&nbsp;1. base64_encode; <br/>
&nbsp;2. убирает "=" ,чтоб не спалили;<br/>
&nbsp;3. добавляет  base64_encode первых 3-х символов; <br/>
&nbsp;4. Переворачивае.</br>
<pre>
<?php

if($_POST['do'] and $_POST['text']){
$text=trim($_POST['text']);


}



function 
code($pass)
{
$hash=base64_encode($pass);
$hash=str_replace('=','',$hash);
$center=base64_encode(substr($hash,0,3));
$center=str_replace('=','',$center);
$count=strlen($hash);
$cn=round($count/2);
$first=substr($hash,0,$cn);
$second=substr($hash,$cn,$count);
$hash=$first.$center.$second;
$hash=strrev($hash);
return 
$hash;
}

function 
decode($pass)
{
$pass=strrev($pass);
$count=(strlen($pass))-4;
$cn=round($count/2);
$first=substr($pass,0,$cn);
$second=substr($pass,$cn+4,$count+4);
$pass=$first.$second;
$pass=$pass.'==';
$hash=base64_decode($pass);
return 
$hash;
}
if(
strlen($text)<=3){
    echo 
'<script>alert("strlen(',$text,')<=3")</script>';
    
$hash='пусто';
    }

 if(!
$hash)
{
    
$hash='пусто';
}

switch ( 
$_REQUEST['ctype']) {
   case 
0:
   
$hash=code($text);
 break;

 case 
1:
 
$hash=$text;
break;
  }
echo 
'&nbsp;зашифрованный пасс:   <font color="green">'$hash,'</font>';
echo 
'<br/>&nbsp;расшифрованный пасс:  <font color="green">',decode($hash),'</font>';
?>
<form name="" action="" method="post">

&nbsp;<input  name='ctype' type="radio" value="0" checked>[зашифровать]<input  name='ctype' type="radio" value="1" checked>[расшифровать]
&nbsp;<input class="form" name="text" type="text" value=""><input class="form" name="do" type="submit" style="height:17px;" value="do it">
</form>
</pre>
</body>
</html>

Последний раз редактировалось L I G A; 09.10.2009 в 20:03..
 
Ответить с цитированием