Jump to content

Encryption System Problem


Cagri

Recommended Posts

Hi,

I wrote an simple encryption system. There is a simple mathematical process multiplication and division. But it's not workin correctly. What's wrong i can not understand. Please help me. I just want to fix this problem please don't offer me alternative methods for encryption.

 

Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Encryption System</title><body>

 

<form action ="<?php $_SERVER['PHP_SELF']; ?>"method ="POST"><h1 align="center">Encryption System</h1>

<p align="center"><input name="radio1" type="radio" value ="encode" checked="checked">Encode    <input name="radio1" type="radio" value = "decode">Decode</p>

<div align="center">

  <textarea name="encryption" rows=8 cols=40>

<?php

$selected_radio = $_POST[radio1];

$text = $_POST['encryption']; 

function encrypt($text) {

Global $crypto;

    ini_set ( 'precision', 131087 );

    $search = range ( chr ( 1 ), chr ( 255 ) );

    foreach ( range ( 1, 255 ) as $num )

        $replace [] = str_pad($num,3,0,STR_PAD_LEFT);

   

    $crypto = strtr ( $text, array_combine ( $search, $replace ) ) ;

    $key = '67285789764983209584182738495874734473673467368232293248932298313131081291108578560185780

348549838461465813437569857428502758027';

    $crypto = ($crypto * $key);

    //return  base64_encode($crypto);

    return floatval($crypto);

}

 

function decrypt($text) {

Global $crypto;

    ini_set ( 'precision', 131087 );

    $key = '67285789764983209584182738495874734473673467368232293248932298313131081291108578560185780

348549838461465813437569857428502758027';

    $text = ($text / $key);

    $search = range ( chr ( 1 ), chr ( 255 ) );

    foreach ( range ( 1, 255 ) as $num )

        $replace [] = str_pad($num,3,0,STR_PAD_LEFT);

   

    //$string = base64_decode($string);

    $crypto = strtr ( $text, array_combine ( $replace, $search ) ) ;

        return  ($crypto);

}

 

encrypt($text);

if  ($selected_radio == 'encode') { echo $crypto;}

 

decrypt($text);

if ($selected_radio == 'decode') { echo $crypto;

}

?></textarea>

<p><input type="submit" name ="send" value ="Send"/><?php exit; ?></form>

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/166620-encryption-system-problem/
Share on other sites

$key = '67285789764983209584182738495874734473673467368232293248932298313131081291108578560185780
348549838461465813437569857428502758027';
$crypto = ($crypto * $key);

 

This may be your problem if you multiply $key it is transformed to an integer (not entirely, explained later). A computer uses the 2-complement system and when it exceeds 2^32 (4 billion, unsigned integer) It continues in the negative part (-2^16). So when php parses $key it will use it's biggest possible type it has and assign $key that type and everything he can't fit into it is cut off. Use PHP_INT_MAX instead.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.