...The general purpose of this program would be for securing images on the disk or in the cloud, available for searching but full resolution requiring a key to then access.
The high frequency coefficients are actually Huffman encoded. As such enough of them have to be spliced together in memory until a block is then available, encrypted, and then piece meal copied back in place.
Huffman encoding in jpg images uses control codes. The encryption can coincidentally produce a control code. Thus those are repeatedly encrypted until no control code, skipping preexisting control code runs.