comment 0

Morse Code Converter

Hi , how are you buddy ? :woot: I hope you always be healthy :smile: . Today (28th May 2013) I can’t come to office because of sick. Yaa.. I got high fever last night until this morning, but its not make me far from my lovely PC :lol: . And for fight my boredom I’m playing with my text editor :hoam: . Its just for fun, tools for convert plain text to morse code with PHP CLI.

Here is the codes


Sponsored links


 
<?php
 
# Morse Code Converter
# Rosdyana Kusuma - admin@r3m1ck.us
# just for fun :P
# reference : http://en.wikipedia.org/wiki/Morse_code
# Exploit-ID :: IndonesianCoder :: KebumenCyber

class morse_code{
 
	function __construct($text){
		//check if parameter is empty show the help
		if(empty($text)){
			$this->help();
			exit;
		}
	//define variable
	$charCodes = 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","1","2","3","4",
	"5","6","7","8","9","0"); 
 
	$morseCodes = array(". _","_ . . .","_ . _ .","_ . .",".",
	". . _ .","_ _ .",". . . .",". .",". _ _ _","_ . _",". _ . .",
	"_ _","_ .","_ _ _",". _ _ .","_ _ . _",". _ .",". . .","_",
	". . _",". . . _",". _ _","_ . . _","_ . _ _","_ _ . .",". _ _ _ _",
	". . _ _ _",". . . _ _",". . . . _",". . . . .",
	"_ . . . .","_ _ . . .","_ _ _ . .","_ _ _ _ .","_ _ _ _ _");
 
	$ilegalChar = array("`","~","!","@","#","$","%","^","&",
	"*","(",")","_","-","+","=","{","}",":",
	";","'","<",">","?","/","'\'","|",".",",");
 
	//filter ilegal char
	$filterIlegal = str_replace($ilegalChar, "",$text);
 
	//avoid case-sensitive
	$plainText = strtolower($filterIlegal);
 
	//to add space betwen morse code
	$addSpaces = chunk_split($plainText,1,"    ");
 
	//replace from char to morse code
	$result_code = str_replace($charCodes,$morseCodes,$addSpaces);
 
	//print the result
	print "\nMorse from ".$text." is\n ".$result_code."\n";
 
	}
 
	//func. to show help
	function help(){
	echo("
___  ___                      _____           _      
|  \/  |                     /  __ \         | |     
| .  . | ___  _ __ ___  ___  | /  \/ ___   __| | ___ 
| |\/| |/ _ \| '__/ __|/ _ \ | |    / _ \ / _` |/ _ \
| |  | | (_) | |  \__ \  __/ | \__/\ (_) | (_| |  __/
\_|  |_/\___/|_|  |___/\___|  \____/\___/ \__,_|\___|
 
		Converter by Rosdyana Kusuma
	");
 
		print "\nHow to using :\n";
		print "morse_code.php < plain text > \n";
		print "morse_code.php love-is-suck \n";
	}
}
 
	$MorseCode = new morse_code($argv[1]);
 
?>

morse_code

every line I add some comment to explain line by line function.
Happy coding… See yaa ,GWS for me :oops:

Leave a Reply

Your email address will not be published. Required fields are marked *