Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    I have a number, x, and want to get a value from it, y.

    So, f(x) = y

    y must be random
    x must not be able to be derived from y (ie: the inverse of x can not be a function)

    I thought I found the solution with:

    PHP Code:
    srand($x);
    $y rand(); 
    but that changes whenever you move servers, I don't know why.

    I don't want to use mcrypt.

    Anyway, I really need to know how to do this. If anyone can get me the answer before 10:00 tonight (wouln't do me much good after that :'( ) I'll give them 20 turtle dollars!

    Thanks!

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Why before 10:00 PM? Is this homework?
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Maybe I'm just not getting it, but if a function gets one value and always returns another based on that seed, it's not very random IMO...
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    PHP Code:
    $y md5($x); 
    y is not random, but is unique for each x. MD5 hash is one way, it very hard (next to impossible) to get the original x from y.
    There and Back Again :Ogre:

  6. #5
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    y must be random
    x must not be able to be derived from y (ie: the inverse of x can not be a function)
    if you want ' y' to be random (meaning you can't get the same result from the same 'x' value if applied multiple times), then you can use the UNIX crypt() function in MySQL. The process is 'one-way' meaning you can't reverse it (deriving Y from X).

    In MySQL the command is;
    Code:
    SELECT ENCRYPT ('x value goes here')
    this will produce a new result every time. This is because the 'salt' is missing. In the original UNIX version, the 'salt' is normally two characters, but in MySQL the 'salt' can be longer. If it's not specified, the function will randomly select one, and the result will be different every time. If you want the same result every time, you just add your own 'salt'.
    Code:
    SELECT ENCRYPT ('x value goes here', 'salt code goes here')
    #example
    SELECT ENCRYPT('secretword', 'kjlksahjv')
    S. Rosland

  7. #6
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    Nsr81, despite the fact that your answer in no way gives me an integer value for y, it will work fine for what I need it for. You have helped me twice now on my project and I am more than happy to award you with the turtle dollars for this thread. Many thanks, you have saved me a good bit of time.

    Also, the project is not for homework. I basically have a script that makes copy and paste code. The script uses a hidden input with a user id to determine which user it belongs too. However, I was afraid that if they edited the code they were given they could pretend they were any user. They verify id is merley there to make doing this harder, and to help insure the form maintains some of it's integrety.

  8. #7
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Glad that I was able to help.
    There and Back Again :Ogre:


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:01 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com