0

我有两个代码片段。一个加密,另一个解密。但是解密代码似乎也无法像我想要的那样工作:/

加密:letter = ((letterInt + 1) * constant) modulus 29

加密代码行:

bogstaver[i-1] = alfabet.get(((alfabet.indexOf(bogstaver[i - 1]) + 1) * C) % 29);

解密:letter = Int / constant, while (int / constant) modulus 1 = 0

解密代码:

D = alfabet.indexOf(bogstaver[i - 1]);

while ((D / C) % 1 != 0){
    D = D + 29;
}           
bogstaver[i - 1] = alfabet.get((D / C) - 1);

我在加密中使用的字母 ( letterInt) 与我在解密后得到的字母 ( letter)不同

顺便说一句,alfabet是一个List有 29 个字符的

4

1 回答 1

1

What is this code (D / C)%1 supposed to do? Are you sure that modulo operator does work with floating operands? I'm not an android developer, but make sure that the expression in brackets isn't casted to an integer before modulo is counted. If that's the case then while loop terminates after first evaluation of the condition. You could rewrite the condition to something like that:

while(D % C != 0){
...
}
于 2013-05-11T13:56:26.483 回答