The user just inputs a passphrase, for example foobar and I have begin with masking it. First I have to isolate the 15th bit and check if its 1. Then I isolate the 14th bit and check if that is 1. I continue doing this until there are no characters left in the file itself. I figured out how to mask (thanks to you and wikipedia). However, I now have to create a loop that starts masking with the 15th bit and keeps going until EOF. I was thinking I would have to use a for loop for this part but I don't know how I would implement a for loop when it comes to masking. Actually, the masking I did doesn't isolate the 15th bit. This is what I have so far:
Code:
#include "crypto.h"
#include <stdlib.h>
#include <stdio.h>
int generateKey()
{
char c;
int h = 0;
int a = 31415;
int b = 27183;
int power = 2;
int i;
/* calculates the 2 to the 16th and stores it to power*/
for(i=1; i<16; i++)
{
power = power*2;
}
/* while there is no linefeed, does the algorithm and
* waits for more input */
while(c != '\n')
{
scanf("%c", &c);
h = (a*h + (int)c) % power;
a = (a*b) % (power-1);
}
return h;
}
int encrypt(int key)
{
FILE *fp;
FILE *fp2;
FILE *fp3;
int MASK;
int retval;
char word, tmp;
if((fp = fopen("input.txt", "r")) == NULL) return -1;
else
{
fp2 = fopen("part1.txt", "w");
fp3 = fopen("part2.txt", "w");
retval = fscanf(fp, "%c", &word);
MASK = generateKey() & 0xffff;
while(retval != EOF)
{
for(i