0

I want to test some cases in my app with strings which have the same hash, and I can't find it =(

I've found two strings with the same MD5. here But their hash are different. And googling didn't help me =(

NSString(MD5) category

Little story about NSDictionary

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSString *string1 = [self fileContentWithName:@"message1" encoding:NSUnicodeStringEncoding];
    NSString *string2 = [self fileContentWithName:@"message2" encoding:NSUnicodeStringEncoding];

    if (string1 != nil) {
        if (string1.hash == string2.hash) {
            NSLog(@"Hashes are the same");
        } else {
            if ([[string1 MD5Hash] isEqualToString:[string2 MD5Hash]]) {
                NSLog(@"MD5 hases are equalfor:");
                NSLog(@"lenght = %3ld - %@", string1.length, string1);
                NSLog(@"lenght = %3ld - %@", string2.length, string2);
                if ([string1 isEqualToString:string2]) {
                    NSLog(@"Strings are equal too");
                } else {
                    NSLog(@"But strings are not equal");
                }
            }
        }
    }
}

#pragma mark -

- (NSString*)fileContentWithName:(NSString*)name encoding:(NSStringEncoding)enc
{
    NSString *txtFilePath1 = [[NSBundle mainBundle] pathForResource:name ofType:@"bin"];
    NSError *error = nil;
    NSString *txtFileContents1 = [NSString stringWithContentsOfFile:txtFilePath1 encoding:enc error:&error];
    return txtFileContents1;
}
Community
  • 1
  • 1
Nuzhdin Vladimir
  • 1,714
  • 18
  • 36

0 Answers0