Support Forums
Simple scantime crypting source code - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Simple scantime crypting source code (/showthread.php?tid=3638)



Simple scantime crypting source code - Dimitri - 12-15-2009

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.


RE: Simple scantime crypting source code - J4P4NM4N - 01-19-2010

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.


RE: Simple scantime crypting source code - MrD. - 01-20-2010

(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.


RE: Simple scantime crypting source code - J4P4NM4N - 01-27-2010

I see. I can also see why it was frowned upon, hehe.