<?php
namespace entities\evr\security;

class Key_Hashes
{
   public function __construct()
   {
      $this->set_path();
      $this->set_hashes();
   }
   private function set_path()
   {
      $this->path = $GLOBALS["KEY_HASHES_PATH"];
   }
   private function set_hashes()
   {
      $this->hashes = file($this->path, FILE_IGNORE_NEW_LINES);
   }
   public function write()
   {
      $string = implode("\n", $this->hashes) . "\n";
      file_put_contents($this->path, $string);
   }
   public function remove($hash)
   {
      $hashes = $this->hashes;
      foreach (range(0, count($hashes) - 1) as $ii)
      {
         if ($hashes[$ii] == $hash)
         {
            array_splice($hashes, $ii, 1);
            break;
         }
      }
      $this->hashes = $hashes;
   }
}
<?php
namespace entities\evr\security;
use entities\html as html;

class Security
{
   public function __construct()
   {
      $this->registrar = new Registrar();
      $this->cookie = new Cookie();
      $this->set_username();
      $this->addresses = new Addresses($this->username);
   }
   private function set_username()
   {
      $username = null;
      if ($this->is_login())
      {
         $submission = $this->get_post_parameter("username");
         $username = $this->find_user_directory($submission);
      }
      else if ($this->cookie->exists())
      {
         $username = $this->cookie->get_username();
      }
      $this->username = $username;
   }
   private function is_login()
   {
      $action = $this->get_post_parameter("action");
      return $action == $GLOBALS["LOGIN_BUTTON_TEXT"];
   }
   public function register_user()
   {
      return $this->registrar->register();
   }
   public static function validate_key()
   {
      $hashes = new Key_Hashes();
      $key = self::get_post_parameter("key");
      if (self::find_hash($hashes, $key))
      {
         return true;
      }
      self::show_error("Key not found");
      return false;
   }
   public static function find_hash($hashes, $key)
   {
      foreach ($hashes->hashes as $hash)
      {
         if (self::match_to_hash($key, $hash))
         {
            return $hash;
         }
      }
   }
   public static function match_to_hash($key, $hash)
   {
      if (!$hash)
      {
         return $hash == crypt($key);
      }
      return $hash == crypt($key, $hash);
   }
   public static function show_error($message)
   {
      echo new html\Div(null, "error", $message);
   }
   public function validate_user()
   {
      $action = $this->get_post_parameter("action");
      if ($this->is_login())
      {
         return $this->log_user_in();
      }
      else if ($this->cookie->exists())
      {
         return $this->validate_cookie();
      }
   }
   public static function get_post_parameter($name)
   {
      if (isset($_POST[$name]))
      {
         return $_POST[$name];
      }
   }
   private function log_user_in()
   {
      $password = $this->get_post_parameter("password");
      if ($hash = $this->verify_credentials($this->username, $password))
      {
         if ($this->get_post_parameter("remember"))
         {
            $this->cookie->set($this->username, $hash);
            $this->addresses->add_current();
         }
         return true;
      }
      return false;
   }
   public static function verify_credentials($username, $password)
   {
      $hash = self::get_stored_hash($username);
      if (self::match_to_hash($password, $hash))
      {
         return $hash;
      }
      self::show_error("Username/password not found");
   }
   public static function get_stored_hash($username)
   {
      $root = $GLOBALS["USERS_PATH"] . "/";
      $path = "$root$username/" . $GLOBALS["USER_HASH_PATH"];
      if (is_file($path))
      {
         return trim(file_get_contents($path));
      }
      return null;
   }
   public static function find_user_directory($username)
   {
      $root = $GLOBALS["USERS_PATH"];
      foreach (scandir($root) as $file_name)
      {
         $path = "$root/$file_name";
         if (is_dir($path) && !strcasecmp($file_name, $username))
         {
            return $file_name;
         }
      }
   }
   private function validate_cookie()
   {
      $hash = $this->cookie->get_hash();
      $stored = self::get_stored_hash($this->username);
      if ($hash == $stored)
      {
         if ($this->addresses->find_current_address())
         {
            $this->cookie->set($this->username, $hash);
            return true;
         }
      }
      return false;
   }
   public static function show_success($message)
   {
      echo new html\Div(null, "success", $message);
   }
   public static function remove_key()
   {
      $key = self::get_post_parameter("key");
      $hashes = new Key_Hashes();
      $hash = self::find_hash($hashes, $key);
      $hashes->remove($hash);
      $hashes->write();
   }
   public function change_password()
   {
      return $this->registrar->change_password();
   }
   public function reset_password()
   {
      return $this->registrar->reset_password();
   }
}
3.235.66.217
3.235.66.217
3.235.66.217
 
September 26, 2017

I made a video about my game Picture Processing for Out of Index 2017! Here is the video along with a transcript.

To save memory, video games are designed to repeat graphics. In raster-based games, image files like textures, tiles and sprites are loaded once into memory and drawn repeatedly by the program to create environments, characters, animations and text. In my puzzle game, 8 by 8 pixel tiles are used to create scenes the player has to recreate. For level 1, the tiles are a cloud, a tree, a mushroom, a character, sky, ground and rock.

An algorithm scrambles the tiles so that each tile is in the wrong memory address at the beginning of a level and the screen looks like a graphics glitch. When level 1 begins, the clouds may be where the trees should be, the mushrooms may be floating in the sky and the character may be switched with rock or the ground. The player's task is to put the tiles where they belong by swapping each tile with a tile in another memory address.

There are five levels, in order of difficulty, based on classic video games or classic video game genres.

The name of this game is taken from the Picture Processing Unit, a microprocessor designed by Nintendo for the Nintendo Entertainment System. The PPU is the hardware component responsible for translating image data into video signals for televisions and screens. It does this with a memory of 8 by 8 pixel tile data, which, along with palette and sprite attribute memory, generates each frame of a video game.

Companies often create lofty, evocative titles for hardware and products. What does the name Picture Processing Unit mean if we consider pictures something independent of a video screen? The phrase picture processing evokes the phrase image processing, a technique used to create applications such as automatic facial and emotion recognition. We often anthropomorphize electronic devices, infusing them with intelligence and souls, forgetting how much more infinitely complex the human mind is compared to a digital processor.

The game is named as a reference to Nintendo's microprocessor because the graphics are tile based, but it is also a reference to the players who are image processors, interpreting a picture from something deterministic into something non-deterministic.

The prototype of this game was created for a game jam called A Game By Its Cover where designers created video games based on imagined Nintendo game cartridges created by visual artists for an exhibition called My Famicase.

Picture Processing is based on one of the imagined cartridges from that exhibition. The cartridge's cover depicts a grid of unordered tiles and is described as a game where one inserts a game cartridge, sees a glitching screen, and meditates about the concept of beauty in imperfection. I added the idea that the player meditates into a state of transcendence until they are able to fix the game's graphics by accessing the memory telepathically.