The code has been written to be the simplest code to illustrate the failure of CBC-MAC upon CBC. The block cipher used is a toy which permutes the set of 8 bit values as DES permutes the set of 64 bit values. PC[x] yields the encryption of x and CP[y] is the decryption of y. Routine CBCc performs classic CBC encryption on the first argument setting the result into the second argument and also returns the last cipher block value for convenience of MAC. Routine CBCd performs the CBC decryption. Routine pct prints ciphertext.

The rest is an illustration of Mallet corrupting the text without getting caught. When I run the code I get the following output:

C4 9B 2E 76 74 0F 5B E7 97 70 74 26 15 5F 6D C1 56 BB CF 0D  is good
CC 9B 2E 76 74 0F 5B E7 97 70 74 26 15 5F 6D C1 56 BB CF 0D  is corrupted
CC 9B 2E 76 74 0F 5B E7 97 70 74 26 15 5F 6D C1 56 BB CF 0D  is reciphered
MAC = 29, MACp = 29
The MAC is good!
Transmitted string = "-irget of corruption"
You may get other values due to vagaries of the rand function.