//Decrypt a ciphertext using a key and the 4 round SPN public static BitString16 Decrypt(BitString16 ciphertext, Key key) { SBox sbox = new SBox(); //Pre BitString16 first_subkey = key.getDecryptionSubKey(1); BitString16 plaintext = Util.xor(ciphertext, first_subkey); //Round 1 BitString16 second_subkey = key.getDecryptionSubKey(2); plaintext = sbox.backwardsTransform(plaintext); plaintext = Util.xor(plaintext, second_subkey); //Rounds 2-4 for (int round = 2; round < 5; ++round) { BitString16 subkey = key.getDecryptionSubKey(round + 1); plaintext = Permutation.backwardsPermutation(plaintext); plaintext = sbox.backwardsTransform(plaintext); plaintext = Util.xor(plaintext, subkey); } return(plaintext); }
static BitString16 partial_decrypt(BitString16 ciphertext, BitString16 key) { SBox sbox = new SBox(); //Pre BitString16 plaintext = Util.xor(ciphertext, key); //Round 1 plaintext = sbox.backwardsTransform(plaintext); return(plaintext); }
static BitString16 partial_decrypt(BitString16 ciphertext, BitString16 key) { SBox sbox = new SBox(); //Pre BitString16 plaintext = Util.xor(ciphertext, key); //Round 1 plaintext = sbox.backwardsTransform(plaintext); return plaintext; }
//Decrypt a ciphertext using a key and the 4 round SPN public static BitString16 Decrypt(BitString16 ciphertext, Key key) { SBox sbox = new SBox(); //Pre BitString16 first_subkey = key.getDecryptionSubKey(1); BitString16 plaintext = Util.xor(ciphertext, first_subkey); //Round 1 BitString16 second_subkey = key.getDecryptionSubKey(2); plaintext = sbox.backwardsTransform(plaintext); plaintext = Util.xor(plaintext, second_subkey); //Rounds 2-4 for (int round = 2; round < 5; ++round) { BitString16 subkey = key.getDecryptionSubKey(round + 1); plaintext = Permutation.backwardsPermutation(plaintext); plaintext = sbox.backwardsTransform(plaintext); plaintext = Util.xor(plaintext, subkey); } return plaintext; }