- <?
- /*
- Cesar_Plus($chaine,$choix,$pos,$pass,$mode);
-
- Var:
- $chaine : chaine à (dé)crypter
- $choix : nombre de décalage de lettres
- $pos : sens de décallage :
- "-1" vers la gauche
- "1" vers la droite
- $pass : clé pour le décryptage
- $mode : mode de fonctionnement :
- "-1" cryptage
- "1" décryptage
-
- Limit :
- $chaine : limit à 60000 caractères
- $choix : limit à 200
- $pass : 8 caractères héxa
-
- Conseil :
- mélanger la chaine $test
- */
- function Cesar_Plus($chaine,$choix,$pos,$pass,$mode){
- global $chaine,$pass;
- $test="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ !#%&')+,-./:>=@]^_`{}~²|éà赤£¨";
- $uncode=0;
-
-
- //uncode pass
-
- if($mode==1){
- if(strlen($pass)-8==0){
- $k1=hexdec($pass[0]);
- if($k1>=2 and $k1<=14){
- $k2=$k1/2;
- if(($k1%2)!=0){$k2+=.5;}
- $nb=hexdec(substr($pass,1,4));
- $pos=hexdec($pass[5]);
- $choix=hexdec(substr($pass,6,2));
- if(($pos-$k1)==1 or ($pos-$k1+2)==1){
- $pos-=$k1;
- $choix=-255+$choix+$k1+$k2;
- $choix*=-1;
- $nb-=65355;
- $nb/=-$k2;
- $pos=-$pos;
- }
- else{$uncode=1;}
- }
- else{$uncode=1;}
- }
- else{$uncode=1;}
- }
-
-
- //cesar
-
- if($uncode==0 or $mode==-1){
- for($i=0;$i<strlen($chaine);$i++){
- if(strpos($test, $chaine[$i]) !== false){
- $j=strpos($test,substr($chaine,$i,1));
-
- if($pos=="-1"){
- $j -= $choix;
- while($j<0){$j +=strlen($test);}
- }
-
- else{
- $j += $choix;
- while($j+1>strlen($test)){$j -=strlen($test);}
- }
-
- $chaine[$i]=$test[$j];
- }
- }
- }
-
-
- //codage
-
- if($mode==-1){
- $nb=rand(0,strlen($chaine)-1);
- for($i=0;$i<$nb;$i++){
- $test=$chaine[$i];
- $chaine[$i]=$chaine[$i+1];
- $chaine[$i+1]=$test;
- }
- $chaine=strrev($chaine);
- }
-
-
- //uncodage
-
- if($mode==1){
- if($uncode==1){$nb=0;}
- $chaine=strrev($chaine);
- for($i=$nb;$i>0;$i--){
- $test=$chaine[$i];
- $chaine[$i]=$chaine[$i-1];
- $chaine[$i-1]=$test;
- }
- }
-
-
- //code pass
-
- if($mode==-1){
- $k1=rand(2,14);
- $k2=$k1/2;
- if(($k1%2)!=0){$k2+=.5;}
- $pos+=$k1;
- $choix-=255-$k1-$k2;
- $choix*=-1;
- $nb=65355-($nb*$k2);
- $pass=dechex($k1).dechex($nb).dechex($pos).dechex($choix);
- }
-
- }
-
- ?>
<?
/*
Cesar_Plus($chaine,$choix,$pos,$pass,$mode);
Var:
$chaine : chaine à (dé)crypter
$choix : nombre de décalage de lettres
$pos : sens de décallage :
"-1" vers la gauche
"1" vers la droite
$pass : clé pour le décryptage
$mode : mode de fonctionnement :
"-1" cryptage
"1" décryptage
Limit :
$chaine : limit à 60000 caractères
$choix : limit à 200
$pass : 8 caractères héxa
Conseil :
mélanger la chaine $test
*/
function Cesar_Plus($chaine,$choix,$pos,$pass,$mode){
global $chaine,$pass;
$test="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ !#%&')+,-./:>=@]^_`{}~²|éà赤£¨";
$uncode=0;
//uncode pass
if($mode==1){
if(strlen($pass)-8==0){
$k1=hexdec($pass[0]);
if($k1>=2 and $k1<=14){
$k2=$k1/2;
if(($k1%2)!=0){$k2+=.5;}
$nb=hexdec(substr($pass,1,4));
$pos=hexdec($pass[5]);
$choix=hexdec(substr($pass,6,2));
if(($pos-$k1)==1 or ($pos-$k1+2)==1){
$pos-=$k1;
$choix=-255+$choix+$k1+$k2;
$choix*=-1;
$nb-=65355;
$nb/=-$k2;
$pos=-$pos;
}
else{$uncode=1;}
}
else{$uncode=1;}
}
else{$uncode=1;}
}
//cesar
if($uncode==0 or $mode==-1){
for($i=0;$i<strlen($chaine);$i++){
if(strpos($test, $chaine[$i]) !== false){
$j=strpos($test,substr($chaine,$i,1));
if($pos=="-1"){
$j -= $choix;
while($j<0){$j +=strlen($test);}
}
else{
$j += $choix;
while($j+1>strlen($test)){$j -=strlen($test);}
}
$chaine[$i]=$test[$j];
}
}
}
//codage
if($mode==-1){
$nb=rand(0,strlen($chaine)-1);
for($i=0;$i<$nb;$i++){
$test=$chaine[$i];
$chaine[$i]=$chaine[$i+1];
$chaine[$i+1]=$test;
}
$chaine=strrev($chaine);
}
//uncodage
if($mode==1){
if($uncode==1){$nb=0;}
$chaine=strrev($chaine);
for($i=$nb;$i>0;$i--){
$test=$chaine[$i];
$chaine[$i]=$chaine[$i-1];
$chaine[$i-1]=$test;
}
}
//code pass
if($mode==-1){
$k1=rand(2,14);
$k2=$k1/2;
if(($k1%2)!=0){$k2+=.5;}
$pos+=$k1;
$choix-=255-$k1-$k2;
$choix*=-1;
$nb=65355-($nb*$k2);
$pass=dechex($k1).dechex($nb).dechex($pos).dechex($choix);
}
}
?>