LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-28-2006, 02:34 PM   #1
Tux-O-Matic
Member
 
Registered: Sep 2006
Distribution: Fedora Core 5 (no internet)
Posts: 95

Rep: Reputation: 15
Post Help on Research Project


I'm doing a research project on the random number theory, and I'm attempting to emulate srand. However, the file is encrypted. Does anyone have the source code, the writer of srand, or someone that may know the ins and outs of srand?
And if anyone tells me to look at the man page, I already have: no author is listed.

Last edited by Tux-O-Matic; 09-28-2006 at 03:59 PM.
 
Old 09-29-2006, 02:07 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,623
Blog Entries: 10

Rep: Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773
What do you mean by "the file is encrypted"?


Cheers,
Tink
 
Old 09-29-2006, 03:48 PM   #3
Tux-O-Matic
Member
 
Registered: Sep 2006
Distribution: Fedora Core 5 (no internet)
Posts: 95

Original Poster
Rep: Reputation: 15
When I used vim srand (when I got to the folder), I saw some garbage like this:
@@@@@@@[^@@@@@@@@@@@@[^[^@@@@@@
 
Old 09-29-2006, 04:02 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, Slackware, Slax, Knoppix, SysrescueCD
Posts: 1,328

Rep: Reputation: 51
Quote:
Originally Posted by Tux-O-Matic
When I used vim srand...
Well, you'll always see garbage like that if you try to edit a binary file.

I wasn't aware of a commandline program named "srand" (it's a C library function) but the context of your description makes me think you found one. And then tried to edit it.
 
Old 09-29-2006, 04:21 PM   #5
Tux-O-Matic
Member
 
Registered: Sep 2006
Distribution: Fedora Core 5 (no internet)
Posts: 95

Original Poster
Rep: Reputation: 15
Thanks, but could someone please answer my original question please?
 
Old 09-29-2006, 05:13 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,623
Blog Entries: 10

Rep: Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773
If you told what that file you're talking about is, maybe?


Cheers,
Tink
 
Old 09-29-2006, 05:59 PM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, Slackware, Slax, Knoppix, SysrescueCD
Posts: 1,328

Rep: Reputation: 51
Quote:
Originally Posted by Tux-O-Matic
Thanks, but could someone please answer my original question please?
Unfortunately, I really can't tell what your original question was. I believe your inital assumption about an encrypted file is incorrect. I think you must be vi-ing some binary file and misinterpretting the non-ASCII characters as encryption. But I can't really tell that for sure, your description was not detailed enough. I'm just guessing. You need to give us more information.

If you're looking for the source code for the C library call srand(), I'd start off with something like the commands below to attempt to find it. I don't know if this will find the code for you, but at least it should give you some idea of where to look. You will need to have your kernel sources installed.
Code:
# cd /usr/include
# find . -type f -print | xargs fgrep srand
# cd /usr/src/linux
# find . -type f -name *.c -print | xargs fgrep srand
# find . -type f -name *.h -print | xargs fgrep srand
You can skip the -name parameter to find if you have just installed your kernel sources but not compiled. After a compile you'll have lots of object files in there and you certainly don't need to be grepping through those. Or, you can run a "make clean" to get rid of the object files before running the find.
 
Old 09-29-2006, 09:59 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,623
Blog Entries: 10

Rep: Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773
Quote:
Originally Posted by haertig
Code:
# cd /usr/include
# find . -type f -print | xargs fgrep srand
# cd /usr/src/linux
# find . -type f -name *.c -print | xargs fgrep srand
# find . -type f -name *.h -print | xargs fgrep srand
Code:
find -type f -name "*srand*.[ch]
No need for two runs, or pipe and xargs. Think lazy ;}


Cheers,
Tink
 
Old 09-29-2006, 10:32 PM   #9
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, Slackware, Slax, Knoppix, SysrescueCD
Posts: 1,328

Rep: Reputation: 51
Quote:
Originally Posted by Tinkster
find -type f -name "*srand*.[ch]
I was trying to locate a sourcefile that contains the text "srand", not a file with srand in it's filename. Who knows what the actual sourcefile name is.
 
Old 10-02-2006, 12:09 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,623
Blog Entries: 10

Rep: Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773
Of course - had a blonde moment. but you can still get away with one run,
and without xargs :}

Code:
find -type f -name "*.[ch]" -exec grep srand {} \;

Cheers,
Tink
 
Old 10-02-2006, 12:39 PM   #11
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, Slackware, Slax, Knoppix, SysrescueCD
Posts: 1,328

Rep: Reputation: 51
Code:
find -type f -name "*.[ch]" -exec grep srand {} \;
Gotcha! I typically use that "*.[ch]" type of specification myself, but didn't in my example, for some unexplained reason.

As far as -exec grep srand {} \;, my poor little brain recognizes | xargs grep srand much more readily. Habit and old age I guess! (Note: I still use -print with find too. Not really required these days, but it used to be. At least on older System V, SunOS, etc. Another archiac habit of mine.)
 
Old 10-02-2006, 01:59 PM   #12
Tux-O-Matic
Member
 
Registered: Sep 2006
Distribution: Fedora Core 5 (no internet)
Posts: 95

Original Poster
Rep: Reputation: 15
Could someone please get me what I want. I don't mean to be hasty . If it's illegal to see the source code, it's okay to just tell me.
 
Old 10-02-2006, 02:44 PM   #13
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Ahhhh you want the source code, you won't get that by opening the binary with a text editor (as stated) you can search for the sourcefile (as stated).

Why ask a question when you dont want an answer?

Go to the authors website (been a longtime since i saw a developer without one) see what license it is under, see if it's there?

I honestly can't believe how rude some people are
 
Old 10-02-2006, 04:14 PM   #14
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, Slackware, Slax, Knoppix, SysrescueCD
Posts: 1,328

Rep: Reputation: 51
Quote:
Originally Posted by Tux-O-Matic
Could someone please get me what I want.
OK!

From .../glibc-2.5/stdlib/srand48.c
Code:
#include <stdlib.h>
void
srand48 (seedval)
     long seedval;
{
  (void) __srand48_r (seedval, &__libc_drand48_data);
}
If that's not enough, more from .../glibc-2.5/stdlib/srand48_r.c
Code:
#include <stdlib.h>
#include <limits.h>

int
__srand48_r (seedval, buffer)
     long int seedval;
     struct drand48_data *buffer;
{
  /* The standards say we only have 32 bits.  */
  if (sizeof (long int) > 4)
    seedval &= 0xffffffffl;

  buffer->__x[2] = seedval >> 16;
  buffer->__x[1] = seedval & 0xffffl;
  buffer->__x[0] = 0x330e;

  buffer->__a = 0x5deece66dull;
  buffer->__c = 0xb;
  buffer->__init = 1;

  return 0;
}
weak_alias (__srand48_r, srand48_r)
If you want the whole enchilada, I'd recommend
Code:
$ wget ftp://ftp.gnu.org/gnu/glibc/glibc-2.5.tar.gz
$ tar xzvf glibc-2.5.tar.gz
$ cd glibc-2.5
$ find . -name "*srand*" -print
... and continue on from there ...
 
Old 10-02-2006, 04:19 PM   #15
Tux-O-Matic
Member
 
Registered: Sep 2006
Distribution: Fedora Core 5 (no internet)
Posts: 95

Original Poster
Rep: Reputation: 15
Okay...Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need a research topic for my Sr. project mack1971 General 6 08-12-2006 06:06 AM
Research for a new GPL project future leet Linux - Software 0 02-17-2004 11:41 AM
Beginning a big project - Need an Good Project Manager gamehack Programming 3 01-15-2004 11:49 AM
Somehow involveing linux with a senior research project adair General 2 07-22-2003 09:13 PM
research project arlothemoo General 1 12-15-2002 07:44 PM


All times are GMT -5. The time now is 04:14 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration