I tried below code :
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * str1 = @"program";
NSArray * alphabets = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil];
NSMutableDictionary * alphaToNum = [NSMutableDictionary dictionary];
NSMutableDictionary * numToAlpha = [NSMutableDictionary dictionary];
NSInteger index =0;
int shifter = 5;
for(NSString * character in alphabets){
index++;
[alphaToNum setObject:[NSNumber numberWithInteger:index] forKey:character];
[numToAlpha setObject:character forKey:[NSNumber numberWithInteger:index]];
}
NSRange * rng = {0,0};
NSLog(@"-------");
//NSLog(@"%@" , [str1 substringWithRange:NSMakeRange(1, 1)]);
for(int i=0;i<[str1 length];i++)
{
NSString * ss = [str1 substringWithRange:NSMakeRange(i, 1)];
NSInteger i = [alphaToNum valueForKey:ss];
i = (i + 5);
NSLog(@"%d",i); //last code
}
and this is what I get for the last code
2011-10-24 13:20:08.289 cipher[22732:a0f] 1103808
2011-10-24 13:20:08.290 cipher[22732:a0f] 1101168
2011-10-24 13:20:08.290 cipher[22732:a0f] 1103200
2011-10-24 13:20:08.290 cipher[22732:a0f] 1103616
2011-10-24 13:20:08.291 cipher[22732:a0f] 1103584
or even sometimes
“EXC_BAD_ACCESS”.
which is totally wrong!
This will return an NSNumber object, not an NSInteger.
Make that line as follows,
And regarding the crash, we can answer only after looking at the crash log. That would be more helpful.