0
嗨 下面是用於加密和解密 現在我想用iphonesdk 有人知道PLZ幫我寫(轉換)的目標c語言的代碼我的java代碼...加密和解密在iphonesdk
//public static byte ENC_DEC_KEY = 3;
/*
public static String encrypt(byte key, String cleartext) throws Exception
{
char[] chars = cleartext.toCharArray();
for (int i=0; i < chars.length; i++)
{
char c = chars[i];
if (c > 32 && c < 127)
{
int x = c - 32;
x = (x + key) % 96; // if x > 96 - shift then modulo is 1
chars[i] = (char) (x + 32);
}
}
return new String(chars);
}
public static String decrypt(byte key, String encrypted) throws Exception
{
char[] chars = encrypted.toCharArray();
key = (byte)(0 - key);
for (int i=0; i < chars.length; i++)
{
char c = chars[i];
if (c > 32 && c < 127)
{
// Change base to make life easier, and use an
// int explicitly to avoid worrying... cast later
int x = c - 32;
x = (x + key) % 96;
//x = x - shift;
chars[i] = (char) (x + 32);
}
}
return new String(chars);
}*/
k謝謝,但我想代碼爲上述代碼 – nikey 2011-03-08 08:42:49