【发布时间】:2014-05-06 14:05:12
【问题描述】:
我正在做一个项目,我需要在 java 中对字符串进行编码和编码。我的字符串是由波斯字符组成的 UTF-8 字符串。我只是想用一个静态字符对每个字节进行异或,然后用相同的静态字符再次对它进行异或。
我写了下面的代码,但它完全错了!我用英文字符检查它,它可以工作。
我该如何解决这个问题?
String str = "س";
char key = 'N';
byte bKey = (byte) key;
byte[] b = str.getBytes();
for (int i = 0; i < b.length; i++)
{
b[i] = Byte.valueOf((byte) (b[i] ^ bKey));
}
String str1 = new String(b);
b = str1.getBytes();
for (int i = 0; i < b.length; i++)
{
b[i] = (byte) (b[i] ^ bKey);
}
String str2 = new String(b);
【问题讨论】: