31.7.07

Super secret decoder ring... in php



It's time for a wee bit of code. The following is a simple php class to encrypt/decrypt strings. This is useful when you need to pass around secret documents but are out of microfiche and fake lipstick tubes.

To use:


<?php
require_once('secretdecoderring.php');

$dr = new SecretDecoderRing();
$enc = $dr->encode($argv[1]);
$dec = $dr->decode($enc);
var_dump($argv[1]);
var_dump($enc);
var_dump($dec);
?>




<?php

class SecretDecoderRing
{
private $key = "supersecret";
private $td;

function __construct()
{
$this->td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND);
mcrypt_generic_init($this->td, $this->key, $iv);
}

function __deconstruct()
{
mcrypt_generic_deinit($this->td);
mcrypt_module_close($this->td);
}

function encode($string)
{
$enc = mcrypt_generic($this->td, $string);
return base64_encode($enc);
}

function decode($string)
{
$enc = base64_decode($string);
$dec = mdecrypt_generic($this->td, $enc);
// It's padded. Really. Security is such a waste of time.
return rtrim($dec, ((ord(substr($dec, strlen($dec)-1, 1)) >= 0 and ord(substr($dec, strlen($dec)-1, 1)) <= 16) ? c
hr(ord(substr($dec, strlen($dec)-1, 1))): null));
}
}

?>

24.7.07

a flower?

23.7.07

OS X terminal settings for tcsh

Everyone seems to love two features of my OS X environment. Color terminals, and an updating title bar that even works when you ssh. Rock.

Put the following in your .cshrc or .tcshrc file in your home directory.


#
# Terminal stuff
#
setenv TERM "xterm-color"
setenv CLICOLOR "true"
setenv LSCOLORS "exfxcxdxbxegedabagacad"

#
# Auto complete
#

set fignore = (.o \~)
set complete = enhance

#
# Title bar
#
setenv SHORTHOST `echo -n $HOST | sed -e 's%\..*%%'`
alias precmd 'printf "\033]0;%s @ $SHORTHOST\007" "${cwd}" | sed -e "s%$HOME%~%"'
sched +0:00 alias postcmd 'printf "\033]0;%s @ $SHORTHOST\007" "\!#"'