cypher

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

#include <stdio.h>
#include <time.h>

int cypher(int a)
{
srand(time(NULL));
int c = rand();
a*c;
return c;
}


I have written this code to act as an encryption key generator. Why when
I use gcc -s cyph.c on this code the compiler will not create cyph.o for me
to keep as an obj file or add to a library?

Bill
 
P

Phil Carmody

Bill Cunningham said:
#include <stdio.h>
#include <time.h>

int cypher(int a)
{
srand(time(NULL));
int c = rand();
a*c;
return c;
}


I have written this code to act as an encryption key generator. Why when
I use gcc -s cyph.c on this code the compiler will not create cyph.o for me
to keep as an obj file or add to a library?


Look at the man page for gcc and its command-line options.
1) Pay attention to the -s switch
2) Pay attention to the -W family

Phil
 
H

Hyuga

Bill said:
#include <stdio.h>
#include <time.h>

int cypher(int a)
{
srand(time(NULL));
int c = rand();
a*c;
return c;
}


I have written this code to act as an encryption key generator. Why when
I use gcc -s cyph.c on this code the compiler will not create cyph.o for me
to keep as an obj file or add to a library?

Maybe the output from gcc should give you a hint:

$ gcc -s cyph.c
/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function
`_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

Also, what on earth do you expect "a*c;" to do? I hope you're not
planning to use this for anything where security matters.
 
V

vippstar

I have written this code to act as an encryption key generator. Why when
I use gcc -s cyph.c on this code the compiler will not create cyph.o for me
to keep as an obj file or add to a library?

Yeah bill, nice code. Your question is about gcc though, why are you
asking here?
 
B

Bill Cunningham

Here's a clever little optimisation trick for you:

#include <stdio.h>
#include <time.h>

int cypher(void)
{
srand(time(NULL));
return rand();
}

This code has precisely the same effect. Can you see

No I'm sorry I can't. I thought my input in main of int a passed to cypher
would multiply time's return by a's value. What's wrong?

Bill
 
I

Ian Collins

Bill said:
No I'm sorry I can't. I thought my input in main of int a passed to cypher
would multiply time's return by a's value. What's wrong?
Everything. Step though your code and see.
 
K

Keith Thompson

Yeah bill, nice code. Your question is about gcc though, why are you
asking here?

Telling him that it's "nice code" is not particularly helpful. I'm
guessing that you were being sarcastic, but Bill might not catch that.

Here's the code:

#include <stdio.h>
#include <time.h>

int cypher(int a)
{
srand(time(NULL));
int c = rand();
a*c;
return c;
}

The parameter ``a'' is not used (other than in an expression whose
result is silently discarded). srand() is called every time cypher()
is called; in most cases, srand() should be called exactly once during
an entire execution of the program. Using time(NULL) as a seed is
typically not acceptable for serious cryptographic applications, nor
is using the rand() function at all.

The answer to Bill's actual question is "read gcc's documentation,
paying particular attention to the -s and -c options".

Bill: I suggest that cryptography is beyond your current skills.
You've repeatedly started some project of reasonable size, then (as
far as we can tell) given up on it and moved on to something else.
Your methods almost guarantee that you will learn nothing.
 
K

Keith Thompson

Bill Cunningham said:
No I'm sorry I can't. I thought my input in main of int a passed to cypher
would multiply time's return by a's value. What's wrong?

You perform the multiplication. What do you do with the result?
(Hint: nothing.)
 
B

Bill Cunningham

[snip]
Bill: I suggest that cryptography is beyond your current skills.
You've repeatedly started some project of reasonable size, then (as
far as we can tell) given up on it and moved on to something else.
Your methods almost guarantee that you will learn nothing.

I guess I'm jumping ahead of myself. I just want to do something
worthwhile with C.

Bill
 
C

CBFalconer

Bill said:
#include <stdio.h>
#include <time.h>

int cypher(int a) {
srand(time(NULL));
int c = rand();
a*c;
return c;
}

I have written this code to act as an encryption key generator.
Why when I use gcc -s cyph.c on this code the compiler will not
create cyph.o for me to keep as an obj file or add to a library?

Since -s removes all relocatable information I wouldn't expect it
to work.
 
K

Keith Thompson

Jujitsu Lizard said:
I very much hope that you do not have children.

Perhaps you should consider learning something about the background of
this discussion before jumping in with stupid personal insults.
 
K

Kenny McCormack

Jujitsu Lizard said:
I very much hope that you (our friend KT, Ed.) do not have children.

I think we're safe on that score.

(At least in so far as producing them "the natural way")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,082
Members
48,773
Latest member
Kaybee

Latest Threads

Top