diff -r 000000000000 -r d52f6b0d94be NSData+Mnemonic.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSData+Mnemonic.m Wed Jul 01 14:04:56 2009 -0700 @@ -0,0 +1,29 @@ +// +// NSData+Mnemonic.m +// Cloudy +// +// Created by Jens Alfke on 6/24/09. +// Copyright 2009 Jens Alfke. All rights reserved. +// + +#import "NSData+Mnemonic.h" +#import "mnemonic.h" + + +@implementation NSData (Mnemonic) + +- (NSString*) my_mnemonic { + NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)]; + if (!chars) + return nil; + int result = mn_encode((void*)self.bytes, self.length, + chars.mutableBytes, chars.length, + MN_FDEFAULT); + if (result != 0) { + Warn(@"Mnemonic encoder failed: err=%i",result); + return nil; + } + return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease]; +} + +@end