jmarrdiaz
3/10/2016 - 1:29 PM

Simply EncodeDecode string with Cesar algorithm

Simply EncodeDecode string with Cesar algorithm

// file: passwordSecurity.php

<?php

	class passwordSecurity
	{
		
		public function __construct ()
		
		{
			return;
		}

		public static function encode ($M)
		
		{
			$C = "";
			for($i = 0; $i < strlen ($M); $i++)
				$C.= chr((ord($M[$i]) + 3) % 255);
			return $C;
		}

    	public static function decode ($C)
		
		{
			$M = "";	
			for($i = 0; $i < strlen($C); $i++)
				$M.= chr((ord($C[$i]) - 3 + 255) % 255);
			return $M;
		}
	}


// file: where you need it

include ("path to passwordSecurity.php");

$password = "my secret password";
$password_encode = passwordSecurity::encode($password);
$password_decode = passwordSecurity::decode($password_encode);