title: python image scrambeling porgram
body: <p>I'm writing an image scrambling and Unscrambling program. I'm transfering a custom seed to the random function in order scramble the image pixels in a way that I could unscramble them with the same seed. The scramble part works fine but when I unscramble the scrambled image it leaves some pixels black, I tired using png format since its not being compressed but still no good.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>from PIL import Image
  import random
  from datetime import datetime
  </code></pre>
  
  <p>class Scrambler:</p>
  
  <pre><code>@staticmethod    
  def scramble(key,fileName):
       image = Image.open(fileName)
       pixels = image.load()
       new_image = Image.new(image.mode,image.size)
       new_image_pix = new_image.load()
       seed = 0
       for c in key:
           seed+=ord(c)
       random.seed(seed)
       for i in range(0,(image.size)[0]):
          for j in range(0,(image.size)[1]):
              new_image_pix[i,j] = pixels[random.randint(0,image.size[0]-1),
                                          random.randint(0,image.size[1]-1)]
  
  
       new_image.show()
       new_image.save('scrambeld.png')
  
  
  @staticmethod
  def unscramble(key,fileName):
      image = Image.open(fileName)
      pixels = image.load()
      new_image = Image.new(image.mode,image.size)
      new_image_pix = new_image.load()
      seed = 0
      for c in key:
        seed+=ord(c)
      random.seed(seed)
      for i in range(0,(image.size)[0]):
          for j in range(0,(image.size)[1]):
              new_image_pix[random.randint(0,image.size[0]-1),
                            random.randint(0,image.size[1]-1)] = pixels[i,j]
  
      new_image.show()
      new_image.save('unscarmbeld.png')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Bv3AN.jpg" rel="nofollow noreferrer">original image:</a></p>
  
  <p><a href="https://i.stack.imgur.com/KBefv.png" rel="nofollow noreferrer">scrambeld image:</a></p>
  
  <p><a href="https://i.stack.imgur.com/7bAmQ.png" rel="nofollow noreferrer">image after Un Scrambeling:</a></p>
  
  <p>Much appreciate any help.</p>