<?php

/*

* helloworld.php

* Copyright (C) 2013 http://www.reddit.com/user/chmod755

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU Affero General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Affero General Public License for more details.

*

* You should have received a copy of the GNU Affero General Public License

* along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

if ( function_exists ( 'ignore_user_abort' ) )

ignore_user_abort ( 0 ) ;

if ( function_exists ( 'header' ) ) {

header ( 'Content-type: text/plain' ) ;

header ( 'Content-Length: 12' ) ;

}

if ( function_exists ( 'setlocale' ) ) {

setlocale ( LC_ALL , 'en_US' ) ;

}

try {

print helloworld ( ) ;

} catch ( Exception $e ) {

die ( $e ) ;

}

// Hello World function

function helloworld ( ) {

$helloworld = array (

0x21 , 0x71 , 0x79 , 0x65 , 0x62 , 0x6a , 0x20 , 0x62 , 0x79 , 0x79 , 0x72 , 0x75

) ;

$str = '' ;

foreach ( $helloworld as $char ) {

$str .= sprintf ( '%c' , $char ) ;

}

if ( function_exists ( 'str_rot13' ) )

$str = str_rot13 ( $str ) ;

else

throw new Exception ( "helloworld(): function str_rot13() not found." ) ;

if ( function_exists ( 'strrev' ) )

$str = strrev ( $str ) ;

else

throw new Exception ( "helloworld(): function strrev() not found." ) ;

if ( function_exists ( 'ucwords' ) )

$str = ucwords ( $str ) ;

else

throw new Exception ( "helloworld(): function ucwords() not found." ) ;

if ( ! function_exists ( 'hash' ) )

throw new Exception ( "helloworld(): function hash() not found." ) ;

if ( ! function_exists ( 'preg_match' ) )

throw new Exception ( "helloworld(): function preg_match() not found." ) ;

if (

// compare hashes

hash ( 'sha512' , $str ) == hash ( 'sha512' , 'Hello World!' ) &&

// to avoid a hash collision

preg_match ( '/^Hello\ World\!$/' , $str )

) {

return $str ;

} else {

throw new Exception ( "helloworld(): hash or string doesn't match." ) ;

}

}

// TODO: add more comments and useless functions