Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 177,068 Bytes
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
:: Formalization of the Advanced Encryption Standard -- Part {I}
::  by Kenichi Arai and Hiroyuki Okazaki

environ

 vocabularies AESCIP_1, DESCIP_1, TARSKI, XBOOLE_0, FINSEQ_1, RELAT_1, FUNCT_1,
      ARYTM_1, FUNCT_2, FINSEQ_2, NAT_1, MARGREL1, ZFMISC_1, SUBSET_1, NUMBERS,
      INT_1, CARD_1, JORDAN3, XXREAL_0, ARYTM_3, ORDINAL4, FINSEQ_5, XCMPLX_0;
 notations TARSKI, XBOOLE_0, ZFMISC_1, SUBSET_1, RELAT_1, FUNCT_1, ORDINAL1,
      RELSET_1, PARTFUN1, FUNCT_2, BINOP_1, CARD_1, NUMBERS, XCMPLX_0,
      XXREAL_0, NAT_1, INT_1, NAT_D, FINSEQ_1, FINSEQ_2, MARGREL1, FINSEQ_4,
      FINSEQ_6, DESCIP_1;
 constructors RELSET_1, FINSEQ_4, NAT_D, FINSEQ_6, DESCIP_1, BINOP_1;
 registrations FINSEQ_1, RELSET_1, FINSEQ_2, FUNCT_2, ORDINAL1, MARGREL1,
      INT_1, NAT_1, XXREAL_0, XBOOLE_0, FUNCT_1, XREAL_0, FINSEQ_4;
 requirements BOOLE, SUBSET, NUMERALS, ARITHM, REAL;
 equalities FINSEQ_1, FINSEQ_2;
 theorems TARSKI, FUNCT_1, FUNCT_2, XXREAL_0, XREAL_1, FINSEQ_6, XREAL_0,
      NAT_1, INT_1, FINSEQ_1, CARD_1, BINOP_1, NAT_D, FINSEQ_2, FINSEQ_4,
      RFINSEQ, FINSEQ_5, XBOOLE_0, ORDINAL1, DESCIP_1, MARGREL1, NAT_2,
      WSIERP_1, XCMPLX_1, FINSEQ_3;
 schemes FUNCT_2, FINSEQ_1, NAT_1, BINOP_1, RECDEF_1;

begin :: Preliminaries

theorem XLMOD02:
  for k,m be Nat st m <> 0 & (k+1) mod m <> 0
  holds (k+1) mod m = (k mod m)+1
proof
  let k,m be Nat;
  assume
C1: m <> 0 & (k+1) mod m <> 0;
  (k mod m)+1 <= m by NAT_D:1,C1,NAT_1:13;
  then
P1: (k mod m)+1-1 <= m-1 by XREAL_1:9;
P2: (k+1) mod m = ((k mod m)+1) mod m by NAT_D:22;
  k mod m < m-1
  proof
    assume not k mod m < m-1;
    then (k+1) mod m = (m-1+1) mod m by XXREAL_0:1,P1,P2
      .= 0 by INT_1:50;
    hence contradiction by C1;
  end;
  then (k mod m)+1 < m-1+1 by XREAL_1:8;
  hence (k+1) mod m = (k mod m)+1 by NAT_D:24,P2;
end;

theorem XLMOD01:
  for k,m be Nat st m <> 0 & (k+1) mod m <> 0 holds (k+1) div m = k div m
proof
  let k,m be Nat;
  assume
C1: m <> 0 & (k+1) mod m <> 0;
  k+1 = ((k+1) div m )*m+((k+1) mod m) by INT_1:59,C1
    .= ((k+1) div m )*m+((k mod m)+1) by XLMOD02,C1;
  then
P1: ((k+1) div m)*m+(k mod m)-(k mod m) = (k div m )*m+(k mod m)-(k mod m)
  by INT_1:59,C1;
  thus ((k+1) div m) = (k div m)*m / m by XCMPLX_1:89,C1,P1
    .= (k div m) by XCMPLX_1:89,C1;
end;

theorem XLMOD02X:
  for k,m be Nat st m <> 0 & (k+1) mod m = 0 holds m-1 = (k mod m)
proof
  let k,m be Nat;
  assume
C1: m <> 0 & (k+1) mod m = 0;
  then (k mod m)+1 <= m by NAT_D:1,NAT_1:13;
  then
P1: (k mod m)+1-1 <= m-1 by XREAL_1:9;
P2: (k+1) mod m = ((k mod m)+1) mod m by NAT_D:22;
  assume not k mod m = m-1;
  then k mod m < m-1 by XXREAL_0:1,P1;
  then k mod m+1 < m-1+1 by XREAL_1:8;
  hence contradiction by P2,NAT_D:24,C1;
end;

theorem XLMOD01X:
  for k,m be Nat st m <> 0 & (k+1) mod m = 0
  holds (k+1) div m = (k div m)+1
proof
  let k,m be Nat;
  assume
C1: m <> 0 & (k+1) mod m = 0;
  then
P3: k mod m = m-1 by XLMOD02X;
P4: k+1 = ((k+1) div m)*m+((k+1) mod m) by INT_1:59,C1
    .= ((k+1) div m)*m by C1;
P5: k = (k div m )*m+(k mod m) by INT_1:59,C1
    .= (k div m)*m+m-1 by P3;
  thus ((k+1) div m) = ((k div m)+1)*m / m by XCMPLX_1:89,C1,P4,P5
    .= ((k div m)+1) by XCMPLX_1:89,C1;
end;

theorem XLMOD03:
  for k,m be Nat holds (k-m) mod m = k mod m
proof
  let k,m be Nat;
  thus (k-m) mod m = (k+m*(-1)) mod m
    .= k mod m by NAT_D:61;
end;

theorem XLMOD04:
  for k,m be Nat st m <> 0 holds (k-m) div m = (k div m)-1
proof
  let k,m be Nat;
  assume
AS: m <> 0;
  thus (k-m) div m = (k+m*(-1)) div m
    .= (k div m)+-1 by AS,NAT_D:61
    .= (k div m)-1;
end;

definition
  let m,n be Nat, X,D be non empty set;
  let F be Function of X, m-tuples_on(n-tuples_on D);
  let x be Element of X;
  redefine func F.x -> Element of m-tuples_on(n-tuples_on D);
  coherence
  proof
    F.x in m-tuples_on(n-tuples_on D);
    hence thesis;
  end;
end;

definition
  let m be Nat, X,Y,D be non empty set;
  let F be Function of [:X,Y:], m-tuples_on D;
  let x be Element of X,y be Element of Y;
  redefine func F.(x,y) -> Element of m-tuples_on D;
  coherence
  proof
    F.(x,y) in m-tuples_on D;
    hence thesis;
  end;
end;

theorem LM01:
  for m,n be Nat, D be non empty set,
  F1,F2 be Element of m-tuples_on (n-tuples_on D) st for i,j be Nat
  st i in Seg m & j in Seg n
  holds (F1.i).j = (F2.i).j holds F1 = F2
  proof
    let m,n be Nat, D be non empty set,
    F1,F2 be Element of m-tuples_on (n-tuples_on D);
    assume
AS: for i,j be Nat st i in Seg m & j in Seg n
    holds (F1.i).j = (F2.i).j;
    F1 in m-tuples_on (n-tuples_on D);
    then
P1: ex s be Element of (n-tuples_on D)* st F1 = s & len s = m;
    F2 in m-tuples_on (n-tuples_on D);
    then
P2: ex s be Element of (n-tuples_on D)* st F2 = s & len s = m;
    now let i be Nat;
      assume 1 <= i & i <= len F1;
      then
P4:   i in Seg m by P1;
      then i in dom F1 by FINSEQ_1:def 3,P1;
      then F1.i in rng F1 by FUNCT_1:3;
      then F1.i in n-tuples_on D;
      then
P6:   ex s be Element of D* st F1.i = s & len s = n;
      then reconsider F1i = F1.i as Element of D*;
      i in dom F2 by FINSEQ_1:def 3,P2,P4;
      then F2.i in rng F2 by FUNCT_1:3;
      then F2.i in n-tuples_on D;
      then
R6:   ex s be Element of D* st F2.i = s & len s = n;
      then reconsider F2i = F2.i as Element of D*;
      now let j be Nat;
      assume 1 <= j & j <= len F1i;
      then j in Seg n by P6;
      hence F1i.j = F2i.j by AS,P4;
    end;
    hence
    F1.i = F2.i by P6,R6,FINSEQ_1:14;
  end;
  hence F1 = F2 by P1,P2,FINSEQ_1:14;
end;

theorem LMGSEQ4:
  for D be non empty set, x1,x2,x3,x4 be Element of D
  holds <* x1,x2,x3,x4 *> is Element of (4-tuples_on D)
proof
  let D be non empty set, x1,x2,x3,x4 be Element of D;
  reconsider x1234 = <* x1,x2,x3,x4 *> as FinSequence of D;
P1: len x1234 = 4 by FINSEQ_4:76;
  x1234 in D* by FINSEQ_1:def 11;
  then x1234 in 4-tuples_on D by P1;
  hence thesis;
end;

theorem LMGSEQ5:
  for D be non empty set,x1,x2,x3,x4,x5 be Element of D
  holds <* x1,x2,x3,x4,x5 *> is Element of (5-tuples_on D)
proof
  let D be non empty set, x1,x2,x3,x4,x5 be Element of D;
  reconsider x12345 = <* x1,x2,x3,x4,x5 *> as FinSequence of D;
P1: len x12345 = 5 by FINSEQ_4:78;
  x12345 in D* by FINSEQ_1:def 11;
  then x12345 in 5-tuples_on D by P1;
  hence thesis;
end;

theorem
  for D be non empty set, x1,x2,x3,x4,x5,x6,x7,x8 be Element of D
  holds <* x1,x2,x3,x4 *>^<* x5,x6,x7,x8 *> is Element of (8-tuples_on D)
proof
  let D be non empty set,x1,x2,x3,x4,x5,x6,x7,x8 be Element of D;
  reconsider x1234 = <* x1,x2,x3,x4 *> as Element of 4-tuples_on D
  by LMGSEQ4;
  reconsider x5678 = <* x5,x6,x7,x8 *> as Element of 4-tuples_on D
  by LMGSEQ4;
  D c= D;
  hence thesis by FINSEQ_2:109;
end;

theorem LMGSEQ10:
  for D be non empty set, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 be Element of D
  holds <* x1,x2,x3,x4,x5 *>^<* x6,x7,x8,x9,x10 *> is
  Element of (10-tuples_on D)
proof
  let D be non empty set, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 be Element of D;
  reconsider x12345 = <* x1,x2,x3,x4,x5 *> as Element of 5-tuples_on D
  by LMGSEQ5;
  reconsider x67890 = <* x6,x7,x8,x9,x10 *> as Element of 5-tuples_on D
  by LMGSEQ5;
  D c= D;
  hence thesis by FINSEQ_2:109;
end;

theorem LMGSEQ16:
  for D be non empty set, x1,x2,x3,x4,x5,x6,x7,x8 be Element of (4-tuples_on D)
  holds <* x1^x5,x2^x6,x3^x7,x4^x8 *> is
  Element of 4-tuples_on (8-tuples_on D)
proof
  let D be non empty set,
  x1,x2,x3,x4,x5,x6,x7,x8 be Element of (4-tuples_on D);
X1: D c= D;
  then
P1: x1^x5 is Element of 8-tuples_on D by FINSEQ_2:109;
P2: x2^x6 is Element of 8-tuples_on D by X1,FINSEQ_2:109;
P3: x3^x7 is Element of 8-tuples_on D by X1,FINSEQ_2:109;
  x4^x8 is Element of 8-tuples_on D by X1,FINSEQ_2:109;
  hence thesis by P1,P2,P3,LMGSEQ4;
end;

theorem
  for D be non empty set, x be Element of 4-tuples_on(4-tuples_on D),
  k be Element of NAT st k in Seg 4 holds
  ex x1,x2,x3,x4 be Element of D st x1 = (x.k).1 & x2 = (x.k).2 &
  x3 = (x.k).3 & x4 = (x.k).4
proof
  let D be non empty set, x be Element of 4-tuples_on(4-tuples_on D),
  k be Element of NAT;
  assume
AS: k in Seg 4;
  x in 4-tuples_on(4-tuples_on D);
  then ex s be Element of (4-tuples_on D)* st x = s & len s = 4;
  then k in dom x by AS,FINSEQ_1:def 3;
  then x.k in rng x by FUNCT_1:3;
  then x.k in 4-tuples_on (D);
  then
Q13: ex s be Element of D* st x.k = s & len s = 4;
  then reconsider xk = x.k as Element of D*;
  1 in Seg 4;
  then 1 in dom xk by Q13,FINSEQ_1:def 3;
  then xk.1 in rng xk by FUNCT_1:3;
  then reconsider x1 = xk.1 as Element of D;
  2 in Seg 4;
  then 2 in dom xk by Q13,FINSEQ_1:def 3;
  then xk.2 in rng xk by FUNCT_1:3;
  then reconsider x2 = xk.2 as Element of D;
  3 in Seg 4;
  then 3 in dom xk by Q13,FINSEQ_1:def 3;
  then xk.3 in rng xk by FUNCT_1:3;
  then reconsider x3 = xk.3 as Element of D;
  4 in Seg 4;
  then 4 in dom xk by Q13,FINSEQ_1:def 3;
  then xk.4 in rng xk by FUNCT_1:3;
  then reconsider x4 = xk.4 as Element of D;
  take x1,x2,x3,x4;
  thus thesis;
end;

theorem INV00:
  for X,Y be non empty set, f be Function of X,Y, g be Function of Y,X
  st (for x be Element of X holds g.(f.x) = x) &
  (for y be Element of Y holds f.(g.y) = y)
  holds f is one-to-one & f is onto & g is one-to-one & g is onto &
  g = f" & f = g"
proof
  let X,Y be non empty set, f be Function of X,Y, g be Function of Y,X;
  assume
A1: for x be Element of X holds g.(f.x) = x;
  assume
A2: for y be Element of Y holds f.(g.y) = y;
  now let x be Element of X;
    thus (g*f).x = g.(f.x) by FUNCT_2:15
      .= x by A1;
  end;
  then
P2: g*f = id X by FUNCT_2:124;
  now let y be Element of Y;
    thus (f*g).y = f.(g.y) by FUNCT_2:15
      .= y by A2;
  end;
  then
P4: f*g = id Y by FUNCT_2:124;
  thus
P5: f is one-to-one & f is onto by P2,P4,FUNCT_2:23;
  thus
P6: g is one-to-one & g is onto by P2,P4,FUNCT_2:23;
  rng f = Y by P5,FUNCT_2:def 3;
  hence g = f" by FUNCT_2:30,P2,FUNCT_2:23;
  rng g = X by P6,FUNCT_2:def 3;
  hence f = g" by FUNCT_2:30,P4,FUNCT_2:23;
end;

begin :: State array

definition
  func AES-Statearray -> Function of 128-tuples_on BOOLEAN,
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefStatearray:
  for input be Element of 128-tuples_on BOOLEAN
  for i,j be Nat st i in Seg 4 & j in Seg 4
  holds ((it.input).i).j = mid (input,1+(i-'1)*8+(j-'1)*32,
  1+(i-'1)*8+(j-'1)*32+7);
  existence
  proof
    defpred P0[Element of 128-tuples_on BOOLEAN,set] means
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st $2 = z & for i,j be Nat st i in Seg 4 & j in Seg 4
    holds (z.i).j = mid ($1,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7);
A1: for x being Element of 128-tuples_on BOOLEAN
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[x,z]
    proof
      let x be Element of 128-tuples_on BOOLEAN;
      x in 128-tuples_on BOOLEAN;
      then
A01:  ex s be Element of (BOOLEAN)* st x = s & len s = 128;
      defpred P[Nat,set] means
      ex zi be Element of (4-tuples_on (8-tuples_on BOOLEAN))
      st $2 = zi & for j be Nat st j in Seg 4
      holds zi.j = mid (x,1+($1-'1)*8+(j-'1)*32,1+($1-'1)*8+(j-'1)*32+7);
Q1:   for k be Nat st k in Seg 4
      ex x being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,x]
      proof
        let k be Nat;
        assume k in Seg 4;
        then
Q110:   1 <= k & k <= 4 by FINSEQ_1:1;
        then 1-1 <= k-1 by XREAL_1:9;
        then k-'1 = k-1 by XREAL_0:def 2;
        then k-'1 <= 4-1 by Q110,XREAL_1:9;
        then
Q112:   (k-'1)*8 <= 3*8 by XREAL_1:64;
        defpred Pi[Nat,set] means
        $2 = mid (x,1+(k-'1)*8+($1-'1)*32,1+(k-'1)*8+($1-'1)*32+7);
Q12:    for j be Nat st j in Seg 4
        ex xi being Element of (8-tuples_on BOOLEAN) st Pi[j,xi]
        proof
          let j be Nat;
          assume j in Seg 4;
          then
Q130:     1 <= j & j <= 4 by FINSEQ_1:1;
          then 1-1 <= j-1 by XREAL_1:9;
          then j-'1 = j-1 by XREAL_0:def 2;
          then j-'1 <= 4-1 by Q130,XREAL_1:9;
          then
Q133:     (j-'1)*32 <= 3*32 by XREAL_1:64;
          (k-'1)*8+(j-'1)*32 <= 24+96 by Q133,Q112,XREAL_1:7;
          then
Q134:     1+((k-'1)*8+(j-'1)*32) <= 1+120 by XREAL_1:7;
Q136:     (1+(k-'1)*8+(j-'1)*32)+7 <= 121+7 by Q134,XREAL_1:7;
          1+0 <= 1+((k-'1)*8+(j-'1)*32) by XREAL_1:7;
          then
Q14:      1 <= 1+(k-'1)*8+(j-'1)*32 & 1+(k-'1)*8+(j-'1)*32 <= len x
          by Q134,XXREAL_0:2,A01;
Q150:     1+0 <= 1+(k-'1)*8+(j-'1)*32+7 by XREAL_1:7;
          reconsider mmd = mid (x,1+(k-'1)*8+(j-'1)*32,
          1+(k-'1)*8+(j-'1)*32+7) as Element of (BOOLEAN)* by FINSEQ_1:def 11;
          1+(k-'1)*8+(j-'1)*32+0 <= 1+(k-'1)*8+(j-'1)*32+7 by XREAL_1:6;
          then len mid (x,1+(k-'1)*8+(j-'1)*32,1+(k-'1)*8+(j-'1)*32+7) =
          (1+(k-'1)*8+(j-'1)*32+7)-'(1+(k-'1)*8+(j-'1)*32)+1
          by FINSEQ_6:118,Q14,Q136,A01,Q150
            .= 7+1 by NAT_D:34
            .= 8;
          then mmd in (8-tuples_on BOOLEAN);
          then reconsider xi = mid (x,1+(k-'1)*8+(j-'1)*32,
          1+(k-'1)*8+(j-'1)*32+7) as Element of (8-tuples_on BOOLEAN);
          xi = mid (x,1+(k-'1)*8+(j-'1)*32,1+(k-'1)*8+(j-'1)*32+7);
          hence thesis;
        end;
        consider zi be FinSequence of (8-tuples_on BOOLEAN) such that
Q13:    dom zi = Seg 4 & for i be Nat st i in Seg 4
        holds Pi[i,zi.i] from FINSEQ_1:sch 5(Q12);
Q14:    len zi = 4 by Q13,FINSEQ_1:def 3;
        reconsider zi as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zi in 4-tuples_on (8-tuples_on BOOLEAN) by Q14;
        then reconsider zi as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        for j be Nat st j in Seg 4
        holds zi.j = mid (x,1+(k-'1)*8+(j-'1)*32,1+(k-'1)*8+(j-'1)*32+7)
        by Q13;
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 &
      for i be Nat st i in Seg 4 holds P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))by Q3;
      then reconsider z as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      for i,j be Nat st i in Seg 4 & j in Seg 4
      holds (z.i).j = mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)
      proof
        let i,j be Nat;
        assume
P11:    i in Seg 4 & j in Seg 4;
        then consider zi be Element of (4-tuples_on (8-tuples_on BOOLEAN))
        such that
P12:    z.i = zi & for j be Nat st j in Seg 4
        holds zi.j = mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7) by Q2;
        thus (z.i).j = mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)
        by P11,P12;
      end;
      hence ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      st P0[x,z];
    end;
    consider I be Function of 128-tuples_on BOOLEAN,
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x being Element of 128-tuples_on BOOLEAN
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    now let input be Element of 128-tuples_on BOOLEAN;
      ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      st I.input = z & for i,j be Nat st i in Seg 4 & j in Seg 4
      holds (z.i).j = mid (input,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)
      by A2;
      hence for i,j be Nat st i in Seg 4 & j in Seg 4
      holds ((I.input).i).j = mid (input,1+(i-'1)*8+(j-'1)*32,
      1+(i-'1)*8+(j-'1)*32+7);
    end;
    hence thesis;
  end;
  uniqueness
  proof
    let H1,H2 be Function of 128-tuples_on BOOLEAN,
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for input be Element of 128-tuples_on BOOLEAN
    for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ((H1.input).i).j = mid (input,1+(i-'1)*8+(j-'1)*32,
    1+(i-'1)*8+(j-'1)*32+7);
    assume
A2: for input be Element of 128-tuples_on BOOLEAN
    for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ((H2.input).i).j = mid (input,1+(i-'1)*8+(j-'1)*32,
    1+(i-'1)*8+(j-'1)*32+7);
    now let input be Element of 128-tuples_on BOOLEAN;
      (H1.input) in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P3:   ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st (H1.input) = s & len s = 4;
      (H2.input) in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P4:   ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st (H2.input) = s & len s = 4;
      now let i be Nat;
        assume 1 <=i & i <= len (H1.input);
        then
P6:     i in Seg 4 by P3;
        then i in dom(H1.input) by FINSEQ_1:def 3,P3;
        then (H1.input).i in rng (H1.input) by FUNCT_1:3;
        then (H1.input).i in 4-tuples_on (8-tuples_on BOOLEAN);
        then
P8:     ex s be Element of (8-tuples_on BOOLEAN)*
        st (H1.input).i = s & len s = 4;
        reconsider H1i = (H1.input).i as
        Element of (8-tuples_on BOOLEAN)* by P8;
        i in dom(H2.input) by FINSEQ_1:def 3,P4,P6;
        then (H2.input).i in rng (H2.input) by FUNCT_1:3;
        then (H2.input).i in 4-tuples_on (8-tuples_on BOOLEAN);
        then
P11:    ex s be Element of (8-tuples_on BOOLEAN)*
        st (H2.input).i = s & len s = 4;
        reconsider H2i = (H2.input).i as
        Element of (8-tuples_on BOOLEAN)* by P11;
        now let j be Nat;
          assume 1 <=j & j <= len H1i;
          then
P14:      j in Seg 4 by P8;
          then ((H1.input).i).j = mid (input,1+(i-'1)*8+(j-'1)*32,
          1+(i-'1)*8+(j-'1)*32+7) by A1,P6;
          hence H1i.j = H2i.j by A2,P6,P14;
        end;
        hence (H1.input).i = (H2.input).i by P8,P11,FINSEQ_1:def 17;
      end;
      hence H1.input = H2.input by P3,P4,FINSEQ_1:def 17;
    end;
    hence H1 = H2 by FUNCT_2:63;
  end;
end;

theorem LMStat0:
  for k be Nat st 1 <= k & k <= 128 ex i,j be Nat st i in Seg 4 & j in Seg 4 &
  1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7
proof
  let k be Nat;
  assume
A1: 1 <= k & k <= 128;
A3: k = 32*(k div 32)+(k mod 32) by NAT_D:2;
  reconsider m = k div 32 as Nat;
  reconsider n = k mod 32 as Nat;
  k div 32 <= (32*4) div 32 by A1,NAT_2:24;
  then
M1: m <= 4 by NAT_D:18;
  per cases;
  suppose
A4: n = 0;
A5: 1 <= m
    proof
      assume not 1 <= m;
      then m = 0 by NAT_1:14;
      hence contradiction by A1,A3,A4;
    end;
    set j = m;
A8: j in Seg 4 by M1,A5;
    set i = 4;
A10: i in Seg 4;
A11: j-'1 = j-1 by XREAL_1:233,A5;
A13: k = 32*(k div 32)+(k mod 32) by NAT_D:2
      .= 32*(j-'1)+8*((i-1)+1) by A4,A11
      .= 32*(j-'1)+8*((i-'1)+1) by XREAL_1:233
      .= 1+(i-'1)*8+(j-'1)*32+7;
    1+(i-'1)*8+(j-'1)*32+0 <= 1+(i-'1)*8+(j-'1)*32+7 by XREAL_1:7;
    hence ex i,j be Nat st i in Seg 4 & j in Seg 4 &
    1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7 by A8,A10,A13;
  end;
  suppose
A14: n <> 0;
    then
XX0: 1 <= n by NAT_1:14;
XX1: n <= 32 by NAT_D:1;
    m <> 4
    proof
      assume
U1:   m = 4;
U2:   k = 32*4+n by NAT_D:2,U1
        .= 128+n;
      128+1 <= 128+n by XX0,XREAL_1:7;
      hence contradiction by U2,XXREAL_0:2,A1;
    end;
    then m < 4 by XXREAL_0:1,M1;
    then
A15: m+1 <= 4 by NAT_1:13;
A16: 1 <= m+1 by NAT_1:11;
    set j = m+1;
A18: j in Seg 4 by A15,A16;
A19: j-'1 = j-1 by XREAL_1:233,NAT_1:11
      .=m;
A20: k = 32*(j-'1)+n by NAT_D:2,A19;
A22: n = 8*(n div 8)+(n mod 8) by NAT_D:2;
    reconsider s = n div 8 as Nat;
    reconsider t = n mod 8 as Nat;
    n div 8 <= (8*4) div 8 by XX1,NAT_2:24;
    then
M2: n div 8 <= 4 by NAT_D:18;
    now per cases;
    suppose
A23:  t = 0;
A24:  1 <= s
      proof
        assume not 1 <= s;
        then n = 8*0+0 by NAT_1:14,A22,A23;
        hence contradiction by A14;
      end;
      set i = s;
A28:  i in Seg 4 by M2,A24;
A29:  i-'1 = i-1 by XREAL_1:233,A24;
A30:  n = 8*s+0 by NAT_D:2,A23
        .= 8*(i-'1)+8*1 by A29;
      1+(i-'1)*8+(j-'1)*32+0 <= 1+(i-'1)*8+(j-'1)*32+7 by XREAL_1:7;
      hence ex i,j be Nat st i in Seg 4 & j in Seg 4 &
      1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7
      by A28,A18,A20,A30;
    end;
    suppose
      t <> 0;
      then
XX0:  1 <= t by NAT_1:14;
XXX1: t <= 8 by NAT_D:1;
      s <> 4
      proof
        assume
U1:     s = 4;
U2:     n = 8*4+t by NAT_D:2,U1
          .= 32+t;
        32+1 <= 32+t by XX0,XREAL_1:7;
        hence contradiction by U2,XXREAL_0:2,XX1;
      end;
      then s < 4 by XXREAL_0:1,M2;
      then
B15:  s+1 <= 4 by NAT_1:13;
B16:  1 <= s+1 by NAT_1:11;
      set i = s+1;
B18:  i in Seg 4 by B15,B16;
B19:  i-'1 = i-1 by XREAL_1:233,NAT_1:11
        .=s;
B20:  n = 8*(i-'1)+t by NAT_D:2,B19;
B220: 32*(j-'1)+8*(i-'1)+1 <= 32*(j-'1)+8*(i-'1)+t by XX0,XREAL_1:7;
      32*(j-'1)+8*(i-'1)+t <= 32*(j-'1)+8*(i-'1)+8 by XXX1,XREAL_1:7;
      then k <= 1+8*(i-'1)+32*(j-'1)+7 by A20,B20;
      hence ex i,j be Nat st i in Seg 4 & j in Seg 4 &
      1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7
      by B220,A20,B20,B18,A18;
    end;
  end;
  hence ex i,j be Nat st i in Seg 4 & j in Seg 4 & 1+(i-'1)*8+(j-'1)*32 <= k &
  k <= 1+(i-'1)*8+(j-'1)*32+7;
end;
end;

theorem LMStat2A:
  for i,j,i0,j0 be Nat st i in Seg 4 & j in Seg 4 & i0 in Seg 4 &
  j0 in Seg 4 & not (i = i0 & j = j0)
  holds {k where k is Nat : 1+(i-'1)*8+(j-'1)*32 <= k &
  k <= 8+(i-'1)*8+(j-'1)*32} /\ {k where k is Nat :
  1+(i0-'1)*8+(j0-'1)*32 <= k & k <= 8+(i0-'1)*8+(j0-'1)*32} = {}
proof
  let i,j,i0,j0 be Nat;
  assume
AS: i in Seg 4 & j in Seg 4 & i0 in Seg 4 &
  j0 in Seg 4 & not (i = i0 & j = j0);
  set A = {k where k is Nat : 1+(i-'1)*8+(j-'1)*32 <= k &
  k <= 8+(i-'1)*8+(j-'1)*32};
  set B = {k where k is Nat : 1+(i0-'1)*8+(j0-'1)*32 <= k &
  k <= 8+(i0-'1)*8+(j0-'1)*32};
A1: 1 <= j & j <= 4 by AS,FINSEQ_1:1;
A2: 1 <= i & i <= 4 by AS,FINSEQ_1:1;
B1: 1 <= j0 & j0 <= 4 by AS,FINSEQ_1:1;
B2: 1 <= i0 & i0 <= 4 by AS,FINSEQ_1:1;
P1: (j-'1) = j-1 by XREAL_1:233,A1;
P2: (i-'1) = i-1 by XREAL_1:233,A2;
P3: (j0-'1) = j0-1 by XREAL_1:233,B1;
P4: (i0-'1) = i0-1 by XREAL_1:233,B2;
  i-1 <= 4-1 by A2,XREAL_1:9;
  then
R2: i-'1 <= 3 by XREAL_1:233,A2;
  i0-1 <= 4-1 by B2,XREAL_1:9;
  then
R4: i0-'1 <= 3 by XREAL_1:233,B2;
  per cases;
  suppose
A2: j <> j0;
    now per cases by A2,XXREAL_0:1;
    suppose
      j < j0;
      then (j-'1) < (j0-'1) by XREAL_1:14,P1,P3;
      then (j-'1)+1 <= (j0-'1) by NAT_1:13;
      then
A12:  ((j-'1)+1)*32 <= (j0-'1)*32 by XREAL_1:64;
      (i-'1)*8 <= 3*8 by R2,XREAL_1:64;
      then 8+(i-'1)*8 <= 8+24 by XREAL_1:6;
      then 8+(i-'1)*8+(j-'1)*32 <= 32+(j-'1)*32 by XREAL_1:6;
      then
A13:  8+(i-'1)*8+(j-'1)*32 <= (j0-'1)*32 by A12,XXREAL_0:2;
      0+(j0-'1)*32 <= (i0-'1)*8+(j0-'1)*32 by XREAL_1:6;
      then (j0-'1)*32+0 < (i0-'1)*8+(j0-'1)*32+1 by XREAL_1:8;
      then
A14:  8+(i-'1)*8+(j-'1)*32 < 1+(i0-'1)*8+(j0-'1)*32 by A13,XXREAL_0:2;
      thus A /\ B = {}
      proof
        assume A /\ B <> {};
        then consider x be object such that
A150:   x in A /\ B by XBOOLE_0:def 1;
A15:    x in A & x in B by XBOOLE_0:def 4,A150;
        consider k1 be Nat such that
A16:    x = k1 & 1+(i-'1)*8+(j-'1)*32 <= k1 & k1 <= 8+(i-'1)*8+(j-'1)*32
        by A15;
        consider k2 be Nat such that
A17:    x = k2 & 1+(i0-'1)*8+(j0-'1)*32 <= k2 & k2 <= 8+(i0-'1)*8+(j0-'1)*32
        by A15;
        reconsider x as Nat by A16;
        thus contradiction by A17,A14,XXREAL_0:2,A16;
      end;
    end;
    suppose
      j0 < j;
      then (j0-'1) < (j-'1) by XREAL_1:14,P1,P3;
      then (j0-'1)+1 <= (j-'1) by NAT_1:13;
      then
A12:  ((j0-'1)+1)*32 <= (j-'1)*32 by XREAL_1:64;
      (i0-'1)*8 <= 3*8 by R4,XREAL_1:64;
      then 8+(i0-'1)*8 <= 8+24 by XREAL_1:6;
      then 8+(i0-'1)*8+(j0-'1)*32 <= 32+(j0-'1)*32 by XREAL_1:6;
      then
A13:  8+(i0-'1)*8+(j0-'1)*32 <= (j-'1)*32 by A12,XXREAL_0:2;
      0+(j-'1)*32 <= (i-'1)*8+(j-'1)*32 by XREAL_1:6;
      then (j-'1)*32+0 < (i-'1)*8+(j-'1)*32+1 by XREAL_1:8;
      then
A14:  8+(i0-'1)*8+(j0-'1)*32 < 1+(i-'1)*8+(j-'1)*32 by A13,XXREAL_0:2;
      thus A /\ B = {}
      proof
        assume A /\ B <> {};
        then consider x be object such that
A150:   x in A /\ B by XBOOLE_0:def 1;
A15:    x in A & x in B by XBOOLE_0:def 4,A150;
        consider k1 be Nat such that
A16:    x = k1 & 1+(i-'1)*8+(j-'1)*32 <= k1 & k1 <= 8+(i-'1)*8+(j-'1)*32
        by A15;
        consider k2 be Nat such that
A17:    x = k2 & 1+(i0-'1)*8+(j0-'1)*32 <= k2 & k2 <= 8+(i0-'1)*8+(j0-'1)*32
        by A15;
        reconsider x as Nat by A16;
        thus contradiction by A16,A14,XXREAL_0:2,A17;
      end;
    end;
  end;
  hence A /\ B = {};
  end;
  suppose
A2: j = j0;
    now per cases by A2,AS,XXREAL_0:1;
      suppose i < i0;
      then (i-'1) < (i0-'1) by XREAL_1:14,P2,P4;
      then (i-'1)+1 <= (i0-'1) by NAT_1:13;
      then ((i-'1)+1)*8 <= (i0-'1)*8 by XREAL_1:64;
      then
A13:  (i-'1)*8+8+(j-'1)*32 <= (i0-'1)*8+(j0-'1)*32 by A2,XREAL_1:6;
      (i0-'1)*8+(j0-'1)*32+0 < (i0-'1)*8+(j0-'1)*32+1 by XREAL_1:8;
      then
A14:  8+(i-'1)*8+(j-'1)*32 < 1+(i0-'1)*8+(j0-'1)*32 by A13,XXREAL_0:2;
      thus A /\ B = {}
      proof
        assume A /\ B <> {};
        then consider x be object such that
A150:   x in A /\ B by XBOOLE_0:def 1;
A15:    x in A & x in B by XBOOLE_0:def 4,A150;
        consider k1 be Nat such that
A16:    x = k1 & 1+(i-'1)*8+(j-'1)*32 <= k1 & k1 <= 8+(i-'1)*8+(j-'1)*32
        by A15;
        consider k2 be Nat such that
A17:    x = k2 & 1+(i0-'1)*8+(j0-'1)*32 <= k2 & k2 <= 8+(i0-'1)*8+(j0-'1)*32
        by A15;
        reconsider x as Nat by A16;
        thus contradiction by A16,A17,A14,XXREAL_0:2;
      end;
    end;
    suppose
      i0 < i;
      then (i0-'1) < (i-'1) by XREAL_1:14,P2,P4;
      then (i0-'1)+1 <= (i-'1) by NAT_1:13;
      then ((i0-'1)+1)*8 <= (i-'1)*8 by XREAL_1:64;
      then
A13:  (i0-'1)*8+8+(j0-'1)*32 <= (i-'1)*8+(j-'1)*32 by A2,XREAL_1:6;
      (i-'1)*8+(j-'1)*32+0 < (i-'1)*8+(j-'1)*32+1 by XREAL_1:8;
      then
A14:  8+(i0-'1)*8+(j0-'1)*32 < 1+(i-'1)*8+(j-'1)*32 by A13,XXREAL_0:2;
      thus A /\ B = {}
      proof
        assume A /\ B <> {};
        then consider x be object such that
A150:   x in A /\ B by XBOOLE_0:def 1;
A15:    x in A & x in B by XBOOLE_0:def 4,A150;
        consider k1 be Nat such that
A16:    x = k1 & 1+(i-'1)*8+(j-'1)*32 <= k1 & k1 <= 8+(i-'1)*8+(j-'1)*32
        by A15;
        consider k2 be Nat such that
A17:    x = k2 & 1+(i0-'1)*8+(j0-'1)*32 <= k2 & k2 <= 8+(i0-'1)*8+(j0-'1)*32
        by A15;
        reconsider x as Nat by A16;
        thus contradiction by A16,A14,XXREAL_0:2,A17;
      end;
    end;
  end;
  hence A /\ B = {};
end;
end;

theorem LMStat2:
  for k,i,j,i0,j0 be Nat st 1 <= k & k <= 128 & i in Seg 4 & j in Seg 4 &
  i0 in Seg 4 & j0 in Seg 4 & 1+(i-'1)*8+(j-'1)*32 <= k &
  k <= 1+(i-'1)*8+(j-'1)*32+7 & 1+(i0-'1)*8+(j0-'1)*32 <= k &
  k <= 1+(i0-'1)*8+(j0-'1)*32+7 holds i = i0 & j = j0
proof
  let k,i,j,i0,j0 be Nat;
  assume
AS: 1 <= k & k <= 128 & i in Seg 4 & j in Seg 4 & i0 in Seg 4 & j0 in Seg 4 &
  1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7 &
  1+(i0-'1)*8+(j0-'1)*32 <= k & k <= 1+(i0-'1)*8+(j0-'1)*32+7;
  assume not (i = i0 & j = j0);
  then
A2: {n where n is Nat : 1+(i-'1)*8+(j-'1)*32 <= n & n <= 8+(i-'1)*8+(j-'1)*32}
  /\ {n where n is Nat : 1+(i0-'1)*8+(j0-'1)*32 <= n &
  n <= 8+(i0-'1)*8+(j0-'1)*32} = {} by LMStat2A,AS;
A3: k in {n where n is Nat : 1+(i-'1)*8+(j-'1)*32 <= n &
  n <= 8+(i-'1)*8+(j-'1)*32} by AS;
  k in {n where n is Nat : 1+(i0-'1)*8+(j0-'1)*32 <= n &
  n <= 8+(i0-'1)*8+(j0-'1)*32} by AS;
  hence contradiction by A3,XBOOLE_0:def 4,A2;
end;

theorem LMStat1:
  AES-Statearray is one-to-one
proof
  for x1,x2 be object st x1 in 128-tuples_on BOOLEAN &
  x2 in 128-tuples_on BOOLEAN &
  (AES-Statearray).x1 = (AES-Statearray).x2 holds x1 = x2
  proof
    let x1,x2 be object;
    assume
A1: x1 in 128-tuples_on BOOLEAN & x2 in 128-tuples_on BOOLEAN &
    (AES-Statearray).x1 = (AES-Statearray).x2;
    then reconsider xx1 = x1,xx2 = x2 as Element of 128-tuples_on BOOLEAN;
P1: ex s be Element of (BOOLEAN)* st xx1 = s & len s = 128 by A1;
P2: ex s be Element of (BOOLEAN)* st xx2 = s & len s = 128 by A1;
    now let k be Nat;
      assume
P5:   1 <= k & k <= len xx1;
      consider i,j be Nat such that
A4:   i in Seg 4 & j in Seg 4 & 1+(i-'1)*8+(j-'1)*32 <= k &
      k <= 1+(i-'1)*8+(j-'1)*32+7 by LMStat0,P5,P1;
      mid (xx1,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7) is
      Element of (BOOLEAN)* by FINSEQ_1:def 11;
      then reconsider A1ij = (((AES-Statearray).xx1).i).j as
      FinSequence of (BOOLEAN) by DefStatearray,A4;
      mid (xx2,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7) is
      Element of (BOOLEAN)* by FINSEQ_1:def 11;
      then reconsider A2ij = (((AES-Statearray).xx2).i).j as
      FinSequence of (BOOLEAN) by DefStatearray,A4;
A50:  1+(i-'1)*8+(j-'1)*32-((i-'1)*8+(j-'1)*32) <= k-((i-'1)*8+(j-'1)*32)
      by A4,XREAL_1:9;
      then reconsider n = k-((i-'1)*8+(j-'1)*32) as Element of NAT by INT_1:3;
F41:  k-((i-'1)*8+(j-'1)*32) <= 1+(i-'1)*8+(j-'1)*32+7-((i-'1)*8+(j-'1)*32)
      by A4,XREAL_1:9;
F1:   1 <= 1+((i-'1)*8+(j-'1)*32) by NAT_1:11;
F2:   1+(i-'1)*8+(j-'1)*32 <= 1+(i-'1)*8+(j-'1)*32+7 by NAT_1:11;
Q110: 1 <= i & i <= 4 by A4,FINSEQ_1:1;
      then 1-1 <= i-1 by XREAL_1:9;
      then i-'1 = i-1 by XREAL_0:def 2;
      then i-'1 <= 4-1 by Q110,XREAL_1:9;
      then
Q112: (i-'1)*8 <= 3*8 by XREAL_1:64;
Q130: 1 <= j & j <= 4 by A4,FINSEQ_1:1;
      then 1-1 <= j-1 by XREAL_1:9;
      then j-'1 = j-1 by XREAL_0:def 2;
      then j-'1 <= 4-1 by Q130,XREAL_1:9;
      then
Q133: (j-'1)*32 <= 3*32 by XREAL_1:64;
      (i-'1)*8+(j-'1)*32 <= 24+96 by Q133,Q112,XREAL_1:7;
      then 1+((i-'1)*8+(j-'1)*32) <= 1+120 by XREAL_1:7;
      then
Q135: 1+(i-'1)*8+(j-'1)*32+7 <= 121+7 by XREAL_1:6;
F5:   n <= (1+(i-'1)*8+(j-'1)*32+7)-(1+(i-'1)*8+(j-'1)*32)+1 by F41;
A6:   k = n-1+(1+(i-'1)*8+(j-'1)*32);
      thus xx1.k = (mid (xx1,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)).n
      by F1,F2,Q135,P1,A50,F5,A6,FINSEQ_6:122
        .= A2ij.n by DefStatearray,A4,A1
        .= (mid (xx2,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)).n
        by DefStatearray,A4
        .= xx2.k by F1,F2,P2,Q135,A50,F5,A6,FINSEQ_6:122;
    end;
  hence thesis by P1,P2,FINSEQ_1:def 17;
end;
hence thesis by FUNCT_2:19;
end;

theorem LMStat3:
  AES-Statearray is onto
proof
  for y be object st y in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  ex x be object st x in 128-tuples_on BOOLEAN & y = AES-Statearray.x
  proof
    let y be object;
    assume y in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
B10:ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
    st y = s & len s = 4;
    then reconsider z = y as Element of (4-tuples_on (8-tuples_on BOOLEAN))*;
    defpred PK[Nat,set] means
    ex i,j,n be Nat, zij be Element of (8-tuples_on BOOLEAN)
    st i in Seg 4 & j in Seg 4 & n in Seg 8 & 1+(i-'1)*8+(j-'1)*32 <= $1 &
    $1 <= 1+(i-'1)*8+(j-'1)*32+7 & n = $1-((i-'1)*8+(j-'1)*32) & zij = (z.i).j
    & $2 = zij.n;
Q12: for k be Nat st k in Seg 128 ex z being Element of BOOLEAN st PK[k,z]
    proof
      let k be Nat;
      assume k in Seg 128;
      then 1 <= k & k <= 128 by FINSEQ_1:1;
      then consider i,j be Nat such that
A4:   i in Seg 4 & j in Seg 4 & 1+(i-'1)*8+(j-'1)*32 <= k &
      k <= 1+(i-'1)*8+(j-'1)*32+7 by LMStat0;
      i in dom z by FINSEQ_1:def 3,A4,B10;
      then z.i in rng z by FUNCT_1:3;
      then z.i in 4-tuples_on (8-tuples_on BOOLEAN);
      then
B10:  ex s be Element of (8-tuples_on BOOLEAN)* st z.i = s & len s = 4;
      then reconsider zi = z.i as Element of (8-tuples_on BOOLEAN)*;
      j in dom zi by B10,FINSEQ_1:def 3,A4;
      then (zi).j in rng zi by FUNCT_1:3;
      then reconsider zij = (z.i).j as Element of 8-tuples_on BOOLEAN;
A50:  1+(i-'1)*8+(j-'1)*32-((i-'1)*8+(j-'1)*32) <= k-((i-'1)*8+(j-'1)*32)
      by A4,XREAL_1:9;
      then reconsider n = k-((i-'1)*8+(j-'1)*32) as Element of NAT by INT_1:3;
      k-((i-'1)*8+(j-'1)*32) <= 1+(i-'1)*8+(j-'1)*32+7-((i-'1)*8+(j-'1)*32)
      by A4,XREAL_1:9;
      then
G4:   n in Seg 8 by A50;
      reconsider z = zij.n as Element of BOOLEAN;
      take z;
      thus thesis by A4,G4;
    end;
    consider x be FinSequence of BOOLEAN
    such that
Q13: dom x = Seg 128 & for i be Nat st i in Seg 128
    holds PK[i,x.i] from FINSEQ_1:sch 5(Q12);
Q14: len x = 128 by Q13,FINSEQ_1:def 3;
    reconsider x as Element of (BOOLEAN)* by FINSEQ_1:def 11;
    x in 128-tuples_on BOOLEAN by Q14;
    then reconsider x as Element of 128-tuples_on BOOLEAN;
P2: for i,j be Nat st i in Seg 4 & j in Seg 4
    holds (z.i).j = mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)
    proof
      let i,j be Nat;
      assume
P21:  i in Seg 4 & j in Seg 4;
      then i in dom z by FINSEQ_1:def 3,B10;
      then z.i in rng z by FUNCT_1:3;
      then z.i in 4-tuples_on (8-tuples_on BOOLEAN);
      then
P8:   ex s be Element of (8-tuples_on BOOLEAN)* st z.i = s & len s = 4;
      reconsider zi = z.i as Element of (8-tuples_on BOOLEAN)* by P8;
      j in dom zi by P8,FINSEQ_1:def 3,P21;
      then zi.j in rng zi by FUNCT_1:3;
      then zi.j in (8-tuples_on BOOLEAN);
      then
P11:  ex s be Element of (BOOLEAN)* st zi.j = s & len s = 8;
      reconsider zij = zi.j as Element of (BOOLEAN)* by P11;
Q110: 1 <= i & i <= 4 by P21,FINSEQ_1:1;
      then 1-1 <= i-1 by XREAL_1:9;
      then i-'1 = i-1 by XREAL_0:def 2;
      then i-'1 <= 4-1 by Q110,XREAL_1:9;
      then
Q112: (i-'1)*8 <= 3*8 by XREAL_1:64;
Q130: 1 <= j & j <= 4 by P21,FINSEQ_1:1;
      then 1-1 <= j-1 by XREAL_1:9;
      then j-'1 = j-1 by XREAL_0:def 2;
      then j-'1 <= 4-1 by Q130,XREAL_1:9;
      then
Q133: (j-'1)*32 <= 3*32 by XREAL_1:64;
      (i-'1)*8+(j-'1)*32 <= 24+96 by Q133,Q112,XREAL_1:7;
      then
Q134: 1+((i-'1)*8+(j-'1)*32) <= 1+120 by XREAL_1:7;
      then
G1:   1+((i-'1)*8+(j-'1)*32) <= len x by XXREAL_0:2,Q14;
G0:   1 <= 1+((i-'1)*8+(j-'1)*32) by NAT_1:11;
G2:   1 <= 1+((i-'1)*8+(j-'1)*32+7) by NAT_1:11;
G3:   1+((i-'1)*8+(j-'1)*32)+0 <= 1+(i-'1)*8+(j-'1)*32+7 by XREAL_1:7;
Q135: 1+(i-'1)*8+(j-'1)*32+7 <= 121+7 by XREAL_1:6,Q134;
      then
F3:   1+(i-'1)*8+(j-'1)*32+7 <= len x by Q13,FINSEQ_1:def 3;
P13:  len (mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)) =
      (1+(i-'1)*8+(j-'1)*32+7)-'(1+(i-'1)*8+(j-'1)*32)+1
      by G1,G2,G3,G0,F3,FINSEQ_6:118
        .= (1+(i-'1)*8+(j-'1)*32+7)-(1+(i-'1)*8+(j-'1)*32)+1 by G3,XREAL_1:233
        .= 8;
      now let n be Nat;
        assume
F40:    1 <= n & n <= len zij;
F1:     1 <= 1+((i-'1)*8+(j-'1)*32) by NAT_1:11;
F2:     1+(i-'1)*8+(j-'1)*32 <= 1+(i-'1)*8+(j-'1)*32+7 by NAT_1:11;
F5:     n <= (1+(i-'1)*8+(j-'1)*32+7)-(1+(i-'1)*8+(j-'1)*32)+1 by F40,P11;
        reconsider k = n+((i-'1)*8+(j-'1)*32) as Nat;
A6:     k = n-1+(1+(i-'1)*8+(j-'1)*32);
        n <= n+((i-'1)*8+(j-'1)*32) by NAT_1:11;
        then
H1:     1 <= k by F40,XXREAL_0:2;
        reconsider k = n+((i-'1)*8+(j-'1)*32) as Nat;
H3:     k <= 8+((i-'1)*8+(j-'1)*32) by F40,P11,XREAL_1:7;
        then
H2:     k <= 128 by Q135,XXREAL_0:2;
        then k in Seg 128 by H1;
        then consider i0,j0,n0 be Nat,
        zi0j0 be Element of (8-tuples_on BOOLEAN) such that
AA1:    i0 in Seg 4 & j0 in Seg 4 & n0 in Seg 8 & 1+(i0-'1)*8+(j0-'1)*32 <= k &
        k <= 1+(i0-'1)*8+(j0-'1)*32+7 & n0 = k-((i0-'1)*8+(j0-'1)*32) &
        zi0j0 = (z.i0).j0 & x.k = zi0j0.n0 by Q13;
        1+((i-'1)*8+(j-'1)*32) <= n+((i-'1)*8+(j-'1)*32) by F40,XREAL_1:7;
        then 1+(i-'1)*8+(j-'1)*32 <= k & k <= 1+(i-'1)*8+(j-'1)*32+7 by H3;
        then i = i0 & j = j0 by LMStat2,AA1,P21,H1,H2;
        hence zij.n = (mid (x,1+(i-'1)*8+(j-'1)*32,1+(i-'1)*8+(j-'1)*32+7)).n
        by AA1,F1,F2,F3,F40,F5,A6,FINSEQ_6:122;
      end;
      hence thesis by FINSEQ_1:def 17,P11,P13;
    end;
    (AES-Statearray.x) in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
P3: ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
    st (AES-Statearray.x) = s & len s = 4;
    now let i be Nat;
      assume 1 <= i & i <= len (AES-Statearray.x);
      then
P6:   i in Seg 4 by P3;
      then i in dom(AES-Statearray.x) by FINSEQ_1:def 3,P3;
      then (AES-Statearray.x).i in rng (AES-Statearray.x) by FUNCT_1:3;
      then (AES-Statearray.x).i in 4-tuples_on (8-tuples_on BOOLEAN);
      then
P8:   ex s be Element of (8-tuples_on BOOLEAN)*
      st (AES-Statearray.x).i = s & len s = 4;
      reconsider H1i = (AES-Statearray.x).i as
      Element of (8-tuples_on BOOLEAN)* by P8;
      i in dom z by FINSEQ_1:def 3,B10,P6;
      then z.i in rng z by FUNCT_1:3;
      then z.i in 4-tuples_on (8-tuples_on BOOLEAN);
      then
P11:  ex s be Element of (8-tuples_on BOOLEAN)*
      st z.i = s & len s = 4;
      reconsider H2i = z.i as Element of (8-tuples_on BOOLEAN)* by P11;
      now let j be Nat;
        assume 1 <= j & j <= len H1i;
        then
P14:    j in Seg 4 by P8;
        then ((AES-Statearray.x).i).j = mid (x,1+(i-'1)*8+(j-'1)*32,
        1+(i-'1)*8+(j-'1)*32+7) by DefStatearray,P6;
        hence H1i.j = H2i.j by P2,P6,P14;
      end;
      hence (AES-Statearray.x).i = z.i by P8,P11,FINSEQ_1:def 17;
    end;
    hence thesis by P3,B10,FINSEQ_1:def 17;
  end;
  then 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) =
  rng AES-Statearray by FUNCT_2:10;
  hence thesis by FUNCT_2:def 3;
end;

registration
  cluster AES-Statearray -> bijective;
  correctness by LMStat1,LMStat3;
end;

theorem LMINV1:
  for cipher be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds AES-Statearray.((AES-Statearray)".(cipher)) = cipher
proof
  let cipher be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  set f = AES-Statearray;
L0: rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  by FUNCT_2:def 3;
  then reconsider g = f" as Function of
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),128-tuples_on BOOLEAN
  by FUNCT_2:25;
L2: (f")*f = id (128-tuples_on BOOLEAN) & f*(f") =
  id (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) by FUNCT_2:29,L0;
  then g is one-to-one & rng g = 128-tuples_on BOOLEAN by FUNCT_2:18;
  then f = g" by FUNCT_2:30,L2;
  hence thesis by FUNCT_2:26;
end;

begin :: SubBytes

reserve SBT for Permutation of (8-tuples_on BOOLEAN);

definition
  let SBT;
  func SubBytes(SBT) ->
  Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefSubBytes:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds for i,j be Nat st i in Seg 4 & j in Seg 4
  holds ex inputij be Element of 8-tuples_on BOOLEAN
  st inputij = (input.i).j & ((it.input).i).j = SBT.(inputij);
  existence
  proof
    defpred P0[Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))] means
    for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ex inputij be Element of 8-tuples_on BOOLEAN
    st inputij = ($1.i).j & ($2.i).j = SBT.(inputij);
A1: for text being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[text,z]
    proof
      let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      text in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q01:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st text = s & len s = 4;
      defpred P[Nat,set] means
      ex zk be Element of (4-tuples_on (8-tuples_on BOOLEAN))
      st $2 = zk & for j be Nat st j in Seg 4
      holds ex textij be Element of 8-tuples_on BOOLEAN
      st textij = (text.$1).j & zk.j = SBT.(textij);
Q1:   for k be Nat st k in Seg 4 ex zk being
      Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,zk]
      proof
        let k be Nat;
        assume k in Seg 4;
        then k in dom text by Q01,FINSEQ_1:def 3;
        then text.k in rng text by FUNCT_1:3;
        then text.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q13:    ex s be Element of (8-tuples_on BOOLEAN)* st text.k = s & len s = 4;
        then reconsider textk = text.k as Element of (8-tuples_on BOOLEAN)*;
        defpred Pi[Nat,set] means
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (textk).$1 &
        $2 = SBT.(textij);
Q18:    for j be Nat st j in Seg 4 ex xi being Element of (8-tuples_on BOOLEAN)
        st Pi[j,xi]
        proof
          let j be Nat;
          assume j in Seg 4;
          then j in dom(textk) by Q13,FINSEQ_1:def 3;
          then (textk).j in rng (textk) by FUNCT_1:3;
          then reconsider textkj = (textk).j as Element of 8-tuples_on BOOLEAN;
          SBT.(textkj) = SBT.(textkj);
          hence thesis;
        end;
        consider zk be FinSequence of (8-tuples_on BOOLEAN) such that
Q22:    dom zk = Seg 4 & for j be Nat st j in Seg 4
        holds Pi[j,zk.j] from FINSEQ_1:sch 5(Q18);
Q23:    len zk = 4 by Q22,FINSEQ_1:def 3;
        reconsider zk as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zk in 4-tuples_on (8-tuples_on BOOLEAN) by Q23;
        then reconsider zk as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        for j be Nat st j in Seg 4 holds
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (textk).j &
        zk.j = SBT.(textij) by Q22;
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 & for i be Nat st i in Seg 4
      holds P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by Q3;
      then reconsider z as Element of
      4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      take z;
      for i,j be Nat st i in Seg 4 & j in Seg 4 holds
      ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
      (z.i).j = SBT.(textij)
      proof
        let i,j be Nat;
        assume
Q4:     i in Seg 4 & j in Seg 4;
        then ex zi be Element of (4-tuples_on (8-tuples_on BOOLEAN))
        st z.i = zi & for j be Nat st j in Seg 4 holds
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        zi.j = SBT.(textij) by Q2;
        hence ex textij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & (z.i).j = SBT.(textij) by Q4;
      end;
      hence thesis;
    end;
    consider I be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let F1,F2 be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4 holds
    ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
    ((F1.text).i).j = SBT.(textij);
    assume
A2: for text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4 holds
    ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
    ((F2.text).i).j = SBT.(textij);
    now let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      now let i,j be Nat;
        assume
A3:     i in Seg 4 & j in Seg 4;
        then
A4:     ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        ((F1.text).i).j = SBT.(textij) by A1;
A5:     ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        ((F2.text).i).j = SBT.(textij) by A3,A2;
        thus ((F1.text).i).j = ((F2.text).i).j by A4,A5;
      end;
      hence F1.text = F2.text by LM01;
    end;
    hence F1 = F2 by FUNCT_2:63;
  end;
end;

definition
  let SBT;
  func InvSubBytes(SBT) ->
  Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefInvSubBytes:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds for i,j be Nat st i in Seg 4 & j in Seg 4 holds
  ex inputij be Element of 8-tuples_on BOOLEAN st inputij = (input.i).j &
  ((it.input).i).j = (SBT").(inputij);
  existence
  proof
    defpred P0[Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))] means
    for i,j be Nat st i in Seg 4 & j in Seg 4 holds
    ex inputij be Element of 8-tuples_on BOOLEAN st inputij = ($1.i).j &
    ($2.i).j = (SBT").(inputij);
A1: for text being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[text,z]
    proof
      let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      text in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q01:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st text = s &
      len s = 4;
      defpred P[Nat,set] means
      ex zk be Element of (4-tuples_on (8-tuples_on BOOLEAN)) st $2 = zk &
      for j be Nat st j in Seg 4 holds
      ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.$1).j &
      zk.j = (SBT").(textij);
Q1:   for k be Nat st k in Seg 4
      ex zk being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,zk]
      proof
        let k be Nat;
        assume k in Seg 4;
        then k in dom text by Q01,FINSEQ_1:def 3;
        then text.k in rng text by FUNCT_1:3;
        then text.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q13:    ex s be Element of (8-tuples_on BOOLEAN)* st text.k = s & len s = 4;
        then reconsider textk = text.k as Element of (8-tuples_on BOOLEAN)*;
        defpred Pi[Nat,set] means
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (textk).$1 &
        $2 = (SBT").(textij);
Q18:    for j be Nat st j in Seg 4 ex xi being Element of (8-tuples_on BOOLEAN)
        st Pi[j,xi]
        proof
          let j be Nat;
          assume j in Seg 4;
          then j in dom(textk) by Q13,FINSEQ_1:def 3;
          then (textk).j in rng (textk) by FUNCT_1:3;
          then reconsider textkj = (textk).j as Element of 8-tuples_on BOOLEAN;
          (SBT").(textkj) = (SBT").(textkj);
          hence thesis;
        end;
        consider zk be FinSequence of (8-tuples_on BOOLEAN) such that
Q22:    dom zk = Seg 4 & for j be Nat st j in Seg 4
        holds Pi[j,zk.j ] from FINSEQ_1:sch 5(Q18);
Q23:    len zk = 4 by Q22,FINSEQ_1:def 3;
        reconsider zk as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zk in 4-tuples_on (8-tuples_on BOOLEAN) by Q23;
        then reconsider zk as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        for j be Nat st j in Seg 4 holds
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (textk).j &
        zk.j = (SBT").(textij) by Q22;
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 & for i be Nat st i in Seg 4
      holds P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by Q3;
      then reconsider z as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      take z;
      for i,j be Nat st i in Seg 4 & j in Seg 4 holds
      ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
      (z.i).j = (SBT").(textij)
      proof
        let i,j be Nat;
        assume
Q4:     i in Seg 4 & j in Seg 4;
        then ex zi be Element of (4-tuples_on (8-tuples_on BOOLEAN))
        st z.i = zi & for j be Nat st j in Seg 4 holds
        ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        zi.j = (SBT").(textij) by Q2;
        hence ex textij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & (z.i).j = (SBT").(textij) by Q4;
      end;
      hence thesis;
    end;
    consider I be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let F1,F2 be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4 holds
    ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
    ((F1.text).i).j = (SBT").(textij);
    assume
A2: for text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4 holds
    ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
    ((F2.text).i).j = (SBT").(textij);
    now let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      now let i,j be Nat;
        assume
A3:     i in Seg 4 & j in Seg 4;
        then
A4:     ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        ((F1.text).i).j = (SBT").(textij) by A1;
A5:     ex textij be Element of 8-tuples_on BOOLEAN st textij = (text.i).j &
        ((F2.text).i).j = (SBT").(textij) by A3,A2;
        thus ((F1.text).i).j = ((F2.text).i).j by A4,A5;
      end;
      hence F1.text = F2.text by LM01;
    end;
    hence F1 = F2 by FUNCT_2:63;
  end;
end;

INV07A:
  for input be Element of 8-tuples_on BOOLEAN
  holds (SBT").(SBT.(input)) = input
proof
  let input be Element of 8-tuples_on BOOLEAN;
  thus (SBT").(SBT.(input)) = ((SBT")*SBT).input by FUNCT_2:15
    .= (id (8-tuples_on BOOLEAN)).input by FUNCT_2:61
    .= input;
end;

INV08A:
  for input be Element of 8-tuples_on BOOLEAN
  holds SBT.((SBT").(input)) = input
proof
  let input be Element of 8-tuples_on BOOLEAN;
  thus SBT.((SBT").(input)) = (SBT*(SBT")).input by FUNCT_2:15
    .= (id (8-tuples_on BOOLEAN)).input by FUNCT_2:61
    .= input;
end;

theorem INV07:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (InvSubBytes(SBT)).((SubBytes(SBT)).input) = input
proof
  let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  now let i,j be Nat;
    assume
A3: i in Seg 4 & j in Seg 4;
    then consider outputij be Element of 8-tuples_on BOOLEAN such that
A4: outputij = (((SubBytes(SBT)).input).i).j &
    (((InvSubBytes(SBT)).((SubBytes(SBT)).input)).i).j = (SBT").(outputij)
    by DefInvSubBytes;
    consider inputij be Element of 8-tuples_on BOOLEAN such that
A5: inputij = (input.i).j & (((SubBytes(SBT)).input).i).j = SBT.(inputij)
    by DefSubBytes,A3;
    thus (((InvSubBytes(SBT)).((SubBytes(SBT)).input)).i).j = (input.i).j
    by A4,A5,INV07A;
  end;
  hence (InvSubBytes(SBT)).((SubBytes(SBT)).input) = input by LM01;
end;

theorem INV08:
  for output be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (SubBytes(SBT)).((InvSubBytes(SBT)).output) = output
proof
  let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  now let i,j be Nat;
    assume
A3: i in Seg 4 & j in Seg 4;
    then consider outputij be Element of 8-tuples_on BOOLEAN such that
A4: outputij = (((InvSubBytes(SBT)).input).i).j &
    (((SubBytes(SBT)).((InvSubBytes(SBT)).input)).i).j = SBT.(outputij)
    by DefSubBytes;
    consider inputij be Element of 8-tuples_on BOOLEAN such that
A5: inputij = (input.i).j &
    (((InvSubBytes(SBT)).input).i).j = (SBT").(inputij) by DefInvSubBytes,A3;
    thus (((SubBytes(SBT)).((InvSubBytes(SBT)).input)).i).j = (input.i).j
    by A4,A5,INV08A;
  end;
  hence (SubBytes(SBT)).((InvSubBytes(SBT)).input) = input by LM01;
end;

theorem
  SubBytes(SBT) is one-to-one & SubBytes(SBT) is onto &
  InvSubBytes(SBT) is one-to-one & InvSubBytes(SBT) is onto &
  InvSubBytes(SBT) = (SubBytes(SBT))" & SubBytes(SBT) = (InvSubBytes(SBT))"
proof
  set f = SubBytes(SBT);
  set g = InvSubBytes(SBT);
P1: for x be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds g.(f.x) = x by INV07;
P2: for y be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds f.(g.y) = y by INV08;
  thus f is one-to-one & f is onto & g is one-to-one & g is onto &
  g = f" & f = g" by INV00,P1,P2;
end;

begin :: ShiftRows

definition
  func ShiftRows ->
  Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefShiftRows:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (for i be Nat st i in Seg 4 holds
  ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
  (it.input).i = Op-Shift(xi,5-i));
  existence
  proof
    defpred P0[Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))] means
    for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = $1.i &
    $2.i = Op-Shift(xi,5-i);
A1: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[x,z]
    proof
      let x be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      x in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q01:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st x = s &
      len s = 4;
      defpred P[Nat,set] means
      ex xk be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xk = x.$1 &
      $2 = Op-Shift(xk,5-$1);
Q1:   for k be Nat st k in Seg 4
      ex zk being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,zk]
      proof
        let k be Nat;
        assume k in Seg 4;
        then k in dom x by Q01,FINSEQ_1:def 3;
        then
Q11:    x.k in rng x by FUNCT_1:3;
        then x.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q13:    ex s be Element of (8-tuples_on BOOLEAN)* st x.k = s & len s = 4;
        then reconsider xk = x.k as Element of (8-tuples_on BOOLEAN)*;
        reconsider xk1 = xk as Element of 4-tuples_on (8-tuples_on BOOLEAN)
        by Q11;
        reconsider zk = Op-Shift(xk,5-k) as
        FinSequence of (8-tuples_on BOOLEAN);
Q15:    len zk = 4 by Q13,DESCIP_1:def 3;
        reconsider zk as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zk in 4-tuples_on (8-tuples_on BOOLEAN) by Q15;
        then reconsider zk as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        ex xk be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xk = x.k &
        zk = Op-Shift(xk1,5-k);
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 & for i be Nat st i in Seg 4
      holds P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by Q3;
      hence thesis by Q2;
    end;
    consider I be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let H1,H2 be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
    (H1.input).i = Op-Shift(xi,5-i));
    assume
A2: for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
    (H2.input).i = Op-Shift(xi,5-i));
    now let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      H1.input in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P3:   ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))* st H1.input = s &
      len s = 4;
      H2.input in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P4:   ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))* st H2.input = s &
      len s = 4;
      now let i be Nat;
        assume 1 <= i & i <= len (H1.input);
        then
XX2:    i in Seg 4 by P3;
        then
XX3:    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN)
        st xi = input.i & (H1.input).i = Op-Shift(xi,5-i) by A1;
XX4:    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN)
        st xi = input.i & (H2.input).i = Op-Shift(xi,5-i) by A2,XX2;
        thus (H1.input).i = (H2.input).i by XX3,XX4;
      end;
      hence H1.input = H2.input by P3,P4,FINSEQ_1:14;
    end;
    hence H1 = H2 by FUNCT_2:63;
  end;
end;

definition
  func InvShiftRows ->
  Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefInvShiftRows:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (for i be Nat st i in Seg 4 holds
  ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
  (it.input).i = Op-Shift(xi,i-1));
  existence
  proof
    defpred P0[Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))] means
    for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = $1.i &
    $2.i = Op-Shift(xi,i-1);
A1: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[x,z]
    proof
      let x be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      x in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q01:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st x = s &
      len s = 4;
      defpred P[Nat,set] means
      ex xk be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xk = x.$1 &
      $2 = Op-Shift(xk,$1-1);
Q1:   for k be Nat st k in Seg 4
      ex zk being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,zk]
      proof
        let k be Nat;
        assume k in Seg 4;
        then k in dom x by Q01,FINSEQ_1:def 3;
        then
Q11:    x.k in rng x by FUNCT_1:3;
        then x.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q13:    ex s be Element of (8-tuples_on BOOLEAN)* st x.k = s & len s = 4;
        then reconsider xk = x.k as Element of (8-tuples_on BOOLEAN)*;
        reconsider xk1 = xk as Element of 4-tuples_on (8-tuples_on BOOLEAN)
        by Q11;
        reconsider zk = Op-Shift(xk,k-1) as
        FinSequence of (8-tuples_on BOOLEAN);
Q15:    len zk = 4 by Q13,DESCIP_1:def 3;
        reconsider zk as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zk in 4-tuples_on (8-tuples_on BOOLEAN) by Q15;
        then reconsider zk as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        ex xk be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xk = x.k &
        zk = Op-Shift(xk1,k-1);
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 & for i be Nat st i in Seg 4 holds
      P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by Q3;
      hence thesis by Q2;
    end;
    consider I be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let H1,H2 be Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
    (H1.input).i = Op-Shift(xi,i-1));
    assume
A2: for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Nat st i in Seg 4 holds
    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
    (H2.input).i = Op-Shift(xi,i-1));
    now let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      H1.input in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P3:   ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))* st H1.input = s &
      len s = 4;
      H2.input in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
P4:   ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))* st H2.input = s &
      len s = 4;
      now let i be Nat;
        assume 1 <= i & i <= len (H1.input);
        then
XX2:    i in Seg 4 by P3;
        then
XX3:    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
        (H1.input).i = Op-Shift(xi,i-1) by A1;
XX4:    ex xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) st xi = input.i &
        (H2.input).i = Op-Shift(xi,i-1) by A2,XX2;
        thus (H1.input).i = (H2.input).i by XX3,XX4;
      end;
      hence H1.input = H2.input by P3,P4,FINSEQ_1:14;
    end;
    hence H1 = H2 by FUNCT_2:63;
  end;
end;

theorem INV04:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds InvShiftRows.(ShiftRows.input) = input
proof
  let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  InvShiftRows.(ShiftRows.input) in
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  then
P3: ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))*
  st InvShiftRows.(ShiftRows.input) = s & len s = 4;
  input in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  then
P4: ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))*
  st input = s & len s = 4;
  now let i be Nat;
    assume 1 <= i & i <= len (InvShiftRows.(ShiftRows.input));
    then
XX2: i in Seg 4 by P3;
    then consider xi be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
XX3: xi = input.i & (ShiftRows.input).i = Op-Shift(xi,5-i) by DefShiftRows;
    xi in 4-tuples_on (8-tuples_on BOOLEAN);
    then
YY1: ex s be Element of (8-tuples_on BOOLEAN)* st xi = s & len s = 4;
    consider yi be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
XX4: yi = (ShiftRows.input).i &
    (InvShiftRows.(ShiftRows.input)).i = Op-Shift(yi,i-1)
    by DefInvShiftRows,XX2;
    thus (InvShiftRows.(ShiftRows.input)).i = Op-Shift(xi,5-i+(i-1))
    by XX3,XX4,DESCIP_1:10,YY1
      .= input.i by DESCIP_1:12,YY1,XX3;
  end;
  hence (InvShiftRows.(ShiftRows.input)) = input by P3,P4,FINSEQ_1:14;
end;

theorem INV05:
  for output be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds ShiftRows.(InvShiftRows.output) = output
proof
  let output be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  ShiftRows.(InvShiftRows.output) in
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  then
P3: ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))*
  st ShiftRows.(InvShiftRows.output) = s & len s = 4;
  output in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  then
P4: ex s be Element of (4-tuples_on(8-tuples_on BOOLEAN))*
  st output = s & len s = 4;
  now let i be Nat;
    assume 1 <= i & i <= len (ShiftRows.(InvShiftRows.output));
    then
XX2: i in Seg 4 by P3;
    then consider xi be Element of 4-tuples_on (8-tuples_on BOOLEAN)
    such that
XX3: xi = output.i &
    (InvShiftRows.output).i = Op-Shift(xi,i-1) by DefInvShiftRows;
    xi in 4-tuples_on (8-tuples_on BOOLEAN);
    then
YY1: ex s be Element of (8-tuples_on BOOLEAN)* st xi = s & len s = 4;
    consider yi be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
XX4: yi = (InvShiftRows.output).i &
    (ShiftRows.(InvShiftRows.output)).i = Op-Shift(yi,5-i) by DefShiftRows,XX2;
    thus (ShiftRows.(InvShiftRows.output)).i = Op-Shift(xi,i-1+(5-i))
    by XX3,XX4,DESCIP_1:10,YY1
      .= output.i by DESCIP_1:12,YY1,XX3;
  end;
  hence (ShiftRows.(InvShiftRows.output)) = output by P3,P4,FINSEQ_1:14;
end;

theorem
  ShiftRows is one-to-one & ShiftRows is onto &
  InvShiftRows is one-to-one & InvShiftRows is onto &
  InvShiftRows = (ShiftRows)" & ShiftRows = (InvShiftRows)"
  by INV00,INV04,INV05;

begin :: AddRoundKey

definition
  func AddRoundKey ->
  Function of [:4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)):],
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :DefAddRoundKey:
  for text, key be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds for i,j be Nat st i in Seg 4 & j in Seg 4
  holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
  st textij = (text.i).j & keyij = (key.i).j &
  ((it.(text,key)).i).j = Op-XOR(textij,keyij);
  existence
  proof
    defpred P0[Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))] means
    for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
    st textij = ($1.i).j & keyij = ($2.i).j & ($3.i).j = Op-XOR(textij,keyij);
A1: for text,key
    being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P0[text,key,z]
    proof
      let text, key
      be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      text in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q01:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st text = s & len s = 4;
      key in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      then
Q02:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st key = s & len s = 4;
      defpred P[Nat,set] means
      ex zk be Element of (4-tuples_on (8-tuples_on BOOLEAN))
      st $2 = zk & for j be Nat st j in Seg 4
      holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
      st textij = (text.$1).j & keyij = (key.$1).j &
      zk.j = Op-XOR(textij,keyij);
Q1:   for k be Nat st k in Seg 4 ex zk being
      Element of (4-tuples_on (8-tuples_on BOOLEAN)) st P[k,zk]
      proof
        let k be Nat;
        assume
Q11:    k in Seg 4;
        then k in dom text by Q01,FINSEQ_1:def 3;
        then text.k in rng text by FUNCT_1:3;
        then text.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q13:    ex s be Element of (8-tuples_on BOOLEAN)*
        st text.k = s & len s = 4;
        then reconsider textk = text.k as Element of (8-tuples_on BOOLEAN)*;
        k in dom(key) by Q02,FINSEQ_1:def 3,Q11;
        then key.k in rng key by FUNCT_1:3;
        then key.k in 4-tuples_on (8-tuples_on BOOLEAN);
        then
Q16:    ex s be Element of (8-tuples_on BOOLEAN)*
        st key.k = s & len s = 4;
        then reconsider keyk = key.k as Element of (8-tuples_on BOOLEAN)*;
        defpred Pi[Nat,set] means
        ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (textk).$1 & keyij = (keyk).$1 & $2 = Op-XOR(textij,keyij);
Q18:    for j be Nat st j in Seg 4 ex xi being Element of (8-tuples_on BOOLEAN)
        st Pi[j,xi]
        proof
          let j be Nat;
          assume
Q19:      j in Seg 4;
          then j in dom(textk) by Q13,FINSEQ_1:def 3;
          then (textk).j in rng (textk) by FUNCT_1:3;
          then reconsider textkj = (textk).j as Element of 8-tuples_on BOOLEAN;
          j in dom(keyk) by Q16,FINSEQ_1:def 3,Q19;
          then (keyk).j in rng (keyk) by FUNCT_1:3;
          then reconsider keykj = (key.k).j as Element of 8-tuples_on BOOLEAN;
          Op-XOR(textkj,keykj) = Op-XOR(textkj,keykj);
          hence thesis;
        end;
        consider zk be FinSequence of (8-tuples_on BOOLEAN) such that
Q22:    dom zk = Seg 4 & for j be Nat st j in Seg 4
        holds Pi[j,zk.j] from FINSEQ_1:sch 5(Q18);
Q23:    len zk = 4 by Q22,FINSEQ_1:def 3;
        reconsider zk as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
        zk in 4-tuples_on (8-tuples_on BOOLEAN) by Q23;
        then reconsider zk as Element of 4-tuples_on (8-tuples_on BOOLEAN);
        for j be Nat st j in Seg 4
        holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (textk).j & keyij = (keyk).j & zk.j = Op-XOR(textij,keyij)
        by Q22;
        hence thesis;
      end;
      consider z be FinSequence of 4-tuples_on (8-tuples_on BOOLEAN) such that
Q2:   dom z = Seg 4 & for i be Nat st i in Seg 4
      holds P[i,z.i] from FINSEQ_1:sch 5(Q1);
Q3:   len z = 4 by Q2,FINSEQ_1:def 3;
      reconsider z as Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      by FINSEQ_1:def 11;
      z in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by Q3;
      then reconsider z as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      take z;
      for i,j be Nat st i in Seg 4 & j in Seg 4 holds
      ex textij,keyij be Element of 8-tuples_on BOOLEAN st textij =
      (text.i).j & keyij = (key.i).j & (z.i).j = Op-XOR(textij,keyij)
      proof
        let i,j be Nat;
        assume
Q4:     i in Seg 4 & j in Seg 4;
        then ex zi be Element of (4-tuples_on (8-tuples_on BOOLEAN))
        st z.i = zi & for j be Nat st j in Seg 4
        holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & keyij = (key.i).j &
        zi.j = Op-XOR(textij,keyij) by Q2;
        hence ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & keyij = (key.i).j &
        (z.i).j = Op-XOR(textij,keyij) by Q4;
      end;
      hence thesis;
    end;
    consider I be Function of [:4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)):],
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2: for x,y being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,y,I.(x,y)] from BINOP_1:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let F1,F2 be Function of [:4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)):],
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: for text,key be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
    st textij = (text.i).j & keyij = (key.i).j &
    ((F1.(text,key)).i).j = Op-XOR(textij,keyij);
    assume
A2: for text,key be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds for i,j be Nat st i in Seg 4 & j in Seg 4
    holds ex textij,keyij be Element of 8-tuples_on BOOLEAN
    st textij = (text.i).j & keyij = (key.i).j &
    ((F2.(text,key)).i).j = Op-XOR(textij,keyij);
    now let text,key be
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      now let i,j be Nat;
        assume
A3:     i in Seg 4 & j in Seg 4;
        then
A4:     ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & keyij = (key.i).j &
        ((F1.(text,key)).i).j = Op-XOR(textij,keyij) by A1;
A5:     ex textij,keyij be Element of 8-tuples_on BOOLEAN
        st textij = (text.i).j & keyij = (key.i).j &
        ((F2.(text,key)).i).j = Op-XOR(textij,keyij) by A3,A2;
        thus ((F1.(text,key)).i).j = ((F2.(text,key)).i).j by A4,A5;
      end;
      hence F1.(text,key) = F2.(text,key) by LM01;
    end;
    hence F1 = F2 by BINOP_1:2;
  end;
end;

begin :: Key Expansion

definition
  let SBT;
  let x be Element of 4-tuples_on (8-tuples_on BOOLEAN);
  func SubWord(SBT,x) -> Element of 4-tuples_on (8-tuples_on BOOLEAN) means
  for i be Element of Seg 4 holds it.i = SBT.(x.i);
  existence
  proof
    defpred P[Nat,set] means ex xi be Element of 8-tuples_on BOOLEAN
    st xi = x.$1 & $2 = SBT.(xi);
P1: for k be Nat st k in Seg 4 ex z being Element of 8-tuples_on BOOLEAN
    st P[k,z]
    proof
      let k be Nat;
      assume
AS:   k in Seg 4;
      x in 4-tuples_on (8-tuples_on BOOLEAN);
      then ex s be Element of (8-tuples_on BOOLEAN)* st x = s & len s = 4;
      then k in dom x by FINSEQ_1:def 3,AS;
      then x.k in rng x by FUNCT_1:3;
      then reconsider xk = x.k as Element of 8-tuples_on BOOLEAN;
      SBT.(xk) is Element of 8-tuples_on BOOLEAN;
      hence thesis;
    end;
    consider p being FinSequence of 8-tuples_on BOOLEAN such that
P3: dom p = Seg 4 & for k be Nat st k in Seg 4 holds
    P[k,p.k] from FINSEQ_1:sch 5(P1);
    reconsider p as Element of (8-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
    len p = 4 by P3,FINSEQ_1:def 3;
    then p in 4-tuples_on (8-tuples_on BOOLEAN);
    then reconsider p as Element of 4-tuples_on (8-tuples_on BOOLEAN);
    take p;
    now let i be Element of Seg 4;
      ex xi be Element of 8-tuples_on BOOLEAN st xi = x.i & p.i = SBT.(xi)
      by P3;
      hence p.i = SBT.(x.i);
    end;
    hence thesis;
  end;
  uniqueness
  proof
    let H1,H2 be Element of 4-tuples_on (8-tuples_on BOOLEAN);
    assume
A1: for i be Element of Seg 4 holds H1.i = SBT.(x.i);
    assume
A2: for i be Element of Seg 4 holds H2.i = SBT.(x.i);
    H1 in 4-tuples_on (8-tuples_on BOOLEAN);
    then
P1: ex s be Element of (8-tuples_on BOOLEAN)* st H1 = s & len s = 4;
    H2 in 4-tuples_on (8-tuples_on BOOLEAN);
    then
P2: ex s be Element of (8-tuples_on BOOLEAN)* st H2 = s & len s = 4;
    now let i be Nat;
      assume 1 <= i & i <= len H1;
      then i in Seg 4 by P1;
      then reconsider j = i as Element of Seg 4;
      thus H1.i = (SBT).(x.j) by A1
        .= H2.i by A2;
    end;
    hence H1 = H2 by P1,P2,FINSEQ_1:14;
  end;
end;

definition
  let x be Element of 4-tuples_on (8-tuples_on BOOLEAN);
  func RotWord(x) -> Element of 4-tuples_on (8-tuples_on BOOLEAN) equals
  Op-LeftShift(x);
  correctness by DESCIP_1:6;
end;

definition
  let n,m be non zero Element of NAT;
  let s,t be Element of m-tuples_on (n-tuples_on BOOLEAN);
  func Op-WXOR(s,t) -> Element of m-tuples_on (n-tuples_on BOOLEAN) means
  for i be Element of Seg m holds it.i = Op-XOR(s.i,t.i);
  existence
  proof
    defpred P[Nat,set] means
    ex si,ti be Element of (n-tuples_on BOOLEAN) st si = s.$1 & ti = t.$1 &
    $2 = Op-XOR(si,ti);
P1: for k be Nat st k in Seg m ex z being Element of n-tuples_on BOOLEAN
    st P[k,z]
    proof
      let k be Nat;
      assume
AS:   k in Seg m;
      s in m-tuples_on (n-tuples_on BOOLEAN);
      then ex v be Element of (n-tuples_on BOOLEAN)* st s = v & len v = m;
      then k in dom s by FINSEQ_1:def 3,AS;
      then s.k in rng s by FUNCT_1:3;
      then reconsider sk = s.k as Element of n-tuples_on BOOLEAN;
      t in m-tuples_on (n-tuples_on BOOLEAN);
      then ex v be Element of (n-tuples_on BOOLEAN)* st t = v & len v = m;
      then k in dom t by FINSEQ_1:def 3,AS;
      then t.k in rng t by FUNCT_1:3;
      then reconsider tk = t.k as Element of n-tuples_on BOOLEAN;
      Op-XOR(sk,tk) is Element of n-tuples_on BOOLEAN;
      hence thesis;
    end;
    consider p being FinSequence of n-tuples_on BOOLEAN such that
P3: dom p = Seg m & for k be Nat st k in Seg m holds P[k,p.k]
    from FINSEQ_1:sch 5(P1);
P4: len p = m by P3,FINSEQ_1:def 3;
    p in (n-tuples_on BOOLEAN)* by FINSEQ_1:def 11;
    then p in m-tuples_on (n-tuples_on BOOLEAN) by P4;
    then reconsider p as Element of m-tuples_on (n-tuples_on BOOLEAN);
    take p;
    now let i be Element of Seg m;
      ex si,ti be Element of n-tuples_on BOOLEAN st si = s.i & ti = t.i &
      p.i = Op-XOR(si,ti) by P3;
      hence p.i = Op-XOR(s.i,t.i);
    end;
    hence thesis;
  end;
  uniqueness
  proof
    let H1,H2 be Element of m-tuples_on (n-tuples_on BOOLEAN);
    assume
A1: for i be Element of Seg m holds H1.i = Op-XOR(s.i,t.i);
    assume
A2: for i be Element of Seg m holds H2.i = Op-XOR(s.i,t.i);
    H1 in m-tuples_on (n-tuples_on BOOLEAN);
    then
P1: ex v be Element of (n-tuples_on BOOLEAN)* st H1 = v & len v = m;
    H2 in m-tuples_on (n-tuples_on BOOLEAN);
    then
P2: ex v be Element of (n-tuples_on BOOLEAN)* st H2 = v & len v = m;
    now let i be Nat;
      assume 1 <= i & i <= len H1;
      then i in Seg m by P1;
      then reconsider j = i as Element of Seg m;
      thus H1.i = Op-XOR(s.j,t.j) by A1
        .= H2.i by A2;
    end;
    hence H1 = H2 by P1,P2,FINSEQ_1:14;
  end;
end;

definition
  func Rcon -> Element of 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
  means
  it.1 = <* <*0,0,0,0*>^<*0,0,0,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.2 = <* <*0,0,0,0*>^<*0,0,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.3 = <* <*0,0,0,0*>^<*0,1,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.4 = <* <*0,0,0,0*>^<*1,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.5 = <* <*0,0,0,1*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.6 = <* <*0,0,1,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.7 = <* <*0,1,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.8 = <* <*1,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.9 = <* <*0,0,0,1*>^<*1,0,1,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
  it.10 = <* <*0,0,1,1*>^<*0,1,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *>;
  existence
  proof
X0: 0 in BOOLEAN by TARSKI:def 2,MARGREL1:def 11;
X1: 1 in BOOLEAN by TARSKI:def 2,MARGREL1:def 11;
P1: <*0,0,0,0*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0;
P2: <*0,0,0,1*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
P3: <*0,0,1,0*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
P4: <*0,1,0,0*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
P5: <*1,0,0,0*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
R1: <*1,0,1,1*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
R2: <*0,0,1,1*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
R3: <*0,1,1,0*> is Element of (4-tuples_on BOOLEAN) by LMGSEQ4,X0,X1;
    reconsider PP6 = <* <*0,0,0,0*>^<*0,0,0,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P2,LMGSEQ16;
    reconsider PP7 = <* <*0,0,0,0*>^<*0,0,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P3,LMGSEQ16;
    reconsider PP8 = <* <*0,0,0,0*>^<*0,1,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P4,LMGSEQ16;
    reconsider PP9 = <* <*0,0,0,0*>^<*1,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P5,LMGSEQ16;
    reconsider PP10 = <* <*0,0,0,1*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P2,LMGSEQ16;
    reconsider PP11 = <* <*0,0,1,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P3,LMGSEQ16;
    reconsider PP12 = <* <*0,1,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P4,LMGSEQ16;
    reconsider PP13 = <* <*1,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P5,LMGSEQ16;
    reconsider PP14 = <* <*0,0,0,1*>^<*1,0,1,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,P2,R1,LMGSEQ16;
    reconsider PP15 = <* <*0,0,1,1*>^<*0,1,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> as
    Element of 4-tuples_on (8-tuples_on BOOLEAN) by P1,R2,R3,LMGSEQ16;
    reconsider Q0 = <*PP6,PP7,PP8,PP9,PP10*> as FinSequence;
    reconsider Q1 = <*PP11,PP12,PP13,PP14,PP15*> as FinSequence;
    reconsider IT = Q0^Q1 as
    Element of 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) by LMGSEQ10;
A1: len Q0 = 5 & Q0.1 = PP6 & Q0.2 = PP7 & Q0.3 = PP8 & Q0.4 = PP9 &
    Q0.5 = PP10 by FINSEQ_4:78;
A2: len Q1 = 5 & Q1.1 = PP11 & Q1.2 = PP12 & Q1.3 = PP13 & Q1.4 = PP14 &
    Q1.5 = PP15 by FINSEQ_4:78;
    1 in Seg 5;
    then 1 in dom Q0 by FINSEQ_1:def 3,A1;
    then
R1: IT.1 = PP6 by A1,FINSEQ_1:def 7;
    2 in Seg 5;
    then 2 in dom Q0 by FINSEQ_1:def 3,A1;
    then
R2: IT.2 = PP7 by A1,FINSEQ_1:def 7;
    3 in Seg 5;
    then 3 in dom Q0 by FINSEQ_1:def 3,A1;
    then
R3: IT.3 = PP8 by A1,FINSEQ_1:def 7;
    4 in Seg 5;
    then 4 in dom Q0 by FINSEQ_1:def 3,A1;
    then
R4: IT.4 = PP9 by A1,FINSEQ_1:def 7;
    5 in Seg 5;
    then 5 in dom Q0 by FINSEQ_1:def 3,A1;
    then
R5: IT.5 = PP10 by A1,FINSEQ_1:def 7;
    1 in Seg 5;
    then 1 in dom Q1 by FINSEQ_1:def 3,A2;
    then
R10: IT.(5+1) = Q1.1 by A1,FINSEQ_1:def 7
      .= PP11 by FINSEQ_4:78;
    2 in Seg 5;
    then 2 in dom Q1 by FINSEQ_1:def 3,A2;
    then
R20: IT.(5+2) = Q1.2 by A1,FINSEQ_1:def 7
      .= PP12 by FINSEQ_4:78;
    3 in Seg 5;
    then 3 in dom Q1 by FINSEQ_1:def 3,A2;
    then
R30: IT.(5+3) = Q1.3 by A1,FINSEQ_1:def 7
      .= PP13 by FINSEQ_4:78;
    4 in Seg 5;
    then 4 in dom Q1 by FINSEQ_1:def 3,A2;
    then
R40: IT.(5+4) = Q1.4 by A1,FINSEQ_1:def 7
      .= PP14 by FINSEQ_4:78;
    5 in Seg 5;
    then 5 in dom Q1 by FINSEQ_1:def 3,A2;
    then
R50: IT.(5+5) = Q1.5 by A1,FINSEQ_1:def 7
      .= PP15 by FINSEQ_4:78;
    thus thesis by R1,R2,R3,R4,R5,R10,R20,R30,R40,R50;
  end;
  uniqueness
  proof
    let R1,R2 be Element of 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
    assume
A1: R1.1 = <* <*0,0,0,0*>^<*0,0,0,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.2 = <* <*0,0,0,0*>^<*0,0,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.3 = <* <*0,0,0,0*>^<*0,1,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.4 = <* <*0,0,0,0*>^<*1,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.5 = <* <*0,0,0,1*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.6 = <* <*0,0,1,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.7 = <* <*0,1,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.8 = <* <*1,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.9 = <* <*0,0,0,1*>^<*1,0,1,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R1.10 = <* <*0,0,1,1*>^<*0,1,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *>;
    assume
A2: R2.1 = <* <*0,0,0,0*>^<*0,0,0,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.2 = <* <*0,0,0,0*>^<*0,0,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.3 = <* <*0,0,0,0*>^<*0,1,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.4 = <* <*0,0,0,0*>^<*1,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.5 = <* <*0,0,0,1*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.6 = <* <*0,0,1,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.7 = <* <*0,1,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.8 = <* <*1,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.9 = <* <*0,0,0,1*>^<*1,0,1,1*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *> &
    R2.10 = <* <*0,0,1,1*>^<*0,1,1,0*>,<*0,0,0,0*>^<*0,0,0,0*>,
    <*0,0,0,0*>^<*0,0,0,0*>,<*0,0,0,0*>^<*0,0,0,0*> *>;
    R1 in 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
    then
XP1: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st R1 = v &
    len v = 10;
    R2 in 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
    then
XP2: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st R2 = v &
    len v = 10;
    for i be Nat st 1 <= i & i <= len R1 holds R1.i = R2.i
    proof
      let i be Nat;
      assume 1 <= i & i <= len R1;
      then i = 1 or ... or i = 10 by XP1;
      hence thesis by A1,A2;
    end;
    hence R1 = R2 by XP1,XP2,FINSEQ_1:14;
  end;
end;

definition
  let SBT;
  let m,i be Nat, w be Element of (4-tuples_on (8-tuples_on BOOLEAN));
  assume AS: (m = 4 or m = 6 or m = 8) & i < 4*(7+m) & m <= i;
  func KeyExTemp(SBT,m,i,w) -> Element of (4-tuples_on (8-tuples_on BOOLEAN))
  means
  (ex T3 be Element of (4-tuples_on (8-tuples_on BOOLEAN)) st T3 = Rcon.(i/m) &
  it = Op-WXOR(SubWord(SBT,RotWord(w)),T3)) if ((i mod m) = 0),
  (it = SubWord(SBT,w)) if (m = 8 & (i mod 8) = 4) otherwise it = w;
  existence
  proof
    thus (i mod m) = 0 implies ex A
    being Element of (4-tuples_on (8-tuples_on BOOLEAN))
    st (ex T3 be Element of (4-tuples_on (8-tuples_on BOOLEAN))
    st T3 = Rcon.(i/m) & A = Op-WXOR(SubWord(SBT,RotWord(w)),T3))
    proof
      assume
A1:   (i mod m) = 0;
      m <> 0 & m divides i by A1,INT_1:62,AS;
      then
LTT0: i/m is Integer by WSIERP_1:17;
LTT1: (4*(7+m))/m = (28/m)+4 by AS;
LTT2: m/m <= i/m by AS,XREAL_1:72;
LTT4: i/m in NAT by INT_1:3,LTT0;
LTT5: i/m < 28/m+4 by AS,XREAL_1:74,LTT1;
      i/m <= 10
      proof
        now per cases by AS;
          case m = 4;
            then i/m <10+1 by AS,XREAL_1:74,LTT1;
            hence thesis by NAT_1:13,LTT4;
          end;
          case m = 6;
            hence thesis by LTT5,XXREAL_0:2;
          end;
          case m = 8;
            hence thesis by LTT5,XXREAL_0:2;
          end;
        end;
        hence thesis;
      end;
      then
Q0:   i/m in Seg 10 by AS,LTT2,LTT4;
      reconsider j = i/m as Nat by LTT4;
      Rcon in 10-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      then ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN)) *
      st Rcon = v & len v = 10;
      then dom Rcon = Seg 10 by FINSEQ_1:def 3;
      then Rcon.j in rng Rcon by Q0,FUNCT_1:3;
      then reconsider T3 = Rcon.j as
      Element of (4-tuples_on (8-tuples_on BOOLEAN));
      Op-WXOR(SubWord(SBT,RotWord(w)),T3) is
      Element of (4-tuples_on (8-tuples_on BOOLEAN));
      hence thesis;
    end;
    thus m = 8 & (i mod 8) = 4 implies ex A being
    Element of (4-tuples_on (8-tuples_on BOOLEAN)) st (A = SubWord(SBT,w));
    thus not ((i mod m) = 0) & not (m = 8 & (i mod 8) = 4) implies
    ex A being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st A = w;
  end;
  uniqueness;
  consistency;
end;

definition
  let SBT;
  let m be Nat;
  assume AS: (m = 4 or m = 6 or m = 8);
  func KeyExpansionX(SBT,m) ->
  Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) means
  for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (for i be Element of NAT st i < m holds (it.Key).(i+1) = Key.(i+1))
  & (for i be Element of NAT st m <= i & i < 4*(7+m) holds
  ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
  Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
  st P = (it.Key).((i-m)+1) & Q = (it.Key).i &
  (it.Key).(i+1) = Op-WXOR(P,KeyExTemp(SBT,m,i,Q)));
  existence
  proof
    defpred P0[Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))] means
    (for i be Element of NAT st i < m holds $2.(i+1) = $1.(i+1))&
    (for i be Element of NAT st m <= i & i < 4*(7+m) holds
    ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
    Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
    st P = $2.((i-m)+1) & Q = ($2).i &
    $2.(i+1) = Op-WXOR(P,KeyExTemp(SBT,m,i,Q)));
A1: for x being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
    st P0[x,z]
    proof
      let x be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      defpred PP[Nat,set,set] means
      ex r,t be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      st r = $2 & t = $3 &
      (ex P0,Q0 be Element of 4-tuples_on (8-tuples_on BOOLEAN)
      st P0 = r.1 & Q0 = r.m & t.1 = Op-WXOR(P0,KeyExTemp(SBT,m,m*$1,Q0))) &
      for i be Nat st 1 <= i & i < m holds
      ex P be Element of 4-tuples_on (8-tuples_on BOOLEAN),
      Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
      st P = r.(i+1) & Q = t.i &
      t.(i+1) = Op-WXOR(P,KeyExTemp(SBT,m,m*$1+i,Q));
      0+m <= 7+m by XREAL_1:6;
      then
LMMLT47M: 1*m <= 4*(7+m) by XREAL_1:66;
      reconsider N2 = (4*(7+m) div m )+1 as Nat;
YY1:  for k being Nat st 1 <= k & k < N2
      for s being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      ex y being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      st PP[k,s,y]
      proof
        let k be Nat;
        assume 1 <= k & k < N2;
        let s be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
        defpred PX[Nat,set,set] means
        ex P,Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
        st P = s.($1+1) & Q = $2 &
        $3 = Op-WXOR(P,KeyExTemp(SBT,m,m*k+$1,Q));
        s in m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
        then ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
        st s = v & len v = m;
        then
QQ3:    dom s = Seg m by FINSEQ_1:def 3;
XX1:    for i being Nat st 1 <= i & i < m
        for z being Element of (4-tuples_on (8-tuples_on BOOLEAN))
        ex w being Element of (4-tuples_on (8-tuples_on BOOLEAN))
        st PX[i,z,w]
        proof
          let i be Nat;
          assume
AA1:      1 <= i & i < m;
          let z be Element of (4-tuples_on (8-tuples_on BOOLEAN));
          1 <= i+1 & i+1 <= m by NAT_1:13,AA1;
          then i+1 in Seg m;
          then s.(i+1) in rng s by QQ3,FUNCT_1:3;
          then reconsider P = s.(i+1) as
          Element of 4-tuples_on (8-tuples_on BOOLEAN);
          reconsider Q = z as Element of 4-tuples_on (8-tuples_on BOOLEAN);
          Op-WXOR(P,KeyExTemp(SBT,m,m*k+i,Q)) is
          Element of (4-tuples_on (8-tuples_on BOOLEAN));
          hence thesis;
        end;
        1 in dom s by AS,QQ3;
        then s.1 in rng s by FUNCT_1:3;
        then reconsider P0 = s.1 as
        Element of 4-tuples_on (8-tuples_on BOOLEAN);
        m in dom s by AS,QQ3;
        then s.m in rng s by FUNCT_1:3;
        then reconsider Q0 = s.m as
        Element of 4-tuples_on (8-tuples_on BOOLEAN);
        reconsider A0 = Op-WXOR(P0,KeyExTemp(SBT,m,m*k,Q0)) as
        Element of 4-tuples_on (8-tuples_on BOOLEAN);
        consider y being FinSequence of (4-tuples_on (8-tuples_on BOOLEAN))
        such that
A2:     len y = m & (y.1 = A0 or m = 0) & for i be Nat st 1 <= i &
        i < m holds PX[i,y.i,y.(i+1)] from RECDEF_1:sch 4 (XX1);
        y in (4-tuples_on (8-tuples_on BOOLEAN))* by FINSEQ_1:def 11;
        then y in m-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) by A2;
        hence thesis by AS,A2;
      end;
      consider z being
      FinSequence of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
A2:   len z = N2 & (z.1 = x or N2 = 0) & for k be Nat st 1 <= k &
      k < N2 holds PP[k,z.k,z.(k+1)] from RECDEF_1:sch 4 (YY1);
      defpred Q0[Nat,set] means
      ex i,j be Element of NAT,
      zi be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
      st (($1 mod m) <> 0 implies i = ($1 div m)+1 & j = $1 mod m) &
      (($1 mod m) = 0 implies i = ($1 div m) & j = m) & zi = z.i & $2 = zi.j;
YY2:  for k be Nat st k in Seg (4*(7+m))
      ex w being Element of (4-tuples_on (8-tuples_on BOOLEAN)) st Q0[k,w]
      proof
        let k be Nat;
        assume
A1:     k in Seg (4*(7+m));
QQ1:    1 <= k & k <= 4*(7+m) by A1,FINSEQ_1:1;
        then
QQ2:    k div m <= (4*(7+m)) div m by NAT_2:24;
        per cases;
        suppose
C1:       (k mod m) <> 0;
          reconsider j = (k mod m) as Element of NAT;
          reconsider i = (k div m)+1 as Element of NAT;
          1 <= i & i <= N2 by QQ2,XREAL_1:6,NAT_1:11;
          then i in Seg N2;
          then i in dom z by A2,FINSEQ_1:def 3;
          then z.i in rng z by FUNCT_1:3;
          then reconsider zi = z.i as
          Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
          zi in m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
          then ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
          st zi = v & len v = m;
          then
Q0:       dom zi = Seg m by FINSEQ_1:def 3;
          1 <= j & j <= m by C1,INT_1:58,AS,NAT_1:14;
          then j in dom zi by Q0;
          then zi.j in rng zi by FUNCT_1:3;
          then reconsider w = zi.j as
          Element of (4-tuples_on (8-tuples_on BOOLEAN));
          ((k mod m) <> 0 implies i = (k div m)+1 & j = k mod m) &
          ((k mod m) = 0 implies i = (k div m) & j = m) & zi = z.i &
          w = zi.j by C1;
          hence thesis;
        end;
        suppose
C2:       (k mod m) = 0;
          reconsider j = m as Element of NAT by ORDINAL1:def 12;
          reconsider i = (k div m) as Element of NAT;
QQ3:      1 <= i by NAT_D:24,QQ1,C2,NAT_2:13,AS;
          (k div m)+0 <= ((4*(7+m)) div m)+1 by QQ2,XREAL_1:7;
          then i in Seg N2 by QQ3;
          then i in dom z by A2,FINSEQ_1:def 3;
          then z.i in rng z by FUNCT_1:3;
          then reconsider zi = z.i as
          Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
          zi in m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
          then ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
          st zi = v & len v = m;
          then
Q0:       dom zi = Seg m by FINSEQ_1:def 3;
          j in Seg m by AS;
          then zi.j in rng zi by Q0,FUNCT_1:3;
          then reconsider w = zi.j as
          Element of (4-tuples_on (8-tuples_on BOOLEAN));
          ((k mod m) <> 0 implies i = (k div m)+1 & j = k mod m) &
          ((k mod m) = 0 implies i = (k div m) & j = m) & zi = z.i &
          w = zi.j by C2;
          hence thesis;
        end;
      end;
      consider u being FinSequence of (4-tuples_on (8-tuples_on BOOLEAN))
      such that
YY3:  dom u = Seg (4*(7+m)) & for k be Nat st k in Seg (4*(7+m))
      holds Q0[k,u.k] from FINSEQ_1:sch 5(YY2);
      4*(7+m) is Element of NAT by ORDINAL1:def 12;
      then
YY4:  len u = 4*(7+m) by YY3,FINSEQ_1:def 3;
      u in ((4-tuples_on (8-tuples_on BOOLEAN)))* by FINSEQ_1:def 11;
      then u in (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
      by YY4;
      then reconsider u as
      Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      take u;
LX3:  for i be Element of NAT st i < m holds u.(i+1) = x.(i+1)
      proof
        let k be Element of NAT;
        assume k < m;
        then
LX31:   1 <= k+1 & k+1 <= m by NAT_1:11,NAT_1:13;
        then 1 <= k+1 & k+1 <= 4*(7+m) by LMMLT47M,XXREAL_0:2;
        then k+1 in Seg (4*(7+m));
        then consider i,j be Element of NAT,
        zi be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        such that
LX34:   (((k+1) mod m) <> 0 implies i = ((k+1) div m)+1 &
        j = (k+1) mod m) & (((k+1) mod m) = 0 implies
        i = ((k+1) div m) & j = m) & zi = z.i & u.(k+1) = zi.j by YY3;
        per cases;
        suppose
C1:       ((k+1) mod m) <> 0;
C11:      (k+1) < m
          proof
            assume not (k+1) < m;
            then (k+1) = m by XXREAL_0:1,LX31;
            hence contradiction by NAT_D:25,C1;
          end;
          then (k+1) div m = 0 by NAT_D:27;
          hence u.(k+1) = x.(k+1) by C11,NAT_D:24,LX34,A2;
        end;
        suppose
C2:       ((k+1) mod m) = 0;
          (k+1) = m
          proof
            assume not (k+1) = m;
            then k+1 < m by LX31,XXREAL_0:1;
            hence contradiction by NAT_D:24,C2;
          end;
          hence u.(k+1) = x.(k+1) by LX34,C2,INT_1:49,A2;
        end;
      end;
      for k be Element of NAT st m <= k & k < 4*(7+m) holds
      ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
      Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
      st P = u.((k-m)+1) & Q = u.k & u.(k+1) = Op-WXOR(P,KeyExTemp(SBT,m,k,Q))
      proof
        let k be Element of NAT;
        assume
AS1:    m <= k & k < 4*(7+m);
        then 1 <= k & k <= 4*(7+m) by XXREAL_0:2,AS;
        then k in Seg (4*(7+m));
        then consider i,j be Element of NAT,
        zi be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        such that
LX34:   ((k mod m) <> 0 implies i = (k div m)+1 & j = k mod m) &
        ((k mod m) = 0 implies i = (k div m) & j = m) & zi = z.i &
        u.k = zi.j by YY3;
NLX32:  1 <= k+1 & k+1 <= 4*(7+m) by AS1,NAT_1:11,NAT_1:13;
        then k+1 in Seg (4*(7+m));
        then consider i1,j1 be Element of NAT,
        zi1 be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        such that
NLX34:  (((k+1) mod m) <> 0 implies i1 = ((k+1) div m)+1 &
        j1 = (k+1) mod m) & (((k+1) mod m) = 0 implies i1 = ((k+1) div m) &
        j1 = m) & zi1 = z.i1 & u.(k+1) = zi1.j1 by YY3;
        reconsider km0 = k-m as Element of NAT by AS1,XREAL_1:48,INT_1:3;
        reconsider km1 = km0+1 as Element of NAT;
        k+1-m <= 4*(7+m)-0 by NLX32,XREAL_1:13;
        then 1 <= km1 & km1 <= 4*(7+m) by NAT_1:11;
        then km1 in Seg (4*(7+m));
        then consider i2,j2 be Element of NAT,
        zi2 be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        such that
LLX34:  ((km1 mod m) <> 0 implies i2 = (km1 div m)+1 & j2 = km1 mod m) &
        ((km1 mod m) = 0 implies i2 = (km1 div m) & j2 = m) &
        zi2 = z.i2 & u.km1 = zi2.j2 by YY3;
        per cases;
        suppose
C1:       (k mod m) <> 0;
          reconsider i0 = k div m as Element of NAT;
DD1:      ((4*(7+m)) div m)+0 < ((4*(7+m)) div m)+1 by XREAL_1:8;
          k div m <= (4*(7+m)) div m by AS1,NAT_2:24;
          then 1 <= i0 & i0 < N2 by DD1,XXREAL_0:2,AS,NAT_2:13,AS1;
          then consider r,t be
          Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
C16:      r = z.i0 & t = z.(i0+1) &
          (ex P0,Q0 be Element of 4-tuples_on (8-tuples_on BOOLEAN)
          st P0 = r.1 & Q0 = r.m & t.1 = Op-WXOR(P0,KeyExTemp(SBT,m,m*i0,Q0)))
          & for n be Nat st 1 <= n & n < m holds
          ex P be Element of 4-tuples_on (8-tuples_on BOOLEAN),
          Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
          st P = r.(n+1) & Q = t.n &
          t.(n+1) = Op-WXOR(P,KeyExTemp(SBT,m,i0*m+n,Q)) by A2;
          1 <= j & j < m by AS,INT_1:58,LX34,C1,NAT_1:14;
          then consider P be Element of 4-tuples_on (8-tuples_on BOOLEAN),
          Q be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
C18:      P = r.(j+1) & Q = t.j &
          t.(j+1) = Op-WXOR(P,KeyExTemp(SBT,m,i0*m+j,Q)) by C16;
          per cases;
          suppose
NC1:        ((k+1) mod m) <> 0;
NC16:       zi1 = zi by NLX34,NC1,AS,XLMOD01,LX34,C1;
C21:        u.(k+1) = t.(j+1) by NLX34,NC16,NC1,AS,XLMOD02,LX34,C1,C16;
C22X:       km1 = (k+1)-m;
LC12:       i2 = ((k+1) div m)-1+1 by NC1,XLMOD03,C22X,LLX34,AS,XLMOD04
              .= i0 by AS,XLMOD01,NC1;
LC13:       j2 = j1 by LLX34,C22X,XLMOD03,NLX34;
C19:        u.(k-m+1) = r.(j+1)
            by LLX34,LC13,LC12,C16,NLX34,NC1,AS,XLMOD02,LX34,C1;
C22:        k = i0*m+j by AS,INT_1:59,LX34,C1;
            thus ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
            Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
            st P = u.((k-m)+1) & Q = u.k &
            u.(k+1) = Op-WXOR(P,KeyExTemp(SBT,m,k,Q))
            by C18,C19,C16,LX34,C1,C21,C22;
          end;
          suppose
MC1:        ((k+1) mod m) = 0;
NC13:       j1 = m-1+1 by NLX34,MC1
              .= j+1 by AS,XLMOD02X,MC1,LX34;
C21:        u.(k+1) = t.(j+1) by NLX34,MC1,XLMOD01X,NC13,C16;
C22X:       km1 = (k+1)-m;
LC12:       i2 = ((k+1) div m)-1 by C22X,MC1,XLMOD03,LLX34,AS,XLMOD04
              .= (k div m)+1-1 by AS,XLMOD01X,MC1
              .= i0;
C19:        u.(k-m+1) = r.(j+1) by LLX34,C22X,XLMOD03,NLX34,LC12,C16,NC13;
C22:        k = i0*m+j by AS,INT_1:59,LX34,C1;
            thus ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
            Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
            st P = u.((k-m)+1) & Q = u.k &
            u.(k+1) = Op-WXOR(P,KeyExTemp(SBT,m,k,Q))
            by C18,C19,LX34,C16,C1,C21,C22;
          end;
        end;
        suppose
C2:       (k mod m) = 0;
DD1:      ((4*(7+m)) div m)+0 < ((4*(7+m)) div m)+1 by XREAL_1:8;
          k div m <= (4*(7+m)) div m by AS1,NAT_2:24;
          then 1 <= i & i < N2 by DD1,XXREAL_0:2,C2,LX34,AS,NAT_2:13,AS1;
          then consider r,t be
          Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
          such that
C16:      r = z.i & t = z.(i+1) &
          (ex P0,Q0 be Element of 4-tuples_on (8-tuples_on BOOLEAN)
          st P0 = r.1 & Q0 = r.m & t.1 = Op-WXOR(P0,KeyExTemp(SBT,m,m*i,Q0)))
          & for n be Nat st 1 <= n & n < m holds
          ex P be Element of 4-tuples_on (8-tuples_on BOOLEAN),
          Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
          st P = r.(n+1) & Q = t.n &
          t.(n+1) = Op-WXOR(P,KeyExTemp(SBT,m,i*m+n,Q)) by A2;
NC1X:     ((k+1) mod m) = ((0 qua Nat)+1) mod m by C2,NAT_D:23
            .= 1 by NAT_D:14,AS;
C21:      u.(k+1) = t.1 by NLX34,NC1X,AS,XLMOD01,C2,LX34,C16;
C22X:     km1 = (k+1)-m;
LC12:     i2 = ((k+1) div m)-1+1 by NC1X,XLMOD03,C22X,LLX34,AS,XLMOD04
            .= i by AS,XLMOD01,NC1X,C2,LX34;
C19:      u.(k-m+1) = r.1 by LLX34,XLMOD03,C22X,LC12,C16,NC1X;
C22:      k = (k div m)*m+(k mod m) by AS,INT_1:59
            .= i*m by C2,LX34;
          thus ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
          Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
          st P = u.((k-m)+1) & Q = u.k &
          u.(k+1) = Op-WXOR(P,KeyExTemp(SBT,m,k,Q))
          by C19,LX34,C16,C2,C21,C22;
        end;
      end;
      hence P0[x,u] by LX3;
    end;
    consider I be Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
    such that
A2: for x being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let H1,H2 be Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
    assume
AA1: for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Element of NAT st i < m holds (H1.Key).(i+1) = Key.(i+1))
    & (for i be Element of NAT st m <= i & i < 4*(7+m) holds
    ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
    Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
    st P = (H1.Key).((i-m)+1) & Q = (H1.Key).i &
    (H1.Key).(i+1) = Op-WXOR(P,KeyExTemp(SBT,m,i,Q)));
    assume
AA2: for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds (for i be Element of NAT st i < m holds (H2.Key).(i+1) = Key.(i+1))
    & (for i be Element of NAT st m <= i & i < 4*(7+m) holds
    ex P be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
    Q be Element of 4-tuples_on (8-tuples_on BOOLEAN)
    st P = (H2.Key).((i-m)+1) & Q = (H2.Key).i &
    (H2.Key).(i+1) = Op-WXOR(P,KeyExTemp(SBT,m,i,Q)));
    now let input be
    Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      (H1.input) in (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      then
XX1:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st (H1.input) = s & len s = (4*(7+m));
      reconsider H1i = (H1.input) as
      Element of (4-tuples_on (8-tuples_on BOOLEAN))* by XX1;
      (H2.input) in (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      then
XX2:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st (H2.input) = s & len s = (4*(7+m));
      reconsider H2i = (H2.input) as
      Element of (4-tuples_on (8-tuples_on BOOLEAN))* by XX2;
      defpred PN[Nat] means
      (m <= $1 & $1 <= 4*(7+m)) implies for k be Element of NAT
      st 1 <= k & k <= $1 holds (H1.input).k = (H2.input).k;
PN0:  PN[0];
PN1:  for i be Nat st PN[i] holds PN[i+1]
      proof
        let i be Nat;
        assume
A1:     PN[i];
        assume
A2:     m <= i+1 & i+1 <= 4*(7+m);
        per cases;
        suppose
C10:      m = i+1;
          thus for k be Element of NAT st 1 <= k & k <= i+1 holds
          (H1.input).k = (H2.input).k
          proof
            let k be Element of NAT;
            assume
B1:         1 <= k & k <= i+1;
            k-1 < k by XREAL_1:44;
            then
B2:         k-1 < m by C10,B1,XXREAL_0:2;
            reconsider k1 = k-1 as Element of NAT by XREAL_1:48,B1,INT_1:3;
            thus (H1.input).k = input.(k1+1) by B2,AA1
              .= (H2.input).k by B2,AA2;
          end;
        end;
        suppose m <> i+1;
          then
C10X:     m < i+1 by A2,XXREAL_0:1;
          i < i+1 by XREAL_1:29;
          then
C11Z:     i < 4*(7+m) by A2,XXREAL_0:2;
          thus for k be Element of NAT st 1 <= k & k <= i+1 holds
          (H1.input).k = (H2.input).k
          proof
            let k be Element of NAT;
            assume
C13:        1 <= k & k <= i+1;
            then reconsider k1 = k-1 as Element of NAT by XREAL_1:48,INT_1:3;
            per cases;
            suppose
C14:          k1 < m;
              thus (H1.input).k = input.(k1+1) by C14,AA1
                .= (H2.input).k by C14,AA2;
            end;
            suppose
C15:          m <= k1;
              k-1 <= i+1-1 by C13,XREAL_1:9;
              then
C16:          m <= k1 & k1 < 4*(7+m) by C11Z,XXREAL_0:2,C15;
              then consider PP1 be
              Element of (4-tuples_on (8-tuples_on BOOLEAN)),
              QQ1 be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
C17:          PP1 = (H1.input).((k1-m)+1) & QQ1 = (H1.input).k1 &
              (H1.input).(k1+1) = Op-WXOR(PP1,KeyExTemp(SBT,m,k1,QQ1)) by AA1;
              consider PP2 be Element of (4-tuples_on (8-tuples_on BOOLEAN)),
              QQ2 be Element of 4-tuples_on (8-tuples_on BOOLEAN) such that
C18:          PP2 = (H2.input).((k1-m)+1) & QQ2 = (H2.input).k1 &
              (H2.input).(k1+1) = Op-WXOR(PP2,KeyExTemp(SBT,m,k1,QQ2))
              by AA2,C16;
C190:         k-1 <= i+1-1 by XREAL_1:9,C13;
              then
C191:         1 <= k1 & k1 <= i by C15,AS,XXREAL_0:2;
C24X:         0 <= k1-m by C15,XREAL_1:48;
              then
C25X:         1+0 <= k1-m+1 by XREAL_1:6;
              k1-(m-1) <= k1 by AS,XREAL_1:43;
              then
C25:          1 <= (k1-m)+1 & (k1-m)+1 <= i by C190,XXREAL_0:2,C25X;
              reconsider k1m1 = (k1-m)+1 as Element of NAT by C24X,INT_1:3;
C21:          (H1.input).k1m1 = (H2.input).k1m1 by A2,C10X,NAT_1:13,A1,C25;
              thus (H1.input).k = (H2.input).k
              by C21,C17,C18,C191,A2,C10X,NAT_1:13,A1;
            end;
          end;
        end;
      end;
L10:  for i be Nat holds PN[i] from NAT_1:sch 2(PN0,PN1);
L1:   now let i be Element of NAT;
        assume
A1:     m <=i & i <= 4*(7+m);
        1 <= i & i <= i by AS,A1,XXREAL_0:2;
        hence (H1.input).i = (H2.input).i by L10,A1;
      end;
      now let i0 be Nat;
        assume
P13:    1 <= i0 & i0 <= len H1i;
        then reconsider i = i0-1 as Element of NAT by XREAL_1:48,INT_1:3;
        now per cases;
        suppose
C1:       i0 <= m;
          i < i0 by XREAL_1:44;
          then
C11:      i < m by C1,XXREAL_0:2;
          thus H1i.i0 = input.(i+1) by C11,AA1
            .= H2i.i0 by C11,AA2;
        end;
        suppose
C3:       m < i0;
          i+1 in Seg len H1i by P13;
          hence H1i.i0 = H2i.i0 by L1,C3,XX1,P13;
        end;
      end;
      hence H1i.i0 = H2i.i0;
    end;
    hence H1.input = H2.input by XX1,XX2,FINSEQ_1:def 17;
  end;
  hence H1 = H2 by FUNCT_2:63;
end;
end;

definition
  let SBT;
  let m be Nat;
  func KeyExpansion(SBT,m) ->
  Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) means
  for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) holds
  ex w be Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
  st w = (KeyExpansionX(SBT,m)).Key & for i be Nat st i < 7+m
  holds (it.Key).(i+1) = <*w.(4*i+1),w.(4*i+2),w.(4*i+3),w.(4*i+4)*>;
  existence
  proof
    defpred P0[Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    Element of (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))]
    means
    ex w be Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
    st w = (KeyExpansionX(SBT,m)).$1 & for i be Nat st i < 7+m holds
    $2.(i+1) = <*w.(4*i+1),w.(4*i+2),w.(4*i+3),w.(4*i+4)*>;
A1: for x being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    ex z be
    Element of (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
    st P0[x,z]
    proof
      let x be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      reconsider w = (KeyExpansionX(SBT,m)).x as
      Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      w in (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN));
      then
XX1:  ex s be Element of (4-tuples_on (8-tuples_on BOOLEAN))*
      st w = s & len s = (4*(7+m));
      reconsider w0 = w as
      Element of (4-tuples_on (8-tuples_on BOOLEAN))* by XX1;
      reconsider m7 = 7+m as Element of NAT by ORDINAL1:def 12;
      reconsider m47 = (4*(7+m)) as Element of NAT by ORDINAL1:def 12;
      defpred P[Nat,set] means
      ex n be Element of NAT st n = $1-1 &
      $2 = <*w.(4*n+1),w.(4*n+2),w.(4*n+3),w.(4*n+4)*>;
P1:   for k be Nat st k in Seg m7
      ex z being Element of 4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
      st P[k,z]
      proof
        let k be Nat;
        assume k in Seg m7;
        then
ZZ1:    1 <= k & k <= m7 by FINSEQ_1:1;
        then reconsider n = k-1 as Element of NAT by XREAL_1:48,INT_1:3;
ZZ3:    4*(n+1) <= 4*m7 by ZZ1,XREAL_1:64;
ZZ4:    0+1 <= 4*n+1 by XREAL_1:7;
ZZ7:    4*n+1 <= 4*n+4 by XREAL_1:7;
ZZ8:    4*n+2 <= 4*n+4 by XREAL_1:7;
ZZ9:    4*n+3 <= 4*n+4 by XREAL_1:7;
        4*n+1 <= 4*m7 by ZZ7,ZZ3,XXREAL_0:2;
        then
X1:     (4*n+1) in Seg m47 by ZZ4;
ZZ10:   1 <= 4*n+2 by ZZ4,XREAL_1:7;
        4*n+2 <= 4*m7 by ZZ8,ZZ3,XXREAL_0:2;
        then
X2:     (4*n+2) in Seg m47 by ZZ10;
ZZ11:   1 <= 4*n+3 by ZZ4,XREAL_1:7;
        4*n+3 <= 4*m7 by ZZ9,ZZ3,XXREAL_0:2;
        then
X3:     (4*n+3) in Seg m47 by ZZ11;
ZZ12:   1 <= 4*n+4 by ZZ4,XREAL_1:7;
X4:     (4*n+4) in Seg m47 by ZZ3,ZZ12;
X5:     dom w = Seg m47 by FINSEQ_1:def 3,XX1;
        w.(4*n+1) in rng w by X5,X1,FUNCT_1:3;
        then reconsider w1 = w.(4*n+1) as
        Element of (4-tuples_on (8-tuples_on BOOLEAN));
        w.(4*n+2) in rng w by X5,X2,FUNCT_1:3;
        then reconsider w2 = w.(4*n+2) as
        Element of (4-tuples_on (8-tuples_on BOOLEAN));
        w.(4*n+3) in rng w by X5,X3,FUNCT_1:3;
        then reconsider w3 = w.(4*n+3) as
        Element of (4-tuples_on (8-tuples_on BOOLEAN));
        w.(4*n+4) in rng w by X5,X4,FUNCT_1:3;
        then reconsider w4 = w.(4*n+4) as
        Element of (4-tuples_on (8-tuples_on BOOLEAN));
        reconsider z = <*w1,w2,w3,w4*> as
        Element of 4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) by LMGSEQ4;
        z = <*w.(4*n+1),w.(4*n+2),w.(4*n+3),w.(4*n+4)*>;
        hence thesis;
      end;
      consider p being
      FinSequence of 4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) such that
P3:   dom p = Seg m7 & for k be Nat st k in Seg m7 holds P[k,p.k]
      from FINSEQ_1:sch 5(P1);
P4:   len p = m7 by P3,FINSEQ_1:def 3;
      p in (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
      by FINSEQ_1:def 11;
      then p in m7-tuples_on (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))
      by P4;
      then reconsider p as Element of
      (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
      take p;
      now let i be Nat;
        assume i < 7+m;
        then
AA2:    i+1 <= 7+m by NAT_1:13;
        1 <= i+1 by NAT_1:11;
        then i+1 in Seg m7 by AA2;
        then ex n be Element of NAT st n = (i+1)-1 &
        p.(i+1) = <*w.(4*n+1),w.(4*n+2),w.(4*n+3),w.(4*n+4)*> by P3;
        hence p.(i+1) = <*w.(4*i+1),w.(4*i+2),w.(4*i+3),w.(4*i+4)*>;
      end;
      hence thesis;
    end;
    consider I be Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
A2: for x being Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds P0[x,I.x] from FUNCT_2:sch 3(A1);
    take I;
    thus thesis by A2;
  end;
  uniqueness
  proof
    let H1,H2 be Function of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
    assume
A1: for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) holds
    ex w be Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
    st w = (KeyExpansionX(SBT,m)).Key & for i be Nat st i < 7+m holds
    (H1.Key).(i+1) = <*w.(4*i+1),w.(4*i+2),w.(4*i+3),w.(4*i+4)*>;
    assume
A2: for Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) holds
    ex w be Element of (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN))
    st w = (KeyExpansionX(SBT,m)).Key & for i be Nat st i <7+m holds
    (H2.Key).(i+1) = <*w.(4*i+1),w.(4*i+2),w.(4*i+3),w.(4*i+4)*>;
    now let input be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      consider w1 be Element of
      (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) such that
P1:   w1 = (KeyExpansionX(SBT,m)).input &
      for i be Nat st i < 7+m holds
      (H1.input).(i+1) = <*w1.(4*i+1),w1.(4*i+2),w1.(4*i+3),w1.(4*i+4)*> by A1;
      consider w2 be Element of
      (4*(7+m))-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)) such that
P2:   w2 = (KeyExpansionX(SBT,m)).input &
      for i be Nat st i < 7+m holds
      (H2.input).(i+1) = <*w2.(4*i+1),w2.(4*i+2),w2.(4*i+3),w2.(4*i+4)*> by A2;
      (H1.input) in
      (7+m)-tuples_on(4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)));
      then
P3:   ex s be Element of (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
      st (H1.input) = s & len s = (7+m);
      (H2.input) in
      (7+m)-tuples_on (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
      then
P4:   ex s be Element of (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
      st (H2.input) = s & len s = (7+m);
      now let i be Nat;
        assume
P5:     1 <= i & i <= len (H1.input);
        then i-1 in NAT by XREAL_1:48,INT_1:3;
        then reconsider i0 = i-1 as Nat;
        i < (7+m)+1 by P3,P5,NAT_1:13;
        then
P6:     i-1 < (7+m)+1-1 by XREAL_1:14;
        thus (H1.input).i = (H1.input).(i0+1)
          .= <*w2.(4*i0+1),w2.(4*i0+2),w2.(4*i0+3),w2.(4*i0+4)*> by P6,P1,P2
          .= (H2.input).(i0+1) by P6,P2
          .= (H2.input).i;
      end;
      hence
      (H1.input) = (H2.input) by P3,P4,FINSEQ_1:def 17;
    end;
    hence H1 = H2 by FUNCT_2:63;
  end;
end;

begin :: Encryption and Decryption

reserve MCFunc for Permutation of
4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
reserve MixColumns for
Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));

definition
  let SBT;
  let MCFunc;
  let m be Nat;
  let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  let Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  func AES-ENC(SBT,MCFunc,text,Key) ->
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :defENC:
  ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
  st len seq = 7+m-1 & (ex Keyi1 be Element of
  4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
  seq.1 = AddRoundKey.(text,Keyi1)) &
  (for i be Nat st 1 <= i & i < 7+m-1 holds
  ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) &
  seq.(i+1) = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq.i),Keyi)) &
  ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
  it = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq.(7+m-1)),KeyNr);
  existence
  proof
    1+0 < 7+m by XREAL_1:8;
    then
N1: 0 < 7+m-1 by XREAL_1:50;
    then 7+m-1 in NAT by INT_1:3;
    then reconsider Nr = 7+m-1 as Nat;
ZZ1: (KeyExpansion(SBT,m)).(Key) in
    (Nr+1)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
    reconsider kky = (KeyExpansion(SBT,m)).(Key) as Element of
    (Nr+1)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
XX12: ex s be Element of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))*
    st kky = s & len s = (Nr+1) by ZZ1;
    defpred P[Nat,set,set] means
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = ((KeyExpansion(SBT,m)).(Key)).($1+1) &
    $3 = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).$2,Keyi);
    1+0 <= 7+m by XREAL_1:7;
    then 1 in Seg (Nr+1);
    then 1 in dom (kky) by FINSEQ_1:def 3,XX12;
    then ((KeyExpansion(SBT,m)).(Key)).1 in rng kky by FUNCT_1:3;
    then reconsider Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    reconsider I0 = AddRoundKey.(text,Keyi1) as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
X1: for n being Nat st 1 <= n & n < Nr
    for z being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds ex y being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P[n,z,y]
    proof
      let n be Nat;
      assume
X11:  1 <= n & n < Nr;
      let z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
X111: n+1 <= Nr+1 by XREAL_1:7,X11;
      0+1 <= n+1 by XREAL_1:7;
      then n+1 in Seg (Nr+1) by X111;
      then n+1 in dom (kky) by FINSEQ_1:def 3,XX12;
      then ((KeyExpansion(SBT,m)).(Key)).(n+1) in rng kky by FUNCT_1:3;
      then reconsider Keyi = ((KeyExpansion(SBT,m)).(Key)).(n+1) as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      reconsider y = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).z,Keyi) as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      take y;
      thus P[n,z,y];
    end;
    consider seq be
    FinSequence of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
X2: len seq = Nr & (seq.1 = I0 or Nr = 0) &
    for i be Nat st 1 <= i & i < Nr holds P[i,seq.i,seq.(i+1)]
    from RECDEF_1:sch 4(X1);
    Nr in Seg Nr by FINSEQ_1:3,N1;
    then
    Nr in dom seq by FINSEQ_1:def 3,X2;
    then seq.Nr in rng seq by FUNCT_1:3;
    then reconsider seq10 = seq.Nr as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    Nr+1 in Seg (Nr+1) by FINSEQ_1:3;
    then Nr+1 in dom (kky) by FINSEQ_1:def 3,XX12;
    then ((KeyExpansion(SBT,m)).(Key)).(Nr+1) in rng kky by FUNCT_1:3;
    then reconsider KeyNr = ((KeyExpansion(SBT,m)).(Key)).(Nr+1) as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    reconsider w = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq10),KeyNr) as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    w = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq.Nr),KeyNr);
    hence thesis by XREAL_1:8,X2;
  end;
  uniqueness
  proof
    let s1,s2 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    1+0 < 7+m by XREAL_1:8;
    then 0 < 7+m-1 by XREAL_1:50;
    then 7+m-1 in NAT by INT_1:3;
    then reconsider Nr = 7+m-1 as Nat;
    assume
A1: ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
    st len seq = 7+m-1 &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
    seq.1 = AddRoundKey.(text,Keyi1)) & (for i be Nat st 1 <= i & i < 7+m-1
    holds ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) &
    seq.(i+1) = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq.i),Keyi)) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
    s1 = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq.(7+m-1)),KeyNr);
    assume
A2: ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
    st len seq = 7+m-1 &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
    seq.1 = AddRoundKey.(text,Keyi1)) & (for i be Nat st 1 <= i & i < 7+m-1
    holds ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) &
    seq.(i+1) = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq.i),Keyi)) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
    s2 = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq.(7+m-1)),KeyNr);
    consider seq1 be
    FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P1: len seq1 = Nr &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
    seq1.1 = AddRoundKey.(text,Keyi1)) & (for i be Nat st 1 <= i & i < Nr
    holds ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) &
    seq1.(i+1) = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq1.i),Keyi))
    & ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(Nr+1) &
    s1 = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq1.(Nr)),KeyNr) by A1;
    consider seq2 be
    FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P2: len seq2 = Nr &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
    seq2.1 = AddRoundKey.(text,Keyi1)) & (for i be Nat st 1 <= i & i < Nr
    holds ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) &
    seq2.(i+1) = AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq2.i),Keyi))
    & ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(Nr+1) &
    s2 = AddRoundKey.((ShiftRows*SubBytes(SBT)).(seq2.(Nr)),KeyNr) by A2;
    defpred EQ[Nat] means
    1 <= $1 & $1 <= len seq1 implies seq1.$1 = seq2.$1;
Q50: EQ[0];
Q51: for i be Nat st EQ[i] holds EQ[i+1]
    proof
      let i be Nat;
      assume
Q52:  EQ[i];
      assume 1 <= i+1 & i+1 <= len seq1;
      then
Q54:  1-1 <= i+1-1 & i+1-1 <= len seq1-1 by XREAL_1:9;
Q550: (len seq1)-1 <= (len seq1)-0 by XREAL_1:13;
      per cases;
      suppose
C1:     i = 0;
        thus seq1.(i+1) = seq2.(i+1) by C1,P1,P2;
      end;
      suppose
Q560:   i <> 0;
        Nr-1 < Nr-0 by XREAL_1:15;
        then
XX1:    1 <= i & i < Nr by Q560,NAT_1:14,P1,Q54,XXREAL_0:2;
        then
Q60:    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) & seq1.(i+1) =
        AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq1.i),Keyi) by P1;
        ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) & seq2.(i+1) =
        AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(seq2.i),Keyi) by P2,XX1;
        hence seq1.(i+1) = seq2.(i+1)
        by Q560,NAT_1:14,Q550,Q54,XXREAL_0:2,Q52,Q60;
      end;
    end;
    for i be Nat holds EQ[i] from NAT_1:sch 2(Q50,Q51);
    hence s1 = s2 by P1,P2,FINSEQ_1:14;
  end;
end;

definition
  let SBT;
  let MCFunc;
  let m be Nat;
  let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  let Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  func AES-DEC(SBT,MCFunc,text,Key) ->
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  :defDEC:
  ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
  st len seq = 7+m-1 &
  (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  seq.1 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))) &
  (for i be Nat st 1 <= i & i < 7+m-1 holds
  ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
  seq.(i+1) =
  (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq.i,Keyi))) &
  ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
  it = AddRoundKey.(seq.(7+m-1),KeyNr);
  existence
  proof
    1+0 < 7+m by XREAL_1:8;
    then
N1: 0 < 7+m-1 by XREAL_1:50;
    then 7+m-1 in NAT by INT_1:3;
    then reconsider Nr = 7+m-1 as Nat;
ZZ1: Rev((KeyExpansion(SBT,m)).(Key)) in
    (Nr+1)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
    reconsider kky = Rev((KeyExpansion(SBT,m)).(Key)) as Element of
    (Nr+1)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
XX12: ex s be Element of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))*
    st kky = s & len s = Nr+1 by ZZ1;
    defpred P[Nat,set,set] means
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).($1+1) &
    $3 = (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.($2,Keyi));
    1+0 <= 7+m by XREAL_1:7;
    then 1 in Seg (Nr+1);
    then 1 in dom (kky) by FINSEQ_1:def 3,XX12;
    then (Rev((KeyExpansion(SBT,m)).(Key))).1 in rng kky by FUNCT_1:3;
    then reconsider Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    reconsider I0 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))
    as Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
X1: for n being Nat st 1 <= n & n < Nr
    for z being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    holds ex y being Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st P[n,z,y]
    proof
      let n be Nat;
      assume
X11:  1 <= n & n < Nr;
      let z be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
X111: n+1 <= Nr+1 by XREAL_1:7,X11;
      0+1 <= n+1 by XREAL_1:7;
      then n+1 in Seg (Nr+1) by X111;
      then n+1 in dom (kky) by FINSEQ_1:def 3,XX12;
      then (Rev((KeyExpansion(SBT,m)).(Key))).(n+1) in rng kky by FUNCT_1:3;
      then reconsider Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(n+1) as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      reconsider y =
      (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(z,Keyi)) as
      Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
      take y;
      thus P[n,z,y];
    end;
    consider seq be
    FinSequence of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) such that
X2: len seq = Nr & (seq.1 = I0 or Nr = 0) &
    for i be Nat st 1 <= i & i < Nr holds P[i,seq.i,seq.(i+1)]
    from RECDEF_1:sch 4(X1);
    Nr in Seg Nr by FINSEQ_1:3,N1;
    then Nr in dom seq by FINSEQ_1:def 3,X2;
    then seq.Nr in rng seq by FUNCT_1:3;
    then reconsider seq10 = seq.Nr as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    Nr+1 in Seg (Nr+1) by FINSEQ_1:3;
    then Nr+1 in dom (kky) by FINSEQ_1:def 3,XX12;
    then (Rev((KeyExpansion(SBT,m)).(Key))).(Nr+1) in rng kky by FUNCT_1:3;
    then reconsider KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(Nr+1) as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    reconsider w = AddRoundKey.((seq10),KeyNr) as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    w = AddRoundKey.(seq.Nr,KeyNr);
    hence thesis by X2,XREAL_1:8;
  end;
  uniqueness
  proof
    let s1,s2 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    1+0 < 7+m by XREAL_1:8;
    then 0 < 7+m-1 by XREAL_1:50;
    then 7+m-1 in NAT by INT_1:3;
    then reconsider Nr = 7+m-1 as Nat;
    assume
A1: ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
    st len seq = 7+m-1 &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
    seq.1 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))) &
    (for i be Nat st 1 <= i & i < 7+m-1 holds
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
    seq.(i+1) =
    (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq.i,Keyi))) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
    s1 = AddRoundKey.(seq.(7+m-1),KeyNr);
    assume
A2: ex seq be FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))
    st len seq = 7+m-1 &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
    seq.1 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))) &
    (for i be Nat st 1 <= i & i < 7+m-1 holds
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
    seq.(i+1) =
    (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq.i,Keyi))) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
    s2 = AddRoundKey.(seq.(7+m-1),KeyNr);
    consider seq1 be
    FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P1: len seq1 = Nr &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
    seq1.1 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))) &
    (for i be Nat st 1 <= i & i < Nr holds
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
    seq1.(i+1) =
    (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq1.i,Keyi))) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
    s1 = AddRoundKey.(seq1.(7+m-1),KeyNr) by A1;
    consider seq2 be
    FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P2: len seq2 = Nr &
    (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
    seq2.1 = (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(text,Keyi1))) &
    (for i be Nat st 1 <= i & i < Nr holds
    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
    seq2.(i+1) =
    (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq2.i,Keyi))) &
    ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
    s2 = AddRoundKey.(seq2.(7+m-1),KeyNr) by A2;
    defpred EQ[Nat] means
    1 <= $1 & $1 <= len seq1 implies seq1.$1 = seq2.$1;
Q50: EQ[0];
Q51: for i be Nat st EQ[i] holds EQ[i+1]
    proof
      let i be Nat;
      assume
Q52:  EQ[i];
      assume 1 <= i+1 & i+1 <= len seq1;
      then
Q54:  1-1 <= i+1-1 & i+1-1 <= (len seq1)-1 by XREAL_1:9;
Q550: (len seq1)-1 <= (len seq1)-0 by XREAL_1:13;
      per cases;
      suppose
C1:     i = 0;
        thus seq1.(i+1) = seq2.(i+1) by C1,P1,P2;
      end;
      suppose
Q560:   i <> 0;
        Nr-1 < Nr-0 by XREAL_1:15;
        then
XX1:    1 <= i & i < Nr by Q560,NAT_1:14,P1,Q54,XXREAL_0:2;
        then
Q60:    ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
        seq1.(i+1) =
        (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq1.i,Keyi))
        by P1;
        ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
        st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
        seq2.(i+1) =
        (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(seq2.i,Keyi))
        by P2,XX1;
        hence seq1.(i+1) = seq2.(i+1)
        by Q560,NAT_1:14,Q550,Q54,XXREAL_0:2,Q52,Q60;
      end;
    end;
    for i be Nat holds EQ[i] from NAT_1:sch 2(Q50,Q51);
    hence s1 = s2 by FINSEQ_1:14,P1,P2;
  end;
end;

theorem INV01:
  for input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds (MCFunc").(MCFunc.input) = input
proof
  let input be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  thus (MCFunc").(MCFunc.(input)) = ((MCFunc")*MCFunc).input by FUNCT_2:15
    .= (id (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))).input
    by FUNCT_2:61
    .= input;
end;

theorem
  for output be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  holds MCFunc.((MCFunc").output) = output
proof
  let output be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  thus (MCFunc).((MCFunc").(output)) = (MCFunc*(MCFunc")).output by FUNCT_2:15
    .= (id (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)))).output
    by FUNCT_2:61
    .= output;
end;

theorem LAST01:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) holds
  (InvSubBytes(SBT)*InvShiftRows).((ShiftRows*SubBytes(SBT)).text) = text
proof
  let m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  thus (InvSubBytes(SBT)*InvShiftRows).((ShiftRows*SubBytes(SBT)).text) =
  (InvSubBytes(SBT)*InvShiftRows).(ShiftRows.((SubBytes(SBT)).text))
  by FUNCT_2:15
    .= (InvSubBytes(SBT)).(InvShiftRows.(ShiftRows.((SubBytes(SBT)).text)))
    by FUNCT_2:15
    .= (InvSubBytes(SBT)). ((SubBytes(SBT)).text) by INV04
    .= text by INV07;
end;

theorem LAST02:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) holds
  (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).
  ((MCFunc*ShiftRows*SubBytes(SBT)).text) = text
proof
  let m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  thus (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).
  ((MCFunc*ShiftRows*SubBytes(SBT)).text) =
  (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).
  ((MCFunc*ShiftRows).((SubBytes(SBT)).text)) by FUNCT_2:15
    .= (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).
    (MCFunc.(ShiftRows.((SubBytes(SBT)).text))) by FUNCT_2:15
    .= (InvSubBytes(SBT)*InvShiftRows).((MCFunc").
    (MCFunc.(ShiftRows.((SubBytes(SBT)).text)))) by FUNCT_2:15
    .= (InvSubBytes(SBT)*InvShiftRows).(ShiftRows.((SubBytes(SBT)).text))
    by INV01
    .= (InvSubBytes(SBT)).(InvShiftRows.(ShiftRows.((SubBytes(SBT)).text)))
    by FUNCT_2:15
    .= (InvSubBytes(SBT)).((SubBytes(SBT)).text) by INV04
    .= text by INV07;
end;

theorem LAST03:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  dkeyi,ekeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & dkeyi = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  ekeyi = ((KeyExpansion(SBT,m)).(Key)).(7+m)
  holds AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi) = text
proof
  let m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  dkeyi,ekeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & dkeyi = (Rev((KeyExpansion(SBT,m)).(key))).1 &
  ekeyi = ((KeyExpansion(SBT,m)).(key)).(7+m);
  set p = (KeyExpansion(SBT,m)).(key);
  (KeyExpansion(SBT,m)).(key) in
  (7+m)-tuples_on(4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)));
  then
B0: ex s be Element of (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
  st (KeyExpansion(SBT,m)).(key) = s & len s = (7+m);
  1+0 < 7+m by XREAL_1:8;
  then 1 in Seg (7+m);
  then
B1: 1 in dom p by FINSEQ_1:def 3,B0;
A0: dkeyi = p.((len p)-1+1) by AS,FINSEQ_5:58,B1
    .= ekeyi by B0,AS;
  now let i,j be Nat;
    assume
A3: i in Seg 4 & j in Seg 4;
    then consider etextij,ekeyij be Element of 8-tuples_on BOOLEAN such that
A4: etextij = (text.i).j & ekeyij = (ekeyi.i).j &
    ((AddRoundKey.(text,ekeyi)).i).j = Op-XOR(etextij,ekeyij)
    by DefAddRoundKey;
    consider dtextij,dkeyij be Element of 8-tuples_on BOOLEAN such that
A5: dtextij = ((AddRoundKey.(text,ekeyi)).i).j & dkeyij = (dkeyi.i).j &
    ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j =
    Op-XOR(dtextij,dkeyij) by DefAddRoundKey,A3;
    thus ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j = (text.i).j
    by A4,A5,A0,DESCIP_1:17;
  end;
  hence AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi) = text by LM01;
end;

LAST04:
  for m be Nat,
  text,otext be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Keyi1,KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
  otext = AddRoundKey.((ShiftRows*SubBytes(SBT)).text,KeyNr)
  holds (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(otext,Keyi1)) = text
proof
  let m be Nat,
  text,otext be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Keyi1,KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
  otext = AddRoundKey.((ShiftRows*SubBytes(SBT)).text,KeyNr);
  (AddRoundKey.(otext,Keyi1)) = (ShiftRows*SubBytes(SBT)).text by AS,LAST03;
  hence (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey. (otext,Keyi1))
  = text by LAST01;
end;

theorem LAST05:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  dkeyi,ekeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & dkeyi = ((KeyExpansion(SBT,m)).(key)).1 &
  ekeyi = (Rev((KeyExpansion(SBT,m)).(key))).(7+m)
  holds AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi) = text
proof
  let m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  dkeyi,ekeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & dkeyi = ((KeyExpansion(SBT,m)).(key)).1 &
  ekeyi = (Rev((KeyExpansion(SBT,m)).(key))).(7+m);
  set p = (KeyExpansion(SBT,m)).(key);
  (KeyExpansion(SBT,m)).(key) in
  (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
  then
B0: ex s be Element of (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
  st (KeyExpansion(SBT,m)).(key) = s & len s = (7+m);
  1+0 < 7+m by XREAL_1:8;
  then 7+m in Seg (7+m);
  then
B1: 7+m in dom p by FINSEQ_1:def 3,B0;
A0: ekeyi = p.((len p)-(7+m)+1) by AS,FINSEQ_5:58,B1
    .= dkeyi by B0,AS;
  now let i,j be Nat;
    assume
A3: i in Seg 4 & j in Seg 4;
    then consider etextij,ekeyij be Element of 8-tuples_on BOOLEAN such that
A4: etextij = (text.i).j & ekeyij = (ekeyi.i).j &
    ((AddRoundKey.(text,ekeyi)).i).j = Op-XOR(etextij,ekeyij)
    by DefAddRoundKey;
    consider dtextij,dkeyij be Element of 8-tuples_on BOOLEAN such that
A5: dtextij = ((AddRoundKey.(text,ekeyi)).i).j & dkeyij = (dkeyi.i).j &
    ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j =
    Op-XOR(dtextij,dkeyij) by DefAddRoundKey,A3;
    thus ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j =
    (text.i).j by A4,A5,A0,DESCIP_1:17;
  end;
  hence AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi) = text by LM01;
end;

theorem
  for m be Nat,
  text,otext be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Keyi1,KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
  KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
  otext = AddRoundKey.((ShiftRows*SubBytes(SBT)).text,KeyNr)
  holds (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(otext,Keyi1)) = text
proof
  let m be Nat,
  text,otext be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Keyi1,KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
  KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
  otext = AddRoundKey.((ShiftRows*SubBytes(SBT)).text,KeyNr);
  (AddRoundKey.(otext,Keyi1)) = (ShiftRows*SubBytes(SBT)).text by AS,LAST05;
  hence (InvSubBytes(SBT)*InvShiftRows).(AddRoundKey.(otext,Keyi1)) = text
  by LAST01;
end;

theorem LAST08:
  for m,i be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  eKeyi,dKeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & i <= 7+m-1 &
  eKeyi = ((KeyExpansion(SBT,m)).(Key)).(7+m-i) &
  dKeyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1)
  holds AddRoundKey.(AddRoundKey.(text,eKeyi),dKeyi) = text
proof
  let m,i be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  ekeyi,dkeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & i <= 7+m-1 &
  ekeyi = ((KeyExpansion(SBT,m)).(key)).(7+m-i) &
  dkeyi = (Rev((KeyExpansion(SBT,m)).(key))).(i+1);
  set p = (KeyExpansion(SBT,m)).(key);
  (KeyExpansion(SBT,m)).(key) in
  (7+m)-tuples_on(4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)));
  then
B0: ex s be Element of (4-tuples_on (4-tuples_on (8-tuples_on BOOLEAN)))*
  st (KeyExpansion(SBT,m)).(key) = s & len s = (7+m);
  i+1 <= 7+m-1+1 by AS,XREAL_1:7;
  then 1 <= i+1 & i+1 <= 7+m by NAT_1:11;
  then i+1 in Seg (7+m);
  then
B1: i+1 in dom p by FINSEQ_1:def 3,B0;
A0: dkeyi = p.((len p)-(i+1)+1) by AS,FINSEQ_5:58,B1
    .= ekeyi by B0,AS;
  now let i,j be Nat;
    assume
A3: i in Seg 4 & j in Seg 4;
    then consider etextij,ekeyij be Element of 8-tuples_on BOOLEAN such that
A4: etextij = (text.i).j & ekeyij = (ekeyi.i).j &
    ((AddRoundKey.(text,ekeyi)).i).j = Op-XOR(etextij,ekeyij)
    by DefAddRoundKey;
    consider dtextij,dkeyij be Element of 8-tuples_on BOOLEAN such that
A5: dtextij = ((AddRoundKey.(text,ekeyi)).i).j & dkeyij = (dkeyi.i).j &
    ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j =
    Op-XOR(dtextij,dkeyij) by DefAddRoundKey,A3;
    thus ((AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi)).i).j =
    (text.i).j by A4,A5,A0,DESCIP_1:17;
  end;
  hence AddRoundKey.(AddRoundKey.(text,ekeyi),dkeyi) = text by LM01;
end;

LAST07:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  eKeyi,dKeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8) & eKeyi = ((KeyExpansion(SBT,m)).(Key)).1 &
  dKeyi = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m)
  holds AddRoundKey.(AddRoundKey.(text,eKeyi),dKeyi) = text
proof
  let m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  eKeyi,dKeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  assume
AS: (m = 4 or m = 6 or m = 8) & eKeyi = ((KeyExpansion(SBT,m)).(Key)).1 &
  dKeyi = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m);
  1+0 < 7+m by XREAL_1:8;
  then 0 < 7+m-1 by XREAL_1:50;
  then 7+m-1 in NAT by INT_1:3;
  then reconsider i = 7+m-1 as Nat;
P2: eKeyi = ((KeyExpansion(SBT,m)).(Key)).(7+m-i) by AS;
  dKeyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) by AS;
  hence thesis by AS,P2,LAST08;
end;

theorem LASTXX:
  for m be Nat,
  text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st (m = 4 or m = 6 or m = 8)
  holds AES-DEC(SBT,MCFunc,AES-ENC(SBT,MCFunc,text,Key),Key) = text
proof
  let m be Nat;
  let text be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  let Key be Element of m-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  1+0 < 7+m by XREAL_1:8;
  then
N1: 0 < 7+m-1 by XREAL_1:50;
  then 7+m-1 in NAT by INT_1:3;
  then reconsider Nr = 7+m-1 as Nat;
A0: 1 <= Nr by NAT_1:14,N1;
  assume
AS: (m = 4 or m = 6 or m = 8);
  consider eseq be
  FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P1: len eseq = Nr &
  (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
  eseq.1 = AddRoundKey.(text,Keyi1)) & (for i be Nat st 1 <= i & i < Nr holds
  ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi = ((KeyExpansion(SBT,m)).(Key)).(i+1) & eseq.(i+1) =
  AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(eseq.i),Keyi)) &
  ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st KeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
  AES-ENC(SBT,MCFunc,text,Key) =
  AddRoundKey.((ShiftRows*SubBytes(SBT)).(eseq.Nr),KeyNr) by defENC;
  consider dseq be
  FinSequence of (4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))) such that
P2: len dseq = Nr &
  (ex Keyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  dseq.1 = (InvSubBytes(SBT)*InvShiftRows).
  (AddRoundKey.(AES-ENC(SBT,MCFunc,text,Key),Keyi1))) &
  (for i be Nat st 1 <= i & i < Nr holds
  ex Keyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st Keyi = (Rev((KeyExpansion(SBT,m)).(Key))).(i+1) &
  dseq.(i+1) =
  (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(dseq.i,Keyi))) &
  ex KeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  st KeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
  AES-DEC(SBT,MCFunc,AES-ENC(SBT,MCFunc,text,Key),Key) =
  AddRoundKey.(dseq.Nr,KeyNr) by defDEC;
  consider eKeyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  such that
P11: eKeyi1 = ((KeyExpansion(SBT,m)).(Key)).1 &
  eseq.1 = AddRoundKey.(text,eKeyi1) by P1;
  consider eKeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  such that
P12: eKeyNr = ((KeyExpansion(SBT,m)).(Key)).(7+m) &
  AES-ENC(SBT,MCFunc,text,Key) =
  AddRoundKey.((ShiftRows*SubBytes(SBT)).(eseq.Nr),eKeyNr) by P1;
  consider dKeyi1 be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  such that
P21: dKeyi1 = (Rev((KeyExpansion(SBT,m)).(Key))).1 &
  dseq.1 = (InvSubBytes(SBT)*InvShiftRows).
  (AddRoundKey.(AES-ENC(SBT,MCFunc,text,Key),dKeyi1)) by P2;
  consider dKeyNr be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
  such that
P22: dKeyNr = (Rev((KeyExpansion(SBT,m)).(Key))).(7+m) &
  AES-DEC(SBT,MCFunc,AES-ENC(SBT,MCFunc,text,Key),Key) =
  AddRoundKey.(dseq.Nr,dKeyNr) by P2;
  defpred PQ[Nat] means
  $1 < Nr implies dseq.($1+1) = eseq.(Nr-$1);
  Nr in Seg Nr by A0;
  then Nr in dom eseq by P1,FINSEQ_1:def 3;
  then eseq.Nr in rng eseq by FUNCT_1:3;
  then reconsider esqm = eseq.Nr as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  dseq.(1+0) = esqm by P12,P21,AS,LAST04
    .= eseq.(Nr-0);
  then
PN1: PQ[0];
PN2: for i be Nat st PQ[i] holds PQ[i+1]
  proof
    let i be Nat;
    assume
A1: PQ[i];
    assume
A2: i+1 < Nr;
A4: i <= i+1 by NAT_1:11;
    consider dKeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    such that
A6: dKeyi = (Rev((KeyExpansion(SBT,m)).(Key))).((i+1)+1) &
    dseq.((i+1)+1) =
    (InvSubBytes(SBT)*InvShiftRows*(MCFunc")).(AddRoundKey.(dseq.(i+1),dKeyi))
    by P2,A2,NAT_1:11;
X11: 0 < Nr-(i+1) by A2,XREAL_1:50;
    then Nr-(i+1) in NAT by INT_1:3;
    then reconsider m7i1 = Nr-(i+1) as Nat;
    1 <= m7i1 by NAT_1:14,X11;
    then
A9: 1 <= Nr-(i+1) & Nr-(i+1) < Nr by XREAL_1:44;
    consider eKeyi be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    such that
A10: eKeyi = ((KeyExpansion(SBT,m)).(Key)).(m7i1+1) &
    eseq.(m7i1+1) =
    AddRoundKey.((MCFunc*ShiftRows*SubBytes(SBT)).(eseq.(m7i1)),eKeyi)
    by P1,A9;
    m7i1 in Seg Nr by A9;
    then m7i1 in dom eseq by P1,FINSEQ_1:def 3;
    then eseq.m7i1 in rng eseq by FUNCT_1:3;
    then reconsider esq7mi1 = eseq.m7i1 as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    reconsider MSSesq7mi1 = (MCFunc*ShiftRows*SubBytes(SBT)).esq7mi1 as
    Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
XXX: eKeyi = ((KeyExpansion(SBT,m)).(Key)).(7+m-(i+1)) by A10;
A12: AddRoundKey.(eseq.(Nr-i),dKeyi) = MSSesq7mi1 by A10,A2,AS,A6,XXX,LAST08;
    thus dseq.((i+1)+1) = eseq.(Nr-(i+1)) by A6,A4,A2,XXREAL_0:2,A1,A12,LAST02;
  end;
P30: for k be Nat holds PQ[k] from NAT_1:sch 2(PN1,PN2);
  5+m < 6+m by XREAL_1:8;
  then
P31: dseq.(5+m+1) = eseq.(Nr-(5+m)) by P30;
  1 <= 1 & 1 <= 1+(5+m) by NAT_1:11;
  then 1 in Seg Nr;
  then 1 in dom eseq by P1,FINSEQ_1:def 3;
  then eseq.1 in rng eseq by FUNCT_1:3;
  then reconsider esq1 = eseq.1 as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  thus AES-DEC(SBT,MCFunc,AES-ENC(SBT,MCFunc,text,Key),Key) = text
  by P22,P31,P11,AS,LAST07;
end;

theorem LR8D1:
  for D be non empty set, n,m be non zero Element of NAT,
  r be Element of n-tuples_on D st m <= n & 8 <= n-m
  holds Op-Left(Op-Right(r,m),8) is Element of 8-tuples_on D
proof
  let D be non empty set,
  n,m be non zero Element of NAT,
  r be Element of n-tuples_on D;
  assume
A1: m <= n & 8 <= n-m;
  r in { s where s is Element of D*: len s = n};
  then consider s be Element of D* such that
A2: r = s & len s = n;
  len Op-Right(r,m) = n - m by A1,A2,RFINSEQ:def 1;
  then len(Op-Left(Op-Right(r,m),8)) = 8 by A1,FINSEQ_1:59;
  hence thesis by FINSEQ_2:92;
end;

Lm1:
  for D be non empty set, n be non zero Element of NAT,
  r be Element of n-tuples_on D st 8 <= n & 8 <= n-8 & 16 <= n &
  8 <= n-16 & 24 <= n & 8 <= n-24
  holds <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),Op-Left(Op-Right(r,16),8),
  Op-Left(Op-Right(r,24),8) *> is Element of 4-tuples_on (8-tuples_on D)
proof
  let D be non empty set, n be non zero Element of NAT,
  r be Element of n-tuples_on D;
  assume 8 <= n & 8 <= n-8 & 16 <= n & 8 <= n-16 & 24 <= n & 8 <= n-24;
  then Op-Left(r,8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,8),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,16),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,24),8) is Element of 8-tuples_on D by DESCIP_1:1,LR8D1;
  hence thesis by LMGSEQ4;
end;

Lm2:
  for D be non empty set, n,m,l,p,q be non zero Element of NAT,
  r be Element of n-tuples_on D st m <= n & 8 <= n-m & l = m+8 & l <= n &
  8 <= n-l & p = m+16 & p <= n & 8 <= n-p & q = m+24 & q <= n & 8 <= n-q
  holds <* Op-Left(Op-Right(r,m),8),Op-Left(Op-Right(r,l),8),
  Op-Left(Op-Right(r,p),8),Op-Left(Op-Right(r,q),8) *> is
  Element of 4-tuples_on (8-tuples_on D)
proof
  let D be non empty set, n,m,l,p,q be non zero Element of NAT,
  r be Element of n-tuples_on D;
  assume m <= n & 8 <= n-m & l = m+8 & l <= n & 8 <= n-l &
  p = m+16 & p <= n & 8 <= n-p & q = m+24 & q <= n & 8 <= n-q;
  then Op-Left(Op-Right(r,m),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,l),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,p),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,q),8) is Element of 8-tuples_on D by LR8D1;
  hence thesis by LMGSEQ4;
end;

Lm3:
  for D be non empty set, n,m,l,p,q be non zero Element of NAT,
  r be Element of n-tuples_on D st m <= n & 8 <= n-m & l = m+8 & l <= n &
  8 <= n-l & p = m+16 & p <= n & 8 <= n-p & q = m+24 & q <= n & 8 = n-q
  holds <* Op-Left(Op-Right(r,m),8),Op-Left(Op-Right(r,l),8),
  Op-Left(Op-Right(r,p),8),Op-Right(r,q) *> is
  Element of 4-tuples_on (8-tuples_on D)
proof
  let D be non empty set, n,m,l,p,q be non zero Element of NAT,
  r be Element of n-tuples_on D;
  assume m <= n & 8 <= n-m & l = m+8 & l <= n & 8 <= n-l &
  p = m+16 & p <= n & 8 <= n-p & q = m+24 & q <= n & 8 = n-q;
  then Op-Left(Op-Right(r,m),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,l),8) is Element of 8-tuples_on D &
  Op-Left(Op-Right(r,p),8) is Element of 8-tuples_on D &
  Op-Right(r,q) is Element of 8-tuples_on D by DESCIP_1:2,LR8D1;
  hence thesis by LMGSEQ4;
end;

definition
  let r be Element of 128-tuples_on BOOLEAN;
  func AES-KeyInitState128(r) ->
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  it.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
    Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
  it.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
    Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
  it.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
    Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
  it.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
    Op-Left(Op-Right(r,112),8),Op-Right(r,120) *>;
  existence
  proof
    set R1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *>;
    set R2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *>;
    set R3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *>;
    set R4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Right(r,120) *>;
    8 <= 128-8 & 8 <= 128-16 & 8 <= 128-24;
    then reconsider R1 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm1;
    8 <= 128-32 & 8 <= 128-40 & 8 <= 128-48 & 8 <= 128-56 &
    40 = 32+8 & 48 = 32+16 & 56 = 32+24;
    then reconsider R2 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 128-64 & 8 <= 128-72 & 8 <= 128-80 & 8 <= 128-88 &
    72 = 64+8 & 80 = 64+16 & 88 = 64+24;
    then reconsider R3 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 128-96 & 8 <= 128-104 & 8 <= 128-112 & 8 = 128-120 &
    104 = 96+8 & 112 = 96+16 & 120 = 96+24 & 8 = 128-120;
    then reconsider R4 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm3;
    set T1 = <*R1,R2*>;
    set T2 = <*R3,R4*>;
    set T = T1^T2;
A4: T.1 = T1.1 & ... & T.2 = T1.2 by FINSEQ_3:154;
A5: T.(2+1) = T2.1 & ... & T.(2+2) = T2.2 by FINSEQ_3:155;
    len T = 4 & T is FinSequence of 4-tuples_on (8-tuples_on BOOLEAN)
    by CARD_1:def 7;
    then reconsider T as Element of
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by FINSEQ_2:92;
    take T;
    thus thesis by A4,A5,FINSEQ_1:44;
  end;
  uniqueness
  proof
    let p,q be Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A6: p.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    p.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    p.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    p.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Right(r,120) *>;
    assume
A7: q.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    q.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    q.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    q.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Right(r,120) *>;
    p in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A8: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st p = v &
    len v = 4;
    q in 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A9: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st q = v &
    len v = 4;
    for i be Nat st 1 <= i & i <= len p holds p.i = q.i
    proof
      let i be Nat;
      assume 1 <= i & i <= len p;
      then i = 1 or ... or i = 4 by A8;
      hence thesis by A6,A7;
    end;
    hence p = q by A8,A9,FINSEQ_1:14;
  end;
end;

definition
  let r be Element of 192-tuples_on BOOLEAN;
  func AES-KeyInitState192(r) ->
  Element of 6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  it.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
    Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
  it.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
    Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
  it.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
    Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
  it.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
    Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
  it.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
    Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
  it.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
    Op-Left(Op-Right(r,176),8),Op-Right(r,184) *>;
  existence
  proof
    set R1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *>;
    set R2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *>;
    set R3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *>;
    set R4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *>;
    set R5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *>;
    set R6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Right(r,184) *>;
    8 <= 192-8 & 8 <= 192-16 & 8 <= 192-24;
    then reconsider R1 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm1;
    8 <= 192-32 & 8 <= 192-40 & 8 <= 192-48 & 8 <= 192-56 &
    40 = 32+8 & 48 = 32+16 & 56 = 32+24;
    then reconsider R2 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 192-64 & 8 <= 192-72 & 8 <= 192-80 & 8 <= 192-88 &
    72 = 64+8 & 80 = 64+16 & 88 = 64+24;
    then reconsider R3 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 192-96 & 8 <= 192-104 & 8 <= 192-112 & 8 <= 192-120 &
    104 = 96+8 & 112 = 96+16 & 120 = 96+24;
    then reconsider R4 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 192-128 & 8 <= 192-136 & 8 <= 192-144 & 8 <= 192-152 &
    136 = 128+8 & 144 = 128+16 & 152 = 128+24;
    then reconsider R5 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 192-160 & 8 <= 192-168 & 8 <= 192-176 & 8 = 192-184 &
    168 = 160+8 & 176 = 160+16 & 184 = 160+24 & 8 = 192-184;
    then reconsider R6 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm3;
    set T1 = <*R1,R2,R3*>;
    set T2 = <*R4,R5,R6*>;
    set T = T1^T2;
A4: T.1 = T1.1 & ... & T.3 = T1.3 by FINSEQ_3:154;
A5: T.(3+1) = T2.1 & ... & T.(3+3) = T2.3 by FINSEQ_3:155;
    len T = 6 & T is FinSequence of 4-tuples_on (8-tuples_on BOOLEAN)
    by CARD_1:def 7;
    then reconsider T as Element of
    6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by FINSEQ_2:92;
    take T;
    thus thesis by A4,A5,FINSEQ_1:45;
  end;
  uniqueness
  proof
    let p,q be Element of 6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A6: p.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    p.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    p.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    p.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
    p.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
    p.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Right(r,184) *>;
    assume
A7: q.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    q.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    q.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    q.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
    q.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
    q.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Right(r,184) *>;
    p in 6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A8: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st p = v &
    len v = 6;
    q in 6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A9: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st q = v &
    len v = 6;
    for i be Nat st 1 <= i & i <= len p holds p.i = q.i
    proof
      let i be Nat;
      assume 1 <= i & i <= len p;
      then i = 1 or ... or i = 6 by A8;
      hence thesis by A6,A7;
    end;
    hence p = q by A8,A9,FINSEQ_1:14;
  end;
end;

definition
  let r be Element of 256-tuples_on BOOLEAN;
  func AES-KeyInitState256(r) ->
  Element of 8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) means
  it.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
    Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
  it.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
    Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
  it.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
    Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
  it.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
    Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
  it.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
    Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
  it.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
    Op-Left(Op-Right(r,176),8),Op-Left(Op-Right(r,184),8) *> &
  it.7 = <* Op-Left(Op-Right(r,192),8),Op-Left(Op-Right(r,200),8),
    Op-Left(Op-Right(r,208),8),Op-Left(Op-Right(r,216),8) *> &
  it.8 = <* Op-Left(Op-Right(r,224),8),Op-Left(Op-Right(r,232),8),
    Op-Left(Op-Right(r,240),8),Op-Right(r,248) *>;
  existence
  proof
    set R1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *>;
    set R2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *>;
    set R3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *>;
    set R4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *>;
    set R5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *>;
    set R6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Left(Op-Right(r,184),8) *>;
    set R7 = <* Op-Left(Op-Right(r,192),8),Op-Left(Op-Right(r,200),8),
      Op-Left(Op-Right(r,208),8),Op-Left(Op-Right(r,216),8) *>;
    set R8 = <* Op-Left(Op-Right(r,224),8),Op-Left(Op-Right(r,232),8),
      Op-Left(Op-Right(r,240),8),Op-Right(r,248) *>;
    8 <= 256-8 & 8 <= 256-16 & 8 <= 256-24;
    then reconsider R1 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm1;
    8 <= 256-32 & 8 <= 256-40 & 8 <= 256-48 & 8 <= 256-56 &
    40 = 32+8 & 48 = 32+16 & 56 = 32+24;
    then reconsider R2 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-64 & 8 <= 256-72 & 8 <= 256-80 & 8 <= 256-88 &
    72 = 64+8 & 80 = 64+16 & 88 = 64+24;
    then reconsider R3 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-96 & 8 <= 256-104 & 8 <= 256-112 & 8 <= 256-120 &
    104 = 96+8 & 112 = 96+16 & 120 = 96+24;
    then reconsider R4 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-128 & 8 <= 256-136 & 8 <= 256-144 & 8 <= 256-152 &
    136 = 128+8 & 144 = 128+16 & 152 = 128+24;
    then reconsider R5 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-160 & 8 <= 256-168 & 8 <= 256-176 & 8 <= 256-184 &
    168 = 160+8 & 176 = 160+16 & 184 = 160+24;
    then reconsider R6 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-192 & 8 <= 256-200 & 8 <= 256-208 & 8 <= 256-216 &
    200 = 192+8 & 208 = 192+16 & 216 = 192+24;
    then reconsider R7 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm2;
    8 <= 256-224 & 8 <= 256-232 & 8 <= 256-240 & 8 = 256-248 &
    232 = 224+8 & 240 = 224+16 & 248 = 224+24 & 8 = 256-248;
    then reconsider R8 as Element of 4-tuples_on (8-tuples_on BOOLEAN) by Lm3;
    set T1 = <*R1,R2,R3,R4*>;
    set T2 = <*R5,R6,R7,R8*>;
    set T = T1^T2;
A4: T.1 = T1.1 & ... & T.4 = T1.4 by FINSEQ_3:154;
A5: T.(4+1) = T2.1 & ... & T.(4+4) = T2.4 by FINSEQ_3:155;
    len T = 8 & T is FinSequence of 4-tuples_on (8-tuples_on BOOLEAN)
    by CARD_1:def 7;
    then reconsider T as Element of
    8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)) by FINSEQ_2:92;
    take T;
    thus thesis by A4,A5,FINSEQ_4:76;
  end;
  uniqueness
  proof
    let p,q be Element of 8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    assume
A6: p.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    p.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    p.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    p.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
    p.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
    p.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Left(Op-Right(r,184),8) *> &
    p.7 = <* Op-Left(Op-Right(r,192),8),Op-Left(Op-Right(r,200),8),
      Op-Left(Op-Right(r,208),8),Op-Left(Op-Right(r,216),8) *> &
    p.8 = <* Op-Left(Op-Right(r,224),8),Op-Left(Op-Right(r,232),8),
      Op-Left(Op-Right(r,240),8),Op-Right(r,248) *>;
    assume
A7: q.1 = <* Op-Left(r,8),Op-Left(Op-Right(r,8),8),
      Op-Left(Op-Right(r,16),8),Op-Left(Op-Right(r,24),8) *> &
    q.2 = <* Op-Left(Op-Right(r,32),8),Op-Left(Op-Right(r,40),8),
      Op-Left(Op-Right(r,48),8),Op-Left(Op-Right(r,56),8) *> &
    q.3 = <* Op-Left(Op-Right(r,64),8),Op-Left(Op-Right(r,72),8),
      Op-Left(Op-Right(r,80),8),Op-Left(Op-Right(r,88),8) *> &
    q.4 = <* Op-Left(Op-Right(r,96),8),Op-Left(Op-Right(r,104),8),
      Op-Left(Op-Right(r,112),8),Op-Left(Op-Right(r,120),8) *> &
    q.5 = <* Op-Left(Op-Right(r,128),8),Op-Left(Op-Right(r,136),8),
      Op-Left(Op-Right(r,144),8),Op-Left(Op-Right(r,152),8) *> &
    q.6 = <* Op-Left(Op-Right(r,160),8),Op-Left(Op-Right(r,168),8),
      Op-Left(Op-Right(r,176),8),Op-Left(Op-Right(r,184),8) *> &
    q.7 = <* Op-Left(Op-Right(r,192),8),Op-Left(Op-Right(r,200),8),
      Op-Left(Op-Right(r,208),8),Op-Left(Op-Right(r,216),8) *> &
    q.8 = <* Op-Left(Op-Right(r,224),8),Op-Left(Op-Right(r,232),8),
      Op-Left(Op-Right(r,240),8),Op-Right(r,248) *>;
    p in 8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A8: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st p = v &
    len v = 8;
    q in 8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
    then
A9: ex v be Element of (4-tuples_on (8-tuples_on BOOLEAN))* st q = v &
    len v = 8;
    for i be Nat st 1 <= i & i <= len p holds p.i = q.i
    proof
      let i be Nat;
      assume 1 <= i & i <= len p;
      then i = 1 or ... or i = 8 by A8;
      hence thesis by A6,A7;
    end;
    hence p = q by A8,A9,FINSEQ_1:14;
  end;
end;

definition
  let SBT,MixColumns;
  let message be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 128-tuples_on BOOLEAN;
  func AES128-ENC(SBT,MixColumns,message,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-ENC(SBT,MixColumns,AES-Statearray.message,
  AES-KeyInitState128(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is Function of
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),128-tuples_on BOOLEAN
    by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

definition
  let SBT,MixColumns;
  let cipher be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 128-tuples_on BOOLEAN;
  func AES128-DEC(SBT,MixColumns,cipher,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,AES-Statearray.cipher,
  AES-KeyInitState128(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is
    Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    128-tuples_on BOOLEAN by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

theorem
  for SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message,Key be Element of 128-tuples_on BOOLEAN holds
  AES128-DEC(SBT,MixColumns,AES128-ENC(SBT,MixColumns,message,Key),Key) =
  message
proof
  let SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message,Key be Element of 128-tuples_on BOOLEAN;
  reconsider text = AES-Statearray.message as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider sKey = AES-KeyInitState128(Key) as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider cipher = AES-ENC(SBT,MixColumns,text,sKey) as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider CBLOCK = AES128-ENC(SBT,MixColumns,message,Key) as
  Element of 128-tuples_on BOOLEAN;
  AES128-DEC(SBT,MixColumns,CBLOCK,Key) =
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,cipher,sKey)) by LMINV1
    .=(AES-Statearray)".text by LASTXX;
  hence thesis by FUNCT_2:26;
end;

definition
  let SBT,MixColumns;
  let message be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 192-tuples_on BOOLEAN;
  func AES192-ENC(SBT,MixColumns,message,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-ENC(SBT,MixColumns,AES-Statearray.message,
  AES-KeyInitState192(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is Function of
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),128-tuples_on BOOLEAN
    by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

definition
  let SBT,MixColumns;
  let cipher be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 192-tuples_on BOOLEAN;
  func AES192-DEC(SBT,MixColumns,cipher,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,AES-Statearray.cipher,
  AES-KeyInitState192(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is
    Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    128-tuples_on BOOLEAN by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

theorem
  for SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message be Element of 128-tuples_on BOOLEAN,
  Key be Element of 192-tuples_on BOOLEAN holds
  AES192-DEC(SBT,MixColumns,AES192-ENC(SBT,MixColumns,message,Key),Key) =
  message
proof
  let SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message be Element of 128-tuples_on BOOLEAN,
  Key be Element of 192-tuples_on BOOLEAN;
  reconsider text = AES-Statearray.message as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider sKey = AES-KeyInitState192(Key) as
  Element of 6-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider cipher = AES-ENC(SBT,MixColumns,text,sKey) as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider CBLOCK = AES192-ENC(SBT,MixColumns,message,Key) as
  Element of 128-tuples_on BOOLEAN;
  AES192-DEC(SBT,MixColumns,CBLOCK,Key) =
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,cipher,sKey)) by LMINV1
    .=(AES-Statearray)".text by LASTXX;
  hence thesis by FUNCT_2:26;
end;

definition
  let SBT,MixColumns;
  let message be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 256-tuples_on BOOLEAN;
  func AES256-ENC(SBT,MixColumns,message,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-ENC(SBT,MixColumns,AES-Statearray.message,
  AES-KeyInitState256(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is Function of
    4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),128-tuples_on BOOLEAN
    by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

definition
  let SBT,MixColumns;
  let cipher be Element of 128-tuples_on BOOLEAN;
  let Key be Element of 256-tuples_on BOOLEAN;
  func AES256-DEC(SBT,MixColumns,cipher,Key) ->
  Element of 128-tuples_on BOOLEAN equals
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,AES-Statearray.cipher,
  AES-KeyInitState256(Key)));
  correctness
  proof
    rng AES-Statearray = 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN))
    by FUNCT_2:def 3;
    then (AES-Statearray)" is
    Function of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
    128-tuples_on BOOLEAN by FUNCT_2:25;
    hence thesis by FUNCT_2:5;
  end;
end;

theorem
  for SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message be Element of 128-tuples_on BOOLEAN,
  Key be Element of 256-tuples_on BOOLEAN holds
  AES256-DEC(SBT,MixColumns,AES256-ENC(SBT,MixColumns,message,Key),Key) =
  message
proof
  let SBT be Permutation of (8-tuples_on BOOLEAN),
  MixColumns be Permutation of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN)),
  message be Element of 128-tuples_on BOOLEAN,
  Key be Element of 256-tuples_on BOOLEAN;
  reconsider text = AES-Statearray.message as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider sKey = AES-KeyInitState256(Key) as
  Element of 8-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider cipher = AES-ENC(SBT,MixColumns,text,sKey) as
  Element of 4-tuples_on(4-tuples_on (8-tuples_on BOOLEAN));
  reconsider CBLOCK = AES256-ENC(SBT,MixColumns,message,Key) as
  Element of 128-tuples_on BOOLEAN;
  AES256-DEC(SBT,MixColumns,CBLOCK,Key) =
  (AES-Statearray)".(AES-DEC(SBT,MixColumns,cipher,sKey)) by LMINV1
    .=(AES-Statearray)".text by LASTXX;
  hence thesis by FUNCT_2:26;
end;