HEX
Server: Apache
System: Linux server1.myinter.net 4.18.0-553.147.1.el8_10.x86_64 #1 SMP Fri Jul 24 08:29:05 EDT 2026 x86_64
User: internet (1005)
PHP: 8.4.23
Disabled: passthru,system
Upload Files
File: /home/internet/public_html/app/libraries/MorseCode.php
<?php

namespace Fir\Libraries;

class MorseCode {

    /**
     * The string to be manipulated
     * @var
     */
    private $string;

    public function __construct($string) {
        $this->string = $string;
    }

    /**
     * A list with all the available characters
     *
     * @return  array
     */
    private static function getList() {
        return array(' ' => '/ ', 'a' => '.- ', 'b' => '-... ', 'c' => '-.-. ', 'd' => '-.. ', 'e' => '. ', 'f' => '..-. ', 'g' => '--. ', 'h' => '.... ', 'i' => '.. ', 'j' => '.--- ', 'k' => '-.- ', 'l' => '.-.. ', 'm' => '-- ', 'n' => '-. ', 'o' => '--- ', 'p' => '.--. ', 'q' => '--.- ', 'r' => '.-. ', 's' => '... ', 't' => '- ', 'u' => '..- ', 'v' => '...- ', 'w' => '.-- ', 'x' => '-.. ', 'y' => '-.-- ', 'z' => '--.. ');
    }

    /**
     * @return  string
     */
    public function encode() {
        return str_replace(array_keys($this->getList()), $this->getList(), mb_strtolower($this->string));
    }

    /**
     * @return  string
     */
    public function decode() {
        $morse = array_map('trim', $this->getList());

        $output = '';
        foreach(explode(' ', $this->string) as $value) {
            $output .= array_search($value, $morse);
        }
        
        return mb_strtoupper($output);
    }
}