Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
doomedout

Need Help!

Recommended Posts

C.

I am having difficulty in doing this C project. Anyone care to explain to me as to how to go about it or any useful links?

Project Description:

Develop a simple encryption program. The program will encrypt and decrypt strings using the fibonacci numbers for a mask.

Specification:
The program will read/write the data from/to the console and a file . The end of the data will be indicated with the new-line character
Character n of the data will be encrypted/decrypted by XOR'ing the lowest byte of the nth-fibonacci number with the character.
Use a command-line switch will indicate whether to encrypt/decrypt the data. Use '/e" for encrypt and "/d" for decrypt. Display an error if the switch is invalid.
The file to read and write will be indicated by 2 strings after the command-line switch
If no files are indicated then read/write from/to the console.

Share this post


Link to post
doomedout said:

Starting, don't know where to start!

Pick a part and write it, then. I'd suggest the fibonacci function as a starting point, as it doesnt depend on any other part of the program.

Share this post


Link to post

#include <stdio.h>
#include <stdlib.h>

int fibonacci(int n);

int main(void)
{

int n = 51;
printf("%d\n", fibonacci(n));

return(0);
}


int fibonacci(int n)
{
if (n <= 2)
return 1;
else
return fibonacci(n-1) + fibonacci(n-2);

}

Ya this is the function, trouble is I have no idea how to incorporate it into the program and use it as a mask. People tell me use FFFF.

Share this post


Link to post

If you take a number and AND it with 0xff (255) you will get the low byte of the number. eg.

int i;

i = fibonacci(blah);
i = i & 0xff;

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×