Jragon Posted July 24, 2010 Share Posted July 24, 2010 Hello, I've made a huge functions list that use functions in that list its sort of confusing my functions: <?php function strtoarr($option){ if($option == 'abc'){ $string = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,.'; }else{ $string = $option; } $array = array(str_split($string)); } function randstr($length) { $chars = '!"£\$%^&*()_+-=1234567890¬`¦QWERTYUIOP{}[]ASDFGHJKL:@~|ZXCVBNM<>?,.;\#\qwertyuioplkjhgfdsazxcvbnm©ˆ…–—˜¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ €™'; //$chars = '!"£\$%^&*()_+-=1234567890¬` ¦QWERTYUIOP{}[]ASDFGHJKL:@~|ZXCVBNM<>?,.;\'\# \ qwertyuioplkjhgfdsazxcvbnm©ˆ…˜↑↓←→–—≈ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ €™'; $str = substr( str_shuffle( $chars ), 0, $length ); return $str; } function cryptc($code, $string, $type){ if($type == 'decrypt'){ if(getmd5($code) != false){ $replace = strtoarr('decrypt'); $find = strtoarr(getmd5($code)); $result = strtr($string, $find, $replace); return $result; } }else{ include("connect.php"); $find = strtoarr('abc'); $replace = randstr(55); $md5 = md5($replace); $query = sprintf("INSERT INTO decipher (md5_code, decipher_code) VALUES('%s', '%s')", mysql_real_escape_string($md5), mysql_real_escape_string($replace)); mysql_query($query); $result = strtr($string, $find, $replace); return $result . '<br />' . $md5; } } function getmd5($code){ include("connect.php"); $query = sprintf("SELECT decipher_code FROM decipher WHERE md5_code = '%s'", mysql_real_escape_string($code)); $numrows = mysql_num_rows(mysql_query($query)); $result = mysql_query($query); if($numrows = 1){ while(mysql_fetch_assoc($result)){ return $row[1]; } }else{ return false; } } ?> What i want it to do is encrypt using a random code or decrypt using a code from the database and right now its not doing eather I know what the problem is: What is happening is that when strtoarr function functions it dosent return anything, what i want it to do is return somthing in array format. Any ideas on how i could this Thanks Jragon Quote Link to comment Share on other sites More sharing options...
trq Posted July 24, 2010 Share Posted July 24, 2010 function strtoarr($option){ if($option == 'abc'){ $string = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,.'; }else{ $string = $option; } return str_split($string); } Quote Link to comment Share on other sites More sharing options...
Jragon Posted July 24, 2010 Author Share Posted July 24, 2010 Still is not working Quote Link to comment Share on other sites More sharing options...
trq Posted July 24, 2010 Share Posted July 24, 2010 Still is not working Describe 'not working'. We are not mind readers. Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 24, 2010 Share Posted July 24, 2010 what do you want in this array? the code thorpe has posted will return an array, just you haven't defined what values this array should hold... on a second thought, if you're just trying to encrypt / decrypt the code with a custom key, you can use MySQL's AES_ENCRYPT / AES_DECRYPT function. http://dev.mysql.com/doc/refman/5.1/en/encryption-functions.html#function_aes-encrypt Quote Link to comment Share on other sites More sharing options...
Jragon Posted July 24, 2010 Author Share Posted July 24, 2010 This is the output i'm getting strings are coool 0c5099c965217e2e75722bc5f762ecdf ô@GSÁsÖ ðÀÔïÐQ¦¡b\rOˆJÎì…h.î]˜¿³£këóÂEc?UXªÕd+¬ÿ±5¶Tŧµ the thing that is not working is: the string replace thing in the cryptc function because the strtoarr is not working correctly The string 'strings are coool' should be a hole load of gobeldegoop also when it encrypts it dosent update the mysql database joel24: Hey joel What i want the function to output is eather 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,.' or the decipher code in an array so it can be used to do the string replace thing Thanks Jraagon Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 24, 2010 Share Posted July 24, 2010 could you not just use AES_ENCRYPT / AES_DECRYPT ? read my last post, i've just modified it. Quote Link to comment Share on other sites More sharing options...
Jragon Posted July 24, 2010 Author Share Posted July 24, 2010 I see that it would be usefull. but i'm want to do it my way so i was wondering if anyone knew how i could fix my errors Quote Link to comment 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.