用户输入字符串值并存储。该字符串中的每个字符都放在一个数组中。数组的每个元素都被修改; (找到字符的ascii值,然后进行计算以更改ascii值)。通过替换先前修改过的元素,将新修改的数字添加到数组中。代码可以在这里显示:
NSString *toEncryptMessage = _message.text;
NSMutableArray *characters = [[NSMutableArray alloc]initWithCapacity:[toEncryptMessage length]];
int encrypted_power;
int encrypted_number;
for (int i = 0; i <[toEncryptMessage length]; i++){
NSString* subchar = [toEncryptMessage
substringWithRange:NSMakeRange(i, 1)];
if (subchar) [characters addObject:subchar];
unichar chr = [subchar characterAtIndex:0];
encrypted_power = pow(chr,e);
encrypted_number = encrypted_power % N;
NSLog(@"ascii value %d", chr);
[characters replaceObjectAtIndex:i withObject:[NSNumber
numberWithInt: encrypted_number]];
}
NSLog(@"%@", characters);
}
然而,我遇到的问题是&#39; encrypted_power&#39;是一个负数。 Encrypted_power是“e”的幂的ascii值,其中e = 7(之前在其他地方计算过)。
我在&#39; pow&#39;中添加了一个断点。线和插入&#39; hi&#39;待修改:
e = 7
toEncryptMessage = (NSTaggedPointerString *) @"hi" 0xa000000000069682
characters __NSArrayM * @"1 element" 0x00006080002513d0
encrypted_power = (int) -2147483648
encrypted_number = (int) -2
i = 0
然后尝试修改下一个字符:
encrypted_power = (int) -2147483648
encrypted_number = (int) -2
i = (int) 1
subchar = (NSTaggedPointerString) @"i"
chr unichar U+0068 u'i'
在日志中是这样的:
Prototype2[56766:1730834] (
"-2",
"-2"
)
2017-10-12 16:54:21.766561 Prototype2[56766:1730834] [Common]
_BSMachError: port 7417; (os/kern) invalid capability (0x14) "Unable to
insert COPY_SEND"
2017-10-12 16:54:21.767494 Prototype2[56766:1730834] [Common]
_BSMachError: port 7417; (os/kern) invalid name (0xf) "Unable to
deallocate send right"
任何帮助都很好,谢谢。