binary files

This is a discussion on binary files within the A Brief History of Cprogramming.com forums, part of the Community Boards category; friends, if i creat a binery file through c program and store some data in it.. then can any one ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    45

    binary files

    friends,
    if i creat a binery file through c program and store some data in it.. then can any one read or retrive data from my file without knowing my structure and data fields and there size?
    any s/w is there to convert binary file into text or any other readable format?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Let me put it this way, given enough time, a good programmer could
    (1) extract all the text
    (2) extract the values of the numerical data
    (3) run a simple algorythm that would give him a BASIC rundown of the structure, though not the names you gave it, ie:

    struct/class foo {

    char _c_1_[10];
    int _i_1_;
    int _i_2_;
    char _c_2_[50];
    };

    struct/class foo2{

    char _c_1_[10];
    double _d_1_;
    char _c_2_[46];
    int _i_1_;
    };


    ...etc.
    However, to be sure, this could amount to several hundred (or more) possibilities.

    So, in short - maybe. But any text would be absolutely exposed, either way.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Originally posted by Sebastiani
    Let me put it this way, given enough time, a good programmer could
    (1) extract all the text
    (2) extract the values of the numerical data
    (
    is it very easy task? and how much time 'the good programmer' will take to extract the data?

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Post a binary file as an attachment and let's see
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Sorry boss ! I don’t want to challenge u ……. I just want to know which data storage type provides max. security . Is there any other type? Or should I use encryption decryption ?

  6. #6
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Yes, it's easy to extract data from a binary file. Especially if your binary file contains text.

    You could simply XOR the binary data with a fixed character. This makes it harder to extract data, but provides no real protection against a determined hacker.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Davros is right. Encryption is really the only way to go.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    thanku very much......for all....!

  9. #9
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    May I add:

    How much 'encryption' you put into your program/binary file should depend on how much you want to protect your data.

    XORing byte values is fine at mangling the appearance of the data in the file so that it can't be viewed as easily. However, your program must be able to read the file itself, so it needs to know the XOR character used.

    Using a strong encryption technique, such RC4, is fine. But if the decryption key is hard-coded into your program, then ultimately your data is only weakly protected (no matter how good your encryption algorithm). This is because a determined programmer may simply decompile your exe to find out how it is decrypting the data, and extract the key.

    The only secure way is NOT to embed the decryption key in your program, but this means that the user must enter it each time they want to open the file (i.e. as a password).

    If all you want to do is mask the data in your binary file, use XOR. If your data is really valuable, you need a 'protection strategy'.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  2. send/recv binary files using sockets in C++
    By dafatdude in forum Networking/Device Communication
    Replies: 14
    Last Post: 07-25-2004, 12:00 PM
  3. MFC: CStrings & binary files question(s)
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-24-2004, 06:41 PM
  4. Binary files
    By Brian in forum C Programming
    Replies: 2
    Last Post: 02-18-2002, 01:13 PM
  5. storing string objects to binary files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2001, 12:33 AM

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