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

My encryption in C

Name: Anonymous 2007-02-04 13:25

// discuss
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void flip(char *str) {
   
    int i = -1, o = strlen(str);
    char temp;
   
    while((--o - ++i) >= 0) {
        temp = str[i];
        str[i] = str[o];
        str[o] = temp;
    }
   
}

void rot(char *str, int number) {
   
    int i;
    number %= 26;
   
    for(i=0; i<strlen(str); i++)
       
        if(isupper(str[i])) {
        if(!isupper(str[i] += number))
            str[i] -= 26;
        }
       
        else if(islower(str[i])) {
            if(!islower(str[i] += number))
                str[i] -= 26;
        }
}

int encrypt(char *filepath, char *encrypted) {
   
    FILE *fp, *fp2;
    char *buffer;
    long filesize;
    int i = -1;
   
    if(!(fp = fopen(filepath, "rb"))) {
        fprintf(stderr, "Can't access %s\n", filepath);
        return 1;
    }
   
    if(!(fp2 = fopen(encrypted, "w"))) {
        fprintf(stderr, "Can't write to %s\n", encrypted);
        fclose(fp);
        return 2;
    }
   
    fseek(fp, 1, SEEK_END);
    filesize = ftell(fp);
    rewind(fp);

    buffer = (char*)malloc(filesize+1);
   
    fread(buffer, 1, filesize, fp);
    fclose(fp);
   
    while(buffer[++i])
        if(islower(buffer[i]))
            buffer[i] = 219 - buffer[i];
        else if(isupper(buffer[i]))
            buffer[i] = 155 - buffer[i];
        else if(isdigit(buffer[i]))
            buffer[i] = 105 - buffer[i];
       
    flip(buffer);
    rot(buffer, 13);
   
    fputs(buffer, fp2);
    free(buffer);
    fclose(fp2);
   
    return 0;
}

main(int argc, char **argv) {
    encrypt(argv[1], argv[2]);
}

Name: Anonymous 2007-02-06 0:47

Don't roll your own. Use AES, Twofish or some such algorithm that's had some actual research and is a proper standard. If you're really paranoid, use separate key material for both and encrypt twice.

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