File Encrytor

This is a discussion on File Encrytor within the C Programming forums, part of the General Programming Boards category; Hey guys, Got a quick question. I am planning on writing a very very simple encryt/decrypt program just for the ...

  1. #1
    Registered User heljy's Avatar
    Join Date
    Mar 2002
    Posts
    36

    File Encrytor

    Hey guys,

    Got a quick question.

    I am planning on writing a very very simple encryt/decrypt program just for the sake of it.

    Now I understand that the simplest way is just to XOR the file with a key

    EnC = file ^ key

    DeC = Enc ^ key

    Thats the baisc idea.

    But how do I actually implement it??

    So I read in a line from the file, using say fgets()?

    Example Pesudo Code:

    open file;
    get key from user;

    while(not end of file) {

    msg = fgets(from file);
    msg = msg ^ key;
    fputs(to file, msg);

    }

    close file

    So is that how I can do it?


    Thanks!
    If only life is as easy as C...

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Don't know if it works but strings, but you can give it a try.

    A different possiblity is reading a single byte, XOR the byte with a byte from the key and write the resulting byte to a crypt-file.

  3. #3
    Registered User heljy's Avatar
    Join Date
    Mar 2002
    Posts
    36
    So the key would be a single byte as well??

    I will try that out, thanks
    If only life is as easy as C...

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    No, the key can be many bits. The key can even be as long as the source. What I meant was that the key is a bitstring, an array of bytes.

    If you're key is 3 bytes, then you could use it like

    dest [0] = source [0] ^ key [0];
    dest [1] = source [1] ^ key [1];
    dest [2] = source [2] ^ key [2];
    dest [3] = source [3] ^ key [0];
    dest [4] = source [4] ^ key [1];
    dest [5] = source [5] ^ key [2];

    Ofcourse in practice the key is much longer and you would use loops.

  5. #5
    Registered User heljy's Avatar
    Join Date
    Mar 2002
    Posts
    36
    hmm...that sounds right

    Thanks!
    If only life is as easy as C...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21