kle_3187 Posted November 5, 2008 Share Posted November 5, 2008 Hi all, This is the first time ive ever done PHP and am really finding it tough! Basically for my uni cw I have to encrypt a string on the client side and send it to the server to be decrypted. In order to do this I made an array and then icremented each ASCII value by 5. Then I imploded this to a string in order to send it to the server but when I try to decrypt its not reading in the encrypted string value. eg. K encrypted is 80 server side decryption is 70 when it should be 75! I would be so greatful of any help as im desperately trying to pass my programming module. Many Thanks Kylie Link to comment https://forums.phpfreaks.com/topic/131521-php-encryption-decryption-problems/ Share on other sites More sharing options...
flyhoney Posted November 5, 2008 Share Posted November 5, 2008 Can you post the code you have so far? Link to comment https://forums.phpfreaks.com/topic/131521-php-encryption-decryption-problems/#findComment-683046 Share on other sites More sharing options...
Yesideez Posted November 5, 2008 Share Posted November 5, 2008 Welcome! I see it's your first post - a good idea is to post your code (surround it with and tags!!!) so others can see what you have so far and maybe see where the problem lies. Link to comment https://forums.phpfreaks.com/topic/131521-php-encryption-decryption-problems/#findComment-683050 Share on other sites More sharing options...
kle_3187 Posted November 5, 2008 Author Share Posted November 5, 2008 Yeh sure, i think its something silly im doing wrong but ive looked at it so much now I can't see the problem. Thank you Client <? $host = "localhost"; $port = 10024; $name = "Kylie Evans"; $arr = array ('K','y','l','i','e','','E','v','a','n','s'); $string = implode("",$arr); echo $arr; print_r($arr); //echo $arr[0]; //echo $arr[1]; //echo $arr[2]; //echo $arr[3]; //echo $arr[4]; //echo $arr[5]; //echo $arr[6]; //echo $arr[7]; //echo $arr[8]; //echo $arr[9]; //echo $arr[10]; //echo $arr[11]; $i=0; foreach ($arr as $letter) { $strChar = ord($arr[$i]) +5; echo "Letter: " . $letter . "<br />"; echo "Value: " . $value. "<br />"; $i++; $arr[$i] = $a; } // For Loop to convert each char into ascii then increase number for ($i = 0; $i < strlen($arr); $i++) { $strChar = ord($arr[$i]); + $strCharNumber; $strChar = bin2hex(chr($strChar)); // $strcode = $strcode & $strChar; } echo $strChar; // create socket $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $ret = socket_connect($socket, $host, $port); socket_write($socket, $string); // close sockets socket_close($socket); ?> Server <? // set some variables $host = "localhost"; $port = 10024; //$arr = Kylie Evans; //$arr = array ('K','y','l','i','e','','E','v','a','n','s'); $string = 'K,y,l,i,e,E,v,a,n,s'; $a = explode(',', $string); $info = print_r($a, true); //echo "<pre>$info</pre>"; echo $arr; $i=0; //foreach ($arr as $letter) { $value = ord($arr[$i]) -5 ; echo "Letter: " . $letter . "<br />"; echo "Value: " . $value. "<br />"; $i++; } echo $strChar; //For Loop to convert each char into Bin then decrease number for ($i = 0; $i < strlen($arr); $i++) { $strChar = ord($arr[$i]); + $strCharNumber; $strChar = bin2hex(chr($strChar)); $strcode = $strcode & $strChar; } // don't timeout! set_time_limit(0); // create socket $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); // clean up input string $input = trim($input); echo $input; // close sockets socket_close($spawn); socket_close($socket); ?> Link to comment https://forums.phpfreaks.com/topic/131521-php-encryption-decryption-problems/#findComment-683054 Share on other sites More sharing options...
kle_3187 Posted November 5, 2008 Author Share Posted November 5, 2008 Hi Yesideez Sorry I didnt see your post regarding tags I will make sure I use them in the future! I think i see where my problem is in a sense that its not displaying the incremented ASCII value so K would become F when it is encrypted and therefore the server is just reading it as K -5. Link to comment https://forums.phpfreaks.com/topic/131521-php-encryption-decryption-problems/#findComment-683084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.