为什么我的脚本中有大量的内容变为负片?

时间:2017-10-13 20:08:44

标签: objective-c arrays int rsa

将数字输入文本字段,然后存储为整数。 然后,用户将数字输入文本视图。每个数字都放在一个数组元素中。修改数组的每个元素(解密以查找ascii数值,然后将数字更改为字符)。通过替换先前修改过的元素,将新修改的数字(到字符)添加到数组中。代码可以在这里显示:

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;

当程序运行时,N = 4307,d = 3341,并且断点位于:

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

为什么encrypted_power NSInteger等于-9223372036854775808,我该如何解决?

与往常一样,非常感谢任何帮助。

0 个答案:

没有答案