<?php

namespace Buckhill\Support;

class ModHex
{
    /**
     * @param string $string
     * @return null|string
     */
    public static function modhex2bin(string $string): ?string
    {
        if (!is_string($string)) return null;

        $r = '';

        for ($a = 0; $a < strlen($string); $a += 2)
        {
            $r .= chr(hexdec($string{$a}.$string{($a + 1)}));
        }

        return $r;
    }

    /**
     * @param string $string
     * @return string
     */
    public static function modhex2hex(string $string): string
    {
        return strtr($string, "cbdefghijklnrtuv", "0123456789abcdef");
    }
}