note 103471 added to function.crypt

From: Date: Fri, 15 Apr 2011 06:12:13 +0000
Subject: note 103471 added to function.crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-178857@lists.php.net to get a copy of this message
I would like to know if this would be a safe use of a script for simplistic ascii encryption/decryption. The output would look like garbled junk but it works due to the low shifting of the ord<->chr use, and without the key I can't see the possible way someone would be able to break the crypt. Obvious that the key would have to be a bit more complex than "mydogsnameisFrank", something such as "j&,2Oc8%" and all character based within the key. Anyway... function fn_Encrypt ($KEY = NULL, $STRING = NULL) { return fn_Crypt (TRUE, $KEY, $STRING); } function fn_Decrypt ($KEY = NULL, $STRING = NULL) { return fn_Crypt (FALSE, $KEY, $STRING); } function fn_Crypt ($POLARITY = TRUE, $KEY = NULL, $STRING = NULL) { if (($KEY != NULL) && ($STRING != NULL)) { if ((strlen($KEY) > 0) && (strlen($STRING) > 0)) { $OUTPUT = ""; $KEY_INDEX = 0; for ($STRING_INDEX = 0; $STRING_INDEX < strlen($STRING); $STRING_INDEX++) { if ($POLARITY) { $NUMERIC = ord($STRING[$STRING_INDEX]) + ord($KEY[$KEY_INDEX]); $POLARITY = !$POLARITY; } else { $NUMERIC = ord($STRING[$STRING_INDEX]) - ord($KEY[$KEY_INDEX]); $POLARITY = !$POLARITY; } $OUTPUT .= chr($NUMERIC); if (($KEY_INDEX + 1) > (strlen($KEY) - 1)) { $KEY_INDEX = 0; } else { $KEY_INDEX++; } } return $OUTPUT; } } return NULL; } Even with people knowing the following, the key being longer and hard to guess, rotating the key over time etc; seems this would do the job if not processing a ton of data throught the $STRING. ---- Server IP: 192.41.42.26 Probable Submitter: 98.240.203.187 ---- Manual Page -- http://www.php.net/manual/en/function.crypt.php Edit -- https://master.php.net/note/edit/103471 Del: integrated -- https://master.php.net/note/delete/103471/integrated Del: useless -- https://master.php.net/note/delete/103471/useless Del: bad code -- https://master.php.net/note/delete/103471/bad+code Del: spam -- https://master.php.net/note/delete/103471/spam Del: non-english -- https://master.php.net/note/delete/103471/non-english Del: in docs -- https://master.php.net/note/delete/103471/in+docs Del: other reasons-- https://master.php.net/note/delete/103471 Reject -- https://master.php.net/note/reject/103471 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178857) next »