diff --git a/src/crypt/DecryptUtils.java b/src/crypt/DecryptUtils.java index 7eda6d8..89a8ca4 100644 --- a/src/crypt/DecryptUtils.java +++ b/src/crypt/DecryptUtils.java @@ -81,10 +81,10 @@ public abstract class DecryptUtils { buffer[3] = table[buffer[3] & 0xFF]; } - protected void set_table_data(byte table[], int i) { - table[i] = decrypt_table[table[i] & 0xFF]; - table[i + 1] = decrypt_table[table[i + 1] & 0xFF]; - table[i + 2] = decrypt_table[table[i + 2] & 0xFF]; - table[i + 3] = decrypt_table[table[i + 3] & 0xFF]; + protected void set_table_data(byte table[], byte base_table[], int i) { + table[i] = base_table[table[i] & 0xFF]; + table[i + 1] = base_table[table[i + 1] & 0xFF]; + table[i + 2] = base_table[table[i + 2] & 0xFF]; + table[i + 3] = base_table[table[i + 3] & 0xFF]; } } diff --git a/src/crypt/Decrypter.java b/src/crypt/Decrypter.java index 475a224..64bb658 100644 --- a/src/crypt/Decrypter.java +++ b/src/crypt/Decrypter.java @@ -199,7 +199,7 @@ public class Decrypter extends DecryptUtils implements DataKeys { int read = filein.read(buffer); size -= read; for (int i = 0; i < read; i += 4) { - set_table_data(buffer, i); + set_table_data(buffer, decrypt_table, i); long alpha = get_table_value(buffer, i); long beta = getBeta(); long gamma = alpha ^ beta; diff --git a/src/crypt/KirkCypher.java b/src/crypt/KirkCypher.java index af05a61..59b9862 100644 --- a/src/crypt/KirkCypher.java +++ b/src/crypt/KirkCypher.java @@ -66,6 +66,7 @@ public class KirkCypher implements GameKeys { fd.read(byte_bt); fd.seek(0); System.out.println("Encrypting savedata (KIRK engine): " + byte_bt.length + " bytes"); + System.out.println("Gamekey: " + getHex(gamekey)); byte out[] = new CryptoEngine().EncryptSavedata(byte_bt, byte_bt.length, gamekey, 0); fd.write(out); fd.setLength(out.length); diff --git a/src/crypt/SavedataCypher.java b/src/crypt/SavedataCypher.java index 48a71ab..1630d09 100644 --- a/src/crypt/SavedataCypher.java +++ b/src/crypt/SavedataCypher.java @@ -73,19 +73,20 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys { private void decrypt_buffer(byte buffer[]) { int len = buffer.length - 4; byte seed[] = new byte[4]; - System.arraycopy(buffer, len, seed, 0, 4); + System.arraycopy(buffer, len, seed, 0, 4); + get_table_value(decrypt_table, seed); get_table_value(decrypt_table, seed); - get_table_value(decrypt_table, seed); long alpha = get_table_value(seed, 0); initSeed(alpha); for (int i = 0; i < len; i += 4) { - set_table_data(buffer, i); + set_table_data(buffer, decrypt_table, i); alpha = get_table_value(buffer, i); long beta = getBeta(); long gamma = alpha ^ beta; set_table_value(buffer, i, gamma); - set_table_data(buffer, i); + set_table_data(buffer, decrypt_table, i); } + System.arraycopy(seed, 0, buffer, len, 4); } public void encrypt(String file) { @@ -130,15 +131,19 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys { } int len = buffer.length - 4; byte seed[] = new byte[4]; - System.arraycopy(buffer, len, seed, 0, 4); + System.arraycopy(buffer, len, seed, 0, 4); long alpha = get_table_value(seed, 0); initSeed(alpha); - for (int i = 0; i < len; i += 4) { + for (int i = 0; i < len; i += 4) { + set_table_data(buffer, encrypt_table, i); long gamma = get_table_value(buffer, i); long beta = getBeta(); alpha = beta ^ gamma; set_table_value(buffer, i, alpha); - get_table_value(encrypt_table, buffer); + set_table_data(buffer, encrypt_table, i); } + get_table_value(encrypt_table, seed); + get_table_value(encrypt_table, seed); + System.arraycopy(seed, 0, buffer, len, 4); } }