Thread: File Encryption

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    File Encryption

    I am not sure if this post belongs in this forum or not... but... I am planing on creating a program that provides the features of a text editor, but also lets you encrypt a file. I plan to do this in the wxWidgets GUI toolkit, to which I am fairly comfortable with. Does anyone have any tips or ideas for how to encrypt a file? I know very little about encyption, but I wasn't planing on using or creating a complex encryption style, just enough to keep a group of un-educated people out of my files. I was thinking of simply adding 3 to all Unicode characters (so the character originally inputed would be 3+ whatever it was;For example, A would be D) but that seemed much to simple to use.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Some possible suggestions:
    1. Ask the user for a passkey of digits (1-8) and use each digit in a cycle to shift the alphabet. So AAAA with a key of 1234 would turn into BCDE.
    2. Use similar to above, but do an XOR encryption. Instead of adding, you use the XOR operator (^) to modify each char.


    Xor encryption can also be done with a alphanumeric key.

    Also bear in mind that if you encrypt the entire content of your text-file, you will have to save/load the file using binary file read, otherwise your newlines will get messed up.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I was thinking of simply adding 3 to all Unicode characters...
    I think that will work for plain text. (For general purpose file encryption, you can run into overflow problems when you add to the values.)

    But, you probably shouldn't try to invent you own encryption scheme. A lot of smart people have done lots of work on encryption methods already. Do a little research to see what you can find.

    The simplest encryption technique is probably XOR encryption. It's easy to do because it uses the same key and the same algorithm for encryption & decription... Run the data through once and it's encrypted. Run it through again, and it's decrypted.

    The only difficult thing about XOR encryption is that binary bit-manipulation can be confusing for beginners. Since binary isn't built into cin and cout, its difficult to "see" what you are doing.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    Nice responses. The passkey idea reminds me of WEP Encryption. Um, I'm sure I can handle bit manipulation, I programmed in assembly languages for years. Actually learned assembly as one of my first programming languages. Back then I think I ran across a program using XOR encryption I think, but it may have been a bit shift, I'm not sure. Also, I won't be using cin or cout, because I'll be using a GUI toolkit (wxWidgets; Even I was doing console, I'd probably use printf, because I feel more comfortable with it ) Those are some great ideas... Thanks.
    Last edited by Jack Walters; 11-09-2007 at 03:52 PM.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You're saving in UTF-16 Unicode, right? If the goal is merely to obfuscate the output to prevent any CASUAL attempt to decrypt it, then an easy method would be to just swap the upper and lower bytes of each Unicode character.

    If you want real encryption there are several free, easy to use libraries available.

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >I was thinking of simply adding 3 to all Unicode characters

    That's called a Ceaser Cypher. And overflow isn't a problem with it, the numbers just wrap around.. so long as they unoverflow when you reverse the cypher.

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    If you want to overdo it you should look up trap door functions. I have a book on them somewhere around here... I wonder where I put it.

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    Trap door functions? Never heard of that sounds interesting.

    >That's called a Ceaser Cypher

    Wow, I didn't think it would actually have a name. Cool.

    I may decide to have an option of different encryption methods. In the encrypted file, I'll put a signifier so the program can tell how it was encrypted, but for passkeys, I'll probably have to make the user remember those, or encrypt them in the file with the same algorithm.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is kind of pointless to have encrypted files if the encryption is hidden within the file itself. At that point, all you need is to know the encryption algorithm, and you have all the information needed to decode it. That's the whole point with a passkey - it is something only the rightful user would know. Just like a password in the olden days when entering a secret society or some such - if you don't know the password, you obviously don't belong.

    Otherwise, you may just as well simply encrypt everything with a fixed key that is stored in your application.

    I think trapdoor functions are functions that allow you to "bypass" the passkey or encryption method. Which is of course making your application "unsecure" to anyone who knows about the trapdoor.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    Hmmm. Good point. I just didn't want to burden the user with passwords,giving people too much to remember can annoy some people. But, I suppose there is no way around it if I want my app secure.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, I guess you could give the user an option:
    "Default passkey" - not particularly secure, but easy to remember - anyone who has the same application can read the file.
    "User specified passkey" - more secure, since the user chooses. No one that doesn't know (or figure out) the passkey can read the file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    Should I use numbers and letters?Or just numbers? If I use letters, should I add the ascii (or unicode) character number or? Or should I use hex codes like wep keys do? Should I make the user remember the encryption method? (If I use Ceaser, the user could mess with app to easily find out the number I added to each char.)
    Last edited by Jack Walters; 11-10-2007 at 10:55 AM.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It would depend a lot on what sort of implementation you are using. With XOR encryption for example, you can use "any key". For a ceasar encruption, you probably want offsets in the range 1..26 or so. But as I said, whatever "makes sense" for your encryption method.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    I think trapdoor functions are functions that allow you to "bypass" the passkey or encryption method. Which is of course making your application "unsecure" to anyone who knows about the trapdoor.
    I think your thinking of 'backdoor'.

  15. #15
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    So, what if I wanted to use hashes to encrypt files? Only problem is, I cant decrypt them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM