Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FrozenVoid wrote a C program!

Name: Anonymous 2009-06-18 1:39

Simple XOR encryptor in C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//Syntax : Xorw inputfile outputfile Number_of_iterations=(encrypt +num,decrypt -num);
//example: 'xorw input.txt output.dat 734',then 'xorw output.dat input.txt -734' to get file back
//numbers above 10k result in much slower encryption/decryption speed.
int main(int argc, char *argv[]){int level;long int filesize;char mode;//1back0forw
if(!argv[3]){puts("No level specified\n");return 1;}else{ level=atoi(argv[3]);if(!level){puts("Bad level\n");return 1;}};
mode=level<0?1:0;level=abs(level);
FILE *output= fopen(argv[2], "wb" );if(!output){puts("File write error\n");return 1;}
FILE *input = fopen( argv[1], "rb" );if(!input){puts("No input file exists\n");return 1;};
fseek(input,0,SEEK_END);filesize=ftell(input);rewind(input);char *inpbuf=malloc(filesize);
fread(inpbuf,1,filesize,input);fclose(input);
unsigned char prevbyte;long int pos;unsigned char tmpbyte;
if(mode){for(;level;level--){
prevbyte=0x00;for(pos=0;pos<filesize;pos++){tmpbyte=inpbuf[pos];inpbuf[pos]^=prevbyte;prevbyte=tmpbyte;}
}}else{for(;level;level--){
prevbyte=0x00;for(pos=0;pos<filesize;pos++){inpbuf[pos]^=prevbyte;prevbyte=inpbuf[pos];}
}};fwrite(inpbuf,1,filesize,output);free(inpbuf);fclose( output );return 0;}
Posted by FrozenVoid at 18:48 0 comments Links to this post
Labels: encryption, xor, xorw.c

Name: Anonymous 2009-06-18 1:55

Let me be the first to say: Nobody gives a fuck.

Name: Anonymous 2009-06-18 2:08

>>2
I'd like to be the second to say it. Implicitly.

Name: Anonymous 2009-06-18 3:42

I'm going to anonymously mail this as a code sample along with a vanilla resume to my HR department, and then ask the senior programmers who got asked about it what they thought.

Name: Anonymous 2009-06-18 4:36

Oh, for fuck sake.
C != Javascript, so why is he still using such horrible script kiddie js formatting?
This is the kind of thing that makes real programmers think web programmers are mentally handicapped.

Name: Anonymous 2009-06-18 4:40

>>5

They aren't?

Name: Anonymous 2009-06-18 4:40

>>2,3
agreed.

Name: Anonymous 2009-06-18 4:48

>>6
Hi Frozenvoid

Name: Anonymous 2009-06-18 5:29

int main(int argc, char *argv[])
FILE *output= fopen(argv[2], "wb" );if(!output){puts("File write error\n");return 1;}
FILE *input = fopen( argv[1], "rb" );if(!input){puts("No input file exists\n");return 1;};
}};fwrite(inpbuf,1,filesize,output);free(inpbuf);fclose( output );return 0;}
Whitespace is bloat, what did I tell you?

Also, lol'd at 0x00.

Name: Anonymous 2009-06-18 5:35

Thanks to astyle, here it is a correct indentation of the code

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//Syntax : Xorw inputfile outputfile Number_of_iterations=(encrypt +num,decrypt -num);
//example: 'xorw input.txt output.dat 734',then 'xorw output.dat input.txt -734' to get file back
//numbers above 10k result in much slower encryption/decryption speed.
int main(int argc, char *argv[])
{
    int level;
    long int filesize;
    char mode;//1back0forw
    if (!argv[3]) {
        puts("No level specified\n");
        return 1;
    } else {
        level=atoi(argv[3]);
        if (!level) {
            puts("Bad level\n");
            return 1;
        }
    };
    mode=level<0?1:0;
    level=abs(level);
    FILE *output= fopen(argv[2], "wb" );
    if (!output) {
        puts("File write error\n");
        return 1;
    }
    FILE *input = fopen( argv[1], "rb" );
    if (!input) {
        puts("No input file exists\n");
        return 1;
    };
    fseek(input,0,SEEK_END);
    filesize=ftell(input);
    rewind(input);
    char *inpbuf=malloc(filesize);
    fread(inpbuf,1,filesize,input);
    fclose(input);
    unsigned char prevbyte;
    long int pos;
    unsigned char tmpbyte;
    if (mode) {
        for (;level;level--) {
            prevbyte=0x00;
            for (pos=0;pos<filesize;pos++) {
                tmpbyte=inpbuf[pos];
                inpbuf[pos]^=prevbyte;
                prevbyte=tmpbyte;
            }
        }
    } else {
        for (;level;level--) {
            prevbyte=0x00;
            for (pos=0;pos<filesize;pos++) {
                inpbuf[pos]^=prevbyte;
                prevbyte=inpbuf[pos];
            }
        }
    }
    ;
    fwrite(inpbuf,1,filesize,output);
    free(inpbuf);
    fclose( output );
    return 0;
}

Name: Anonymous 2009-06-18 5:38

>>9
Whitespace is bloat
Anybody who says this is going to programmer hell.
In programmer hell you will get to experience the joys of spending all day and night reading/debugging/& modifying endless legacy code written by programmers who also do not believe in using whitespace or legibility.

Name: Anonymous 2009-06-18 5:43

>>10
well it looks like i need to eat my words.
when /prog/ was talking about this earlier i thought it was bullshit. now i finally see the light and understand it's purpose, to make javascript programmer's code readable.

Name: Anonymous 2009-06-18 5:56

>>10
};
Oh no you don't.

Name: Anonymous 2009-06-18 6:09


I thought I
XOR a pussycat
          .-"-.
     \   /_ _  \
      \  \@ @  /
         (_> _)
          `)(_
          /((_`)_,
          \__(/-" 
         __|||_
        ((__|__))

Name: Anonymous 2009-06-18 8:37

lol'd

Name: Anonymous 2009-06-18 8:50

>>10
Nice to see that FV didn't stop at his previous pinnacle of idiocy, -- describing converting numbers to different bases as a compression algorithm, -- and now produced an even more stunningly retarded technique: *TA DA DA DA* repeated XORing! Because if you XOR second byte with first **twice** it'll be twice as hard to decrypt!

Name: Anonymous 2009-06-18 8:51

>>13
(;

Name: Anonymous 2009-06-18 9:42

>>16
??????????

Name: Anonymous 2009-06-18 11:03

>>10
puts("No level specified\n");
is another new line really necessary?

Name: Anonymous 2009-06-18 12:21

>>16
It's about as effective as rot26 encryption.

Name: Anonymous 2009-06-18 12:48

>>20
UNBREAKABLE

Name: Anonymous 2009-06-18 13:50

>>19
NO EXCEPTIONS

Name: Anonymous 2009-06-18 13:56

>>22
Expert DYCPer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List