Cagri Posted July 20, 2009 Share Posted July 20, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/166620-encryption-system-problem/ Share on other sites More sharing options...
ignace Posted July 20, 2009 Share Posted July 20, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/166620-encryption-system-problem/#findComment-878636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.