Numbers are entered into text fields and are then stored as integers. The user then enters numbers into a text view. Every number is put into an element of an array. Each element of the array is modified (decrypts to find ascii number value and then changes the number to a character). The newly modified number (to character) is added into the array by replacing the element it had previously modified. Code for this can be shown here:
NSString *n_string = _n_key_textfield.text;
int n = [n_string intValue];
NSString *d_string = _d_key_textfield.text;
int d = [d_string intValue];
NSString *toDecryptMessage = _messageToDecrypt.text;
NSArray *words = [toDecryptMessage componentsSeparatedByString: @","];
NSMutableArray *mutableWords = [NSMutableArray arrayWithCapacity:[words count]];
[mutableWords addObjectsFromArray:words];
for (int i = 0; i <[words count]; i++){
//get value at index i
//decrypt it
//then becomees ascii number
//convert ascii number to character
//replace in array
//print array
NSString *string = mutableWords[i];
NSLog(@"%@", string);
NSInteger x = [string intValue];
NSLog(@"%ld",(long)x);
NSInteger encrypted_power = pow(x,d);
//problem here
NSInteger decrypted_number = encrypted_power % n;
NSLog(@"decrypted number @%ld", (long)decrypted_number);
NSString* charString = [NSString stringWithFormat:@"%ld" , (long)decrypted_number];
[mutableWords replaceObjectAtIndex:i withObject:charString];
}
NSString *string = [mutableWords componentsJoinedByString:@" "];
_finalDecryptedMessage.text = string;
When the program is ran with N = 4307, d = 3341, and with a breakpoint at:
NSInteger decrypted_number = encrypted_power % n;
...
n_string NSTaggedPointerString * @"4307" 0xa000000373033344
n int 4307
d_string NSTaggedPointerString * @"3341" 0xa000000313433334
d int 3341
toDecryptMessage __NSCFString * @"3442,3121" 0x000060800005f0e0
words __NSArrayM * @"2 elements" 0x000060800005ed20
mutableWords __NSArrayM * @"2 elements" 0x0000608000057a60
string NSString * 0x1 0x0000000000000001
i int 0
string NSTaggedPointerString * @"3442" 0xa000000323434334
x NSInteger 3442
encrypted_power NSInteger = (NSInteger) -9223372036854775808
decrypted_number NSInteger 0
charString NSString * nil 0x0000000000000000
why is encrypted_power NSInteger equal to -9223372036854775808 and how do I solve this?
As always, any help is greatly appreciated.