The Cryptosystem

Khafre is another encryption system from Ralph Merkle and is very similar to one of his other cryptosystems known as Khufu, in that is consists of a 64 bit plaintext that is split into two 32 bit halves and then cycled through S-Boxes for a period of time,it but unlike Khufu, the S-Boxes used in Khafre are not computed as a part of the encryption process. Instead, Khafre selects its S-Boxes from a standard set. Using standard S-Boxes also means that some new mechanism of mixing in key material must be adopted because the standard S-boxes can not serve as the key. The workaround for this problem involves the key materials being XORed into the first 64 bits of the data block before the first encryption cycle, and every 8 cycles afterwards. This does mean, however, that all key lengths for Khafre have to be a multiple of 64. Below is the pseudocode for the Khafre system

```   L, R: int32;
standardSBoxes: ARRAY {1 .. enough/8} OF ARRAY {0 .. 255} OF int32;
key: ARRAY {0 .. enoughKey-1} OF ARRAY {0 .. 1} of int32:
keyIndex: {0 .. enoughKey-1};
rotateSchedule: ARRAY {1 .. 8} := {16,16,8,8,16,16,24,24};

L := L XOR key{0}{0};
R := R XOR key{0}{1};
keyIndex := 1 MOD enoughKey;
round := 1;
octet := 1;
WHILE (round <= enough) DO
Begin
L := L XOR standardSBoxesoctet {R AND #FF};
R := RotateRight{R, rotateSchedule{round mod 8 + 1}};
SWAP{L,R};
IF round MOD 8 = 0 THEN
BEGIN
L := L XOR RotateRight{ key{keyIndex}{0}, octet};
R := R XOR RotateRight{ key{keyIndex}{1}, octet};
keyIndex := keyIndex + 1;
IF keyIndex = enoughKey THEN keyIndex := 0;
octet := octet + 1;
END;
round := round + 1;
End;
IF keyIndex # 0 THEN ERROR;```
Code taken from A Software Encryption Function by Ralph C. Merkle,
(available at http://www.cryptocd.org/cryptocd/source/cyphers/khufu/c/merkle/1.txt)

Khafre requires more cycles of encryption to approach the level of security offered by Khufu due to its use of standard S-Boxes, and due to its more complex key inclusion method, each cycle takes more computation, but the fact that Khafre doesn't used computational power to create custom S-Boxes, it runs faster for small amounts of plaintext.

The Person

Khafre (also known as Rakhaef or Chephren) was the son of Khufu(better known as Cheops), and ruled from 2520 - 2494 BC. He was responsible for the creation of the second largest pyramid complex at Giza, and also as the pharoh under whom the Sphinx was created. His reign was succeeded by an, as yet, unknown king.