public byte[] xtsBlockEncrypt(byte[] plain, int j) { byte[] pp = xor(plain, tTable[j]); aes.setKey(key1); byte[] cc = aes.encrypt(pp); byte[] cj = xor(cc, tTable[j]); return cj; }
public byte[] xtsBlockDecrypt(byte[] cipher, int j) { byte[] cc = xor(cipher, tTable[j]); aes.setKey(key1); byte[] pp = aes.decrypt(cc); byte[] pj = xor(pp, tTable[j]); return pj; }
public void start() { try { System.out.println(0x100); // key FileReader fr = new FileReader(k); BufferedReader buff = new BufferedReader(fr); String temp = buff.readLine(); key1 = temp.substring(0, 16).getBytes(); key2 = temp.substring(16, 32).getBytes(); aes.setKey(key2); String input = ""; // input fr = new FileReader(i); buff = new BufferedReader(fr); temp = buff.readLine(); if (temp != null) { input = temp; } while ((temp = buff.readLine()) != null) { input = input + "\r" + temp; } System.out.println(input); plain = input.getBytes(); plainBlock = new byte[(int) Math.ceil(plain.length / 16)][16]; for (int i = 0; i < plainBlock.length; i++) { System.arraycopy(plain, 16 * i, plainBlock[i], 0, 16); } for (int i = 0; i < plain.length; i++) { System.out.print(plain[i] + " "); } System.out.println(); for (int i = 0; i < plainBlock.length; i++) { for (int j = 0; j < plainBlock[i].length; j++) { System.out.print(plainBlock[i][j] + " "); } System.out.println(); } tTable = new byte[plainBlock.length][16]; tweakAfterEncrypt = aes.encrypt(tweak); fillTTable(); // output FileWriter fw = new FileWriter(o); BufferedWriter bw = new BufferedWriter(fw); for (int i = 0; i < plainBlock.length - 2; i++) { xtsBlockEncrypt(plain, i); } } catch (Exception e) { e.printStackTrace(); } }