As you can see from the code the problem is that i cant come up with some sort of loop which allows me to try 255 keys without the manual brute force method . Ive had a look into the Bash manual but cant seem to find anything specific to what im looking for and unfortunately pipping is too complicated for me to fully understand given my current knowledge of C.
Encrypts a file using a permutation cipher.
The permutation is simply ^ with a key [0-255].
void usage(char *);
main(int argc, char *argv)
char *plainfilename, *encryptedfilename;
if (argc != 4) usage(argv);
plainfilename = argv;
encryptedfilename = argv;
key = atoi(argv);
plainin = fopen(plainfilename,"r");
encryptedout = fopen(encryptedfilename,"w");
while((c = getc(plainin)) != EOF)
// The following line is the encryption algorithm
char ec = (char) (c^key);
void usage(char * commandname)
printf("USAGE: %s plaintextfile encryptedfile key\n",commandname);
printf(" Where plaintextfile is the file you wish to encrypt\n");
printf(" and the encrypted version is placed in encryptedfile.\n");
printf(" key takes a value in the range (0-255).\n");
I need to come up with some way to do do 255 keys without having to manually try it , or even if i have to manually type it the there should be some kind of indication showing me that the file contains the unencypted file .. I can cheat around this as I already know what the key for my file is, so if there is some way i can get a detection of a sequence of words within the file then it will know it is unencrypted.
Is there anyway to overcome this problem ?