Viewing other files... (Not Text Files)

This is a discussion on Viewing other files... (Not Text Files) within the C++ Programming forums, part of the General Programming Boards category; Okay, so i finished my encryptor and it works great, i'm not sure on how secure it is but judging ...

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

    Viewing other files... (Not Text Files)

    Okay, so i finished my encryptor and it works great, i'm not sure on how secure it is but judging by the key-size and fact that i'm new to all this, i'm willing to bet not very secure, haha.

    But anyways...

    If i wanted the program to be able to encrypt ANY kind of file... is this even possible? To have it encrypt word files or images etc. etc.?

    I think ios::bin or something opens the file in binary but where do i start/ go from there?


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

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    as long as you're sure you can encrypt and decrypt in a fully reversible way, this shouldn't be a problem.
    Presumably your encryptor takes an array of bytes and encrypts it? well a word file, an image, an xml doc... these are all essentially just a long array of bytes.

    so just read the file as binary into a vector of unsigned char and then encrypt.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by Junior89 View Post
    Okay, so i finished my encryptor and it works great, i'm not sure on how secure it is but judging by the key-size and fact that i'm new to all this, i'm willing to bet not very secure, haha.

    But anyways...

    If i wanted the program to be able to encrypt ANY kind of file... is this even possible? To have it encrypt word files or images etc. etc.?

    I think ios::bin or something opens the file in binary but where do i start/ go from there?


    Thanks for any help!
    Correction, not ios::bin, but ios::binary. E.g.
    Code:
    //Save current data to file
    void CSettings::saveDataToFile()
    {
    	std::ofstream binary_file("data/settings.dat",std::ios::out|std::ios::binary);
    	binary_file.write(reinterpret_cast<char *>(&mData),sizeof(CSettings::sSettingData));
    	binary_file.close();
    	std::cout<<"Settings data saved successfully!"<<std::endl;
    }
    
    //Load data from file
    void CSettings::loadDataFromFile()
    {
    	std::ifstream binary_file("data/settings.dat",std::ios::in|std::ios::binary);
    	binary_file.read(reinterpret_cast<char *>(&mData),sizeof(CSettings::sSettingData));
    	binary_file.close();
    	std::cout<<"Settings data loaded successfully!"<<std::endl;
    }

    Also for a simple encoding algorithm you might want to look at Huffman Code.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    thanks for the help guys... yes my algorithm is fully reversible i've tested it many many times and each and every one comes out the same way it went in.

    Also, this is coming from memory, but isn't this Huffman Code (now i haven't looked at the link yet) just that Huffman compression?

    I'll give these files a shot, just load them in as unsigned chars right? Cause that's how my program is opening files now, taking them in as unsigned chars so a few modifications and hopefully it'll work =)

    I'll give it a shot soon! Thanks!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Yes, using unsigned chars is a good idea when you're processing binary files.
    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.

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    Actually, (depending on the type of binary file) lpvoid type is good to use.

  7. #7
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Yarin View Post
    Actually, (depending on the type of binary file) lpvoid type is good to use.
    why?

  8. #8
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    Becuase lpvoid allows for different byte sizes (like if you are reading ints from the file), char only allows as single bytes.

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    like if you are reading ints from the file
    You will not - in a portable program - read an int from a binary file because of the endian issue...
    So you will read a sequence of bytes and create int using byteoperations depending on the endian model used.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    I see.

  11. #11
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    besides my program works on those size bytes, unsigned chars

    Thanks for the help... i'm gonna try to give it a shot... i'll let you guys know how badly i fail at first, but that's what you're here for! haha

    Cheers! =)
    "Anyone can aspire to greatness if they try hard enough."
    - Me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  2. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. reading integers into arrays from text files
    By c_beginner in forum C Programming
    Replies: 6
    Last Post: 08-05-2004, 11:42 AM
  5. Problem viewing text file
    By JamMan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2001, 06:32 AM

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