Support Forums

Full Version: Simple scantime crypting source code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well hackforums.net is down atm and i'm bored. Jus a simple code to let you guys see how to encrypt an entire file and put in in a different file encrypted, which you can then decrypt it. It's not the scantime crypter source code with stub and builder but just the encryption decryption function.

Code:
/// rot 128
int Rot128_FileToFile(char *Filename_In, char *Filename_Out)
{
    FILE *Copy = fopen(Filename_In, "rb");
    FILE *Paste = fopen(Filename_Out, "wb");
    if(!Copy || !Paste)
        return -1;

    int c;
    while((c = fgetc(Copy)) != EOF)
    {
        // works with 128, 120 too weird.
        if(c >= 0 && c <= 127)
            c+=128;
        else c-=128;

        fprintf(Paste, "%c", c);
    }

    fclose(Copy);
    fclose(Paste);
    return 1;
}

Let me know what you guys think.
Looks pretty pimp, dude. As far as complexity, the algorithm isn't very strong, but I like your coding style. Does:
Code:
while((c = fgetc(Copy)) != EOF)
actually work? Using an assignment operator in conjuction with a comparison operator, all as part of a conditional? Never seen that before.
(01-19-2010, 08:10 PM)J4P4NM4N Wrote: [ -> ]Does Using an assignment operator in conjuction with a comparison operator, all as part of a conditional?

It's valid C/C++ so it works fine. It's use can sometimes be frowned upon (the coding standards where I worked disallowed doing it) because it can be troublesome to read when you are scanning code, but it works in this case since it prevents code duplication.
I see. I can also see why it was frowned upon, hehe.