2012-07-17 20:57:11 +00:00
|
|
|
/**
|
2014-09-24 05:07:02 +00:00
|
|
|
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com)
|
|
|
|
*
|
|
|
|
* See the enclosed file LICENSE for license information (LGPLv3). If you did
|
|
|
|
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
|
|
*
|
|
|
|
* @author Maarten Billemont <lhunath@lyndir.com>
|
|
|
|
* @license http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
|
|
*/
|
2012-07-17 20:57:11 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// MPAlgorithm
|
|
|
|
//
|
|
|
|
// Created by Maarten Billemont on 16/07/12.
|
|
|
|
// Copyright 2012 lhunath (Maarten Billemont). All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MPAlgorithm.h"
|
|
|
|
|
2015-09-23 04:31:33 +00:00
|
|
|
id<MPAlgorithm> MPAlgorithmForVersion(MPAlgorithmVersion version) {
|
2012-07-17 20:57:11 +00:00
|
|
|
|
|
|
|
static NSMutableDictionary *versionToAlgorithm = nil;
|
|
|
|
if (!versionToAlgorithm)
|
|
|
|
versionToAlgorithm = [NSMutableDictionary dictionary];
|
|
|
|
|
2013-09-28 01:23:52 +00:00
|
|
|
id<MPAlgorithm> algorithm = versionToAlgorithm[@(version)];
|
2014-09-24 05:07:02 +00:00
|
|
|
if (!algorithm && (algorithm = (id<MPAlgorithm>)[NSClassFromString( strf( @"MPAlgorithmV%lu", (unsigned long)version ) ) new]))
|
2013-09-28 01:23:52 +00:00
|
|
|
versionToAlgorithm[@(version)] = algorithm;
|
2012-07-17 20:57:11 +00:00
|
|
|
|
|
|
|
return algorithm;
|
|
|
|
}
|
|
|
|
|
|
|
|
id<MPAlgorithm> MPAlgorithmDefaultForBundleVersion(NSString *bundleVersion) {
|
|
|
|
|
2013-04-20 18:11:19 +00:00
|
|
|
if (PearlCFBundleVersionCompare( bundleVersion, @"1.3" ) == NSOrderedAscending)
|
2014-09-24 05:07:02 +00:00
|
|
|
// Pre-1.3
|
2013-04-20 18:11:19 +00:00
|
|
|
return MPAlgorithmForVersion( 0 );
|
2014-09-24 11:58:23 +00:00
|
|
|
if (PearlCFBundleVersionCompare( bundleVersion, @"2.1" ) == NSOrderedAscending)
|
|
|
|
// Pre-2.1
|
|
|
|
return MPAlgorithmForVersion( 1 );
|
2012-07-17 20:57:11 +00:00
|
|
|
|
|
|
|
return MPAlgorithmDefault;
|
|
|
|
}
|
2014-07-26 05:26:33 +00:00
|
|
|
|
|
|
|
NSString *NSStringFromTimeToCrack(TimeToCrack timeToCrack) {
|
|
|
|
|
|
|
|
if (timeToCrack.universes > 1)
|
|
|
|
return strl( @"> age of the universe" );
|
|
|
|
else if (timeToCrack.years > 1)
|
|
|
|
return strl( @"%d years", timeToCrack.years );
|
|
|
|
else if (timeToCrack.months > 1)
|
|
|
|
return strl( @"%d months", timeToCrack.months );
|
|
|
|
else if (timeToCrack.weeks > 1)
|
|
|
|
return strl( @"%d weeks", timeToCrack.weeks );
|
|
|
|
else if (timeToCrack.days > 1)
|
|
|
|
return strl( @"%d days", timeToCrack.days );
|
|
|
|
else if (timeToCrack.hours > 1)
|
|
|
|
return strl( @"%d hours", timeToCrack.hours );
|
|
|
|
else
|
|
|
|
return strl( @"trivial" );
|
|
|
|
}
|