Jump to content

Recommended Posts

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©ˆ…˜↑↓←→–—≈&#160;&#161;&#162;&#163;&#164;&#165;&#166;&#167;&#168;&#169;&#170;&#171;&#172;&#173;&#174;&#175;°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ   €™';
    $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

Link to comment
https://forums.phpfreaks.com/topic/208753-my-functions-are-working/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.