title: Unscrambling rotation of jpeg concentric pixel blocks
body: <p>As part of a 'Capture The Flag' challenge the attached jpg was scrambled to obscure the content. The image (&quot;flagpoles.jpg&quot;) is 1600 pixels by 1600 pixels. The concentric lines appear to have a blocksize of 10 pixels wide. (It resembles a Frank Stella painting). It appears the original image has been split into four portions which are arranged symmetrically around the center. I have been trying to write a python script to work through the pixels and unscramble the concentric squares. My efforts have resulted in two useless recurring conditions, either no change or increased scrambling. I think this might be because I am working on the entire image and it might be better to try and unscramble part of it. Here is the code I have. At the moment it only processes half of the pixels because I am trying to match up portions of the picture with each other. I tried sending the blocks to the other side of the image to try and match them up, but there is no improvement. Any assistance in getting a clear picture would be gratefully received.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from PIL import Image
  import math
  
  im = Image.open("flagpoles.jpg", "r")
  pic = im.load() 
  
  def rot(A, r, x1, y1): 
      myArray = []
      for i in range(r):
          myArray.append([])
          for j in range(r):
              myArray[i].append(pic[x1+i, y1+j])
      for i in range(r):
          for j in range(r):
              pic[x1+i,y1+j] = myArray[r-1-i][r-1-j]
  
  xres = 800
  yres = 800
  blocksize = 10 
  for i in range(blocksize, blocksize+1):
      for j in range(int(math.floor(float(xres)/float(blocksize+2+i)))):
          for k in range(int(math.floor(float(yres)/float(blocksize+2+i)))):
              rot(pic, blocksize+2+i, j*(blocksize+2+i), k*(blocksize+2+i))
  
  im.save("hopeful.png")
  
  print("Finished!")</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://i.stack.imgur.com/V4P3n.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V4P3n.jpg" alt="enter image description here" /></a></p>