2

I've the following line retrieved with ilSpy

p[var1] = (t[var1] + z.c[var1 % z.c.Length]) % 'Ā';

p,t and c are char array[].

my question is: how can he + characters? t[var1]+z.c[someNumber] are 2 characters and then he module the result with a number 'A' at the end.

4

3 回答 3

4

char is an integral type, just like int and long are, so you can add them together and use % on the value of a char instance.

In the same way that you can add ints and % them.

This explains why the above works.

What it means is a different question and is not so apparent. It could be the char was used because of its range, but is used as an integral type. It cold be that this is a function that converts lowercase characters to upper case (or vice versa), but without more context it is impossible to tell.

It is entirely possible that the decompiler you are using has misinterpreted (or couldn't fully interpret) the IL and is presenting you with something equivalent to the IL, but that is not the same as the original code.

于 2012-03-06T11:14:39.873 回答
0

如果你添加字符,你实际上是在调用 Int operator+,因为在 char 上没有定义加法。基本上,字符也是数值(只是显示方式不同),所以没问题。他可能会用“Ā”(数值:256)修改结果,以便结果在 1 字节字符的范围内。

于 2012-03-06T11:21:08.607 回答
0

正如 Oded指出的那样,ilSpy 检索到的表达式在语法上是有效的,但我认为原始代码不同。

(U+0100, Latin Capital Letter A With Macron)的代码Ā是 256,这表明 , t,cp表示一些单字节编码的字符串,例如 ASCII。那么您从 ilSpy 获得的代码确实有意义。例如(我刚刚重命名了tcp):

encrypted[index] = (source[index] + z.passPhrase[index % z.passPhrase.Length]) % 256;

在这里,我们有一个简单的加密器,它循环地向原始字符串添加一些密码。

于 2012-03-06T11:42:59.643 回答