A new project i'm undertaking...

This is a discussion on A new project i'm undertaking... within the C++ Programming forums, part of the General Programming Boards category; Hey everyone! I've been really bored lately and i want some programming to do! haha so i asked my mom ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    A new project i'm undertaking...

    Hey everyone!

    I've been really bored lately and i want some programming to do! haha so i asked my mom if she wanted me to make her a program to keep track of her grades at school. She uses a gradebook and spends hours calculating final grades and such so i figured i'd make her life easier.

    Okay so i've been writing everything down and all to get organized, i need to have everything together before i even put down a single line of code, ha.

    One thing i encountered was this, i wanted to do a basic encryption on the grade files. I know no one is ever gonna try to mess with the files but i figured it would add an extra challenge and aspect to the program to keep me busy. I was thinking of using the hash of the user password (to get into the program) the only problem is that i would have to store this number somewhere and it would be easy for someone to get to it and decrypt the files using it.

    So what should i do? I'm not looking for code right now just suggestions.


    Thanks!


    PS- Maybe a hash of the hash? i dunno.
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    One thing i encountered was this, i wanted to do a basic encryption on the grade files. I know no one is ever gonna try to mess with the files but i figured it would add an extra challenge and aspect to the program to keep me busy. I was thinking of using the hash of the user password (to get into the program) the only problem is that i would have to store this number somewhere and it would be easy for someone to get to it and decrypt the files using it.
    This is how Linux and UNIX password systems work. The password is encrypted with some encryption mechanism, and the encrypted version is stored somewhere (usually in /etc/shadow). Then, when someone types a password, that password is encrypted and compared with the encypted version. If they match, the password is correct.

    The nice thing about that scheme is that you never store the unencrypted password, nor do you actually even need to use an algorithm that can be decypted. You can use a "one-way" algorithm, and in fact many programs do.

    I don't know if that helps. Unfortunately I don't know of any one-way (trapdoor) algorithms.

    [edit] BTW, you could write the plaintext version first, and then, if you write it well and modular-ily, modify it to use encryption with little hassle. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Yeah one way hash functions

    But yeah, i figured out not to store the unencrypted password a while ago, i used to (*try to*) do a lot of that stuff.

    It's just how do i encrypt the files? That's what i wonder, i cant use and irreversible algorithm for that cause you gotta be able to reopen the files haha so i dunno what to do. I'll do that part of the program last but its the one pitfall i can really think of right now.


    Thanks!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Well, it depends on how secure you want those files to be. For very simple encryption you could just use CBC, Cipher Block Chaining encryption. It's very easy to crack (this is a first-hand experience), but someone who just opens the file by accident won't be able to read it.

    For CBC, basically you take the key and XOR it with the first byte; this byte is written to the file. Then you use the generated byte for the next key.

    I did a study on CBC once, a long time ago. You can improve its encryption somewhat (very slightly) by using two keys. (It's still a very bad encryption algorithm.) Perhaps you could have the password as two bytes, then split that in half and use each half as one of the keys.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Your best best for "unbreakable" encryption is probably AES (it is a standard, after all). I'm sure you can find plenty of implementations on the web.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    I'll look into CBC, AES is overkill haha, no ones ever really gonna open the files directly, lol, so i just need sometihng basic, like CBC, thanks though!


    Oh and nother quick quesiton, i feel like an idiot cause i asked this a long..... time ago and i forget now, how do i make a folder from the program? Do i have to use a batch-file type command or is there something in C++ i can use?


    Thanks!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Oh and nother quick quesiton, i feel like an idiot cause i asked this a long..... time ago and i forget now, how do i make a folder from the program? Do i have to use a batch-file type command or is there something in C++ i can use?
    POSIX has a function called mkdir() (in <unistd.h>, I think) but it isn't standard (though omnipresent on Linux systems). You'd need to use system() for windows:
    Code:
    system("mkdir directory");
    I suggest using "mkdir" instead of "md", because "mkdir" is the right command on both Windows and Linux.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Thanks!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  9. #9
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Hey guys, i gotta problem =(

    In my program i have a function to encrypt a file (using what i think is the CBC mentioned earlier). But when i pass the filename to ofstream and ifstream it tells me that it cannot convert a string to a const char *.

    The function looks like this:
    Code:
    ...
    void encryptFile(string filename)
    {
         ...
         ofstream fout(filename);
         ...
    }
    ...
    Why wont it work? Its cause its beign passed to the function as a pointer probably right?

    What can i do?


    thanks!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    filename.c_str()

  11. #11
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    i had a feeling that might be it i'll give it a try, thanks!

    Nope =( It still won't compile
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Not sure what the problem might be, the below compiles fine as an example.

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    std::string testthis;
    std::string testthat;
    
    void encryptFile(std::string filename)
    {
         filename.append(".txt");
         ofstream fout(filename.c_str(),ios::out);
         fout<<testthat;
    }
    
    
    int main()
     {
           testthat="Hello, thar";
    
               testthis="testthis";
               encryptFile(testthis);
           
          std::cin.get();
          return 0;
          }
    Last edited by Oldman47; 04-14-2007 at 10:06 PM.

  13. #13
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    i added the .c_str() in the wrong spot Lemme give it a try.
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  14. #14
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    It works but i'm getting a seg fault i think with the strings, here's the code:
    Code:
    //Encryption Algorithm Start
    	encrypted.at(0) = temp.at(0)^hPass;
    	for(int i=1; i<temp.size(); i++)
    	{
    		encrypted.at(i) = encrypted.at(i-1)^hPass;
    	}
    encrypted is a string (not yet initialized) and hPass is an unsigned integer.


    Anyone know why this is seg faulting? All the variables in the debugger look alright to me. =(

    EDIT:

    Nevermind, i used push_back() instead.
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  15. #15
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Never mind again

    EDIT
    "Anyone can aspire to greatness if they try hard enough."
    - Me

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undertaking Website Building Project and Application Software Development
    By Programmer168 in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-21-2009, 04:44 AM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 08:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM

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