Thread: Unique Files

  1. #1
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640

    Unique Files

    Is it possible to identify if files are the same if they have the same md5 code? Erm, just came to mind, how do you calculate the md5 of a file?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Not sure, but you might look at this and this.
    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
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    ok, I took a look at
    http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html

    And I'm trying to get the Cpp code to work, I get tons of errors and not sure why. All I do is include the md5.cc and md5.hh in my main.cpp and compile and I get a shyteload of errors.

    Visual C++ .Net 2k3
    Windows XP
    Last edited by neandrake; 12-02-2003 at 08:57 AM.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Ok so I found in MSDN this:
    http://msdn.microsoft.com/library/de...ClassTopic.asp
    (imagine life without copy & paste)

    I'm a little confused though; I've never used namespaces before. How do I include the System.Security.Cryptography namespace?
    namespace System.Security.Cryptography
    doesn't work.

    Also, will I need to add the mscorlib.dll file in my project somehow?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Is it possible to identify if files are the same if they have the same md5 code?
    No, that just tells you that the files are probably the same.

    The probablility is however pretty high. md5 is a 128 bit hash, and the probability that two different files have the same md5 hash is 1 in pow(2,128)

    > and I get a shyteload of errors.
    Well posting a few of them may be helpful to the rest of us.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Originally posted by Salem
    >> and I get a shyteload of errors.
    Well posting a few of them may be helpful to the rest of us.
    Well, I kinda dumped that code and found out that there are functions already in Security namespace, but I still get an error with this code:

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    
    #using <mscorlib.dll>
    using namespace System;
    using namespace System::IO;
    using namespace System::Security;
    using namespace System::Security::Cryptography;
    
    INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPInst, LPSTR lpszCmdLine, INT iCmdShow)
    {
    	MSG msgMain;
    
    	while(GetMessage(&msgMain, 0, 0, 0))
    	{
    		TranslateMessage(&msgMain);
    		DispatchMessage(&msgMain);
    	}
    
    	MD5 *str = new MD5CryptoServiceProvider();
    
    	return (int)msgMain.wParam;
    }
    Code:
    Error:
    main.cpp(4): fatal error C1190: managed targeted code
    requires '#using <mscorlib.dll>' and '/clr' option
    Last edited by neandrake; 12-02-2003 at 10:12 AM.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  7. #7
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Ok so I changed the project option to Using Managed Extentions or something like that. No errors now.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  8. #8
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    damnit, I can't get that to work, never used namespaces before, too much new stuff, back to using the example c++ code given.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  9. #9
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Ok, back to using the example code, all I did was include md5.h and md5.cpp into my project.

    Code:
    [i]Errors:[/]
    md5.h(52): error C2061: syntax error : identifier 'istream'
    
    md5.h(54): error C2061: syntax error : identifier 'ifstream'
    
    md5.h(54): error C2535: 'void MD5::update(void)' : member
    function already defined or declared
    
    md5.h(60): error C2143: syntax error : missing ')' before '&'
    That's only a few of the errors I get. From a glance, all errors are in md5.h
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about sticking to regular C++ before trying to getting yourself horribly tangled in all that vs.net "managed" stuff?


    > md5.h(52): error C2061: syntax error : identifier 'istream'
    Perhaps a simple C++
    using namespace std;
    placed at the start of md5.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Yea, that's why I stopped using the .net shyte. I tried adding the namespace, and it didn't change anything. Could you try the same thing I did? Download the file, extract md5.hh and md5.cc and include them in your project. Then for main.cpp all I did was have a WinMain() function with nothing in it (except the message handling).
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    1,619

    Re: Unique Files

    Originally posted by neandrake
    Is it possible to identify if files are the same if they have the same md5 code? Erm, just came to mind, how do you calculate the md5 of a file?
    Also, you may want to move to SHA-1 or RIPEMD-160. MD5 has been demonstrated to be weaker against collisions in some sense, which is why most cryptographic systems are supporting MD5 only for backwards compatibility.

    In other words, SHA-1 and RIPEMD-160 are better in that collisions (two different messages producing the same digest) seems to be less. At least that is the current thought.

    You might try this library:
    http://www.eskimo.com/~weidai/cryptlib.html

    of course, it may be overkill.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  13. #13
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Very overkill

    There aren't any sites that show how to implement these hashes in c++? Maybe in another language that can be easily converted to c++
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. 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
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM