255) {$ByteDirecciónIP= 255;}; // Paso 2. $ByteIdCliente= ord(trim($IdCliente)." "); // Paso 3. $ByteNroSesión= $NroSesión - floor($NroSesión/256)*256; // Paso 4: $RandA1= rand(0,255); // Paso 5: $RandA2= rand(1,3); // Pasos 6 y 7: $ArgumentoNum= ""; $Long= strlen($Argumento); for ($i=1; $i<=$Long; $i++) { $Byte= ord(substr($Argumento,($i-1),1)); $Byte= $Byte*$RandA2 + $RandA1 + $ByteDirecciónIP + $ByteIdCliente + $ByteNroSesión + ($i-1)*$RandA2; $ArgumentoNum= $ArgumentoNum.substr("0000".strval($Byte),-4);}; // Paso 8: $Encriptado= ""; for ($i=1; $i<=$Long; $i++) { $Cifra= strval(substr($ArgumentoNum,($Long-$i)*4,4)); if ($i/2==floor($i/2)) {$Encriptado= $Encriptado. substr($Cifra,0,1). strval(rand(0,9). substr($Cifra,1,1). substr($Cifra,2,1). substr($Cifra,3,1));} else {$Encriptado= $Encriptado. substr($Cifra,3,1). substr($Cifra,2,1). substr($Cifra,1,1). strval(rand(0,9). substr($Cifra,0,1));}; if ($i==1) {$Encriptado= $Encriptado. substr("000".strval($RandA1),-3). strval($RandA2);};}; $Encriptado= $Encriptado. strval(rand(0,9)). strval(rand(0,9)). strval(rand(0,9)). strval(rand(0,9)); // Calcular dígitos de verificación. $Long= strlen($Encriptado); if ($Long>4) { $Factores1= "78299843724466"; $Suma1= 0; $Factores2= "19667441233855"; $Suma2= 0; for ($i=1; $i<=$Long; $i++) {$Suma1= $Suma1+intval(substr($Encriptado,($i-1),1))* intval(substr($Factores1,($i-floor(($i-1)/strlen($Factores1))*strlen($Factores1)-1),1)); $Suma2= $Suma2+intval(substr($Encriptado,($i-1),1))* intval(substr($Factores2,($i-floor(($i-1)/strlen($Factores2))*strlen($Factores2)-1),1));}; $Dígito1= $Suma1-floor($Suma1/10)*10; $Dígito2= $Suma2-floor($Suma2/10)*10; $Dígito1= 9 - $Dígito1; $Dígito2= $Dígito2 + 3; if ($Dígito2>9) {$Dígito2= $Dígito2 - 10;}; $Encriptado= substr($Encriptado,0,5). strval($Dígito1).strval($Dígito2). substr($Encriptado,5);}; return $Encriptado; } // ----------------------------------------------------------------------------- // DesencriptarParametroWeb: // Desencripta @Argumento de acuerdo al algoritmo descripto en EncriptarParametroWeb. // // AFL @ 08/09/14. function DesencriptarParametroWeb ($Argumento, $DirecciónIP, $IdCliente, $NroSesión) { // Inicializar proceso. $Pos= strrpos($DirecciónIP,"."); if (!($Pos===false)) {$ByteDirecciónIP= intval(substr($DirecciónIP,$Pos+1));} else {$ByteDirecciónIP= 0;}; if ($ByteDirecciónIP<0) {$ByteDirecciónIP= 0;}; if ($ByteDirecciónIP>255) {$ByteDirecciónIP= 255;}; $ByteIdCliente= ord(trim($IdCliente)." "); $ByteNroSesión= $NroSesión - floor($NroSesión/256)*256; $Desencriptado= ""; $Ok= "S"; // Validar longitud del Argumento. IF ($Ok=="S") { $Long= strlen($Argumento); if ($Long<15 or $Long/5<>floor($Long/5)) {$Ok= "N";};}; // Validar que solo tenga dígitos. if ($Ok=="S") { for ($i=1; $i<=$Long; $i++) { $Carácter= strval(substr($Argumento,($i-1),1)); if ($Carácter<"0" or $Carácter>"9") {$Ok= "N";};};}; // Validar dígitos de verificación. if ($Ok=="S") { $Argumento2= substr($Argumento,0,5).substr($Argumento,7); $Long= strlen($Argumento2); $Factores1= "78299843724466"; $Suma1= 0; $Factores2= "19667441233855"; $Suma2= 0; for ($i=1; $i<=$Long; $i++) {$Suma1= $Suma1+intval(substr($Argumento2,($i-1),1))* intval(substr($Factores1,($i-floor(($i-1)/strlen($Factores1))*strlen($Factores1)-1),1)); $Suma2= $Suma2+intval(substr($Argumento2,($i-1),1))* intval(substr($Factores2,($i-floor(($i-1)/strlen($Factores2))*strlen($Factores2)-1),1));}; $Dígito1= $Suma1-floor($Suma1/10)*10; $Dígito2= $Suma2-floor($Suma2/10)*10; $Dígito1= 9 - $Dígito1; $Dígito2= $Dígito2 + 3; if ($Dígito2>9) {$Dígito2= $Dígito2 - 10;}; if (intval(substr($Argumento,5,2))<>($Dígito1*10+$Dígito2)) {$Ok= "N";};}; // Proceso de desencriptado. IF ($Ok=="S") { $Long= (strlen($Argumento)-10)/5; $RandA1= intval(substr($Argumento,7,3)); $RandA2= intval(substr($Argumento,10,1)); $Argumento3= substr($Argumento,0,5); if ($Long>=2) {$Argumento3= $Argumento3.substr($Argumento,11);}; for ($i=$Long; $i>=1; $i--) { $Cifra1= strval(substr($Argumento3,($i-1)*5,5)); if ($i/2==floor($i/2)) {$Cifra2= substr($Cifra1,0,1). substr($Cifra1,2,1). substr($Cifra1,3,1). substr($Cifra1,4,1);} else {$Cifra2= substr($Cifra1,4,1). substr($Cifra1,2,1). substr($Cifra1,1,1). substr($Cifra1,0,1);}; $Cifra3= intval($Cifra2); $Cifra4= $Cifra3 - $RandA1 - $ByteDirecciónIP - $ByteIdCliente - $ByteNroSesión - ($Long-$i)*$RandA2; $Cifra4= $Cifra4/$RandA2; $Desencriptado= $Desencriptado.chr($Cifra4);};}; return $Desencriptado; } // Fin de la Libreriita... // ----------------------------------------------------------------------------- ?> THEMA - Red Médica