Custom algorithm for hashing and un-hashing password I am attempting to create functions for getting an algorithm, hashing and un-hashing a string.

As it stands, it works, and very well. But, I feel this is not secure enough and someone could easily break it!

Can someone help me to improve this?

Code:

&lt;?php
function HashIt($string)
{
    $return = '';
    $algo = GetAlgo();
    $hashing = str_split($string, 1);
    foreach ($hashing as $part)
    {
        $return .= $algo[$part] . "|";
    }
    return rtrim($return, "|");
}

function UnhashIt($hash)
{
    $return = '';
    $algo = GetAlgo();
    $unhash = explode("|", $hash);
    foreach ($unhash as $value)
    {
        $find = array_search($value, $algo);
        if ($find)
            $return .= $find;
    }
    return $return;
}

function GetAlgo()
{
    return [
        "a"=&gt;"[H]",
        "b"=&gt;"[He]",
        "c"=&gt;"[Li]",
        "d"=&gt;"[Be]",
        "e"=&gt;"[B]",
        "f"=&gt;"[C]",
        "g"=&gt;"[N]",
        "h"=&gt;"[O]",
        "i"=&gt;"[F]",
        "j"=&gt;"[Ne]",
        "k"=&gt;"[Na]",
        "l"=&gt;"[Mg]",
        "m"=&gt;"[Al]",
        "n"=&gt;"[Si]",
        "o"=&gt;"[P]",
        "p"=&gt;"[S]",
        "q"=&gt;"[Cl]",
        "r"=&gt;"[Ar]",
        "s"=&gt;"[K]",
        "t"=&gt;"[Ca]",
        "u"=&gt;"[Sc]",
        "v"=&gt;"[Ti]",
        "w"=&gt;"[V]",
        "x"=&gt;"[Cr]",
        "y"=&gt;"[Mn]",
        "z"=&gt;"[Fe]",
        "A"=&gt;"[Co]",
        "B"=&gt;"[Ni]",
        "C"=&gt;"[Cu]",
        "D"=&gt;"[Zn]",
        "E"=&gt;"[Ga]",
        "F"=&gt;"[Ge]",
        "G"=&gt;"[As]",
        "H"=&gt;"[Se]",
        "I"=&gt;"[Br]",
        "J"=&gt;"[Kr]",
        "K"=&gt;"[Rb]",
        "L"=&gt;"[Sr]",
        "M"=&gt;"[Y]",
        "N"=&gt;"[Zr]",
        "O"=&gt;"[Nb]",
        "P"=&gt;"[Mo]",
        "Q"=&gt;"[Tc]",
        "R"=&gt;"[Ru]",
        "S"=&gt;"[Rh]",
        "T"=&gt;"[Pd]",
        "U"=&gt;"[Ag]",
        "V"=&gt;"[Cd]",
        "W"=&gt;"[In]",
        "X"=&gt;"[Sn]",
        "Y"=&gt;"[Sb]",
        "Z"=&gt;"[Te]",
        " "=&gt;"[I]",
        "1"=&gt;"[Xe]",
        "2"=&gt;"[Cs]",
        "3"=&gt;"[Ba]",
        "4"=&gt;"[Hf]",
        "5"=&gt;"[Ta]",
        "6"=&gt;"[W]",
        "7"=&gt;"[Re]",
        "8"=&gt;"[Os]",
        "9"=&gt;"[Ir]",
        "0"=&gt;"[Pt]",
        "!"=&gt;"[Au]",
        "£"=&gt;"[Hg]",
        "$"=&gt;"[Tl]",
        "%"=&gt;"[Pb]",
        "^"=&gt;"[Bi]",
        "&amp;"=&gt;"[Po]",
        "*"=&gt;"[At]",
        "("=&gt;"[Rn]",
        ")"=&gt;"[Fr]",
        "_"=&gt;"[Ra]",
        "-"=&gt;"[Rf]",
        "="=&gt;"[Db]",
        "+"=&gt;"[Sg]",
        "`"=&gt;"[Bh]",
        "¬"=&gt;"[Hs]",
        ""=&gt;"[Mt]",
        ","=&gt;"[Ds]",
        "&lt;"=&gt;"[Rg]",
        "."=&gt;"[Cn]",
        "&gt;"=&gt;"[Uut]",
        "/"=&gt;"[Fl]",
        "?"=&gt;"[Uup]",
        ";"=&gt;"[Lv]",
        ":"=&gt;"[Uus]",
        "'"=&gt;"[Uuo]",
        "@"=&gt;"[La]",
        "#"=&gt;"[Ce]",
        "~"=&gt;"[Pr]",
        "["=&gt;"[Nd]",
        "]"=&gt;"[Pm]",
        "{"=&gt;"[Sm]",
        "}"=&gt;"[Eu]",
        "."=&gt;"Gd",
    ];
}
?&gt;
First of all, what you have is an encryption function, not a hashing function (encryption can be reversed by knowing the algorithm and optionally a password, hashing is one way).

For passwords, you always* want to hash, not encrypt (because if an attacker gets your source code, they can easily decrypt the passwords). 

You are using a substitution cipher, which is also very easy to break. You might want to look into block or stream ciphers, if you want encryption that is more secure.

As to the code you do have:


function names should start with a lower-case character (classes start with an uppercase one).
with the information given above, it's obvious that the function names don't really fit. Also, you don't need filler words such as It in function names. Something like encrypt(plaintext) and decrypt(ciphertext) would be better.
You shouldn't silently ignore errors. I would add an else clause to your if ($find) and throw an exception.
In UnhashIt you check if the string exists, but you don't do it for the more important HashIt function. This means that UnhashIt(HashIt(text)) != text in some cases, which is not good. 
For any real-world code, use bcrypt.


* there are exceptions such as kerberos and password managers, but in use cases where you want to authenticate a user by checking a user supplied password against a stored password (ie whenever you do have a user supplied plaintext password to check against), hashing is the correct way, not encryption 
(see the comments/chat for an extended discussion)