Wednesday, October 1, 2014

Smallest encryption program in C

<?php
$example = range(0, 9);
foreach ($example as $value)
{
 echo $value;
}
int main(int argc, char** argv)
{   
    // retrieve the first argument passed to the program (action)
    char action = argv[1][0];

    // retrieve the second argument passed to the program (key)
    char* key = argv[2];

    // initialize character position in the key
    int i = 0;

    // initialize the current input character
    int c = 0;

    // loop until we reach the end of input
    while (c != -1){
        // get a character from stdin
        c = getchar();
        if (action == 'E'){
            // encode the current character
            putchar(c + key[i]);
        } else{
            // decode the current character
            putchar(c - key[i]);
        }
        // increment the position in the key string, without overflow
        i = (i + 1) % strlen(key);
    }
}

Friday, August 24, 2012

Convert an array to object in PHP using a recursive function


function array_to_object($variable){ if (is_array($variable)){ $object = new StdClass(); foreach ($variable as $key=>$value){ $object->$key = array_to_object($value); } return $object; } else{ return $variable; } }




Convert an object to array in PHP using a recursive function


function object_to_array($variable){ if (is_object($variable)){ $array = array(); foreach ($variable as $key=>$value){ $array[$key] = object_to_array($value); } return $array; } else{ return $variable; } }




Sunday, January 22, 2012

The Stooges & The Fugees


Coincidence ? Maybe...


The Stooges' eponym album cover :




The Fugees' second album cover :



Though there isn't any relationship between the music of the two of them, the album covers do share a very similar graphic design...