For compression
In Javascript, http://rumkin.com/tools/compression/compress_huff.php
Also have a look at http://stackoverflow.com/questions/994667/javascript-text-compression-decompression
For encryption
In PHP, you can use mcrypt:
http://www.php.net/manual/en/function.mcrypt-encrypt.php
http://www.php.net/manual/en/function.mcrypt-decrypt.php
Sample code (from above site):
<?php
class Cipher {
private $securekey, $iv;
function __construct($textkey) {
$this->securekey = hash('sha256',$textkey,TRUE);
$this->iv = mcrypt_create_iv(32);
}
function encrypt($input) {
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv));
}
function decrypt($input) {
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
}
}
$cipher = new Cipher('secret passphrase');
$encryptedtext = $cipher->encrypt("hide me");
echo "->encrypt = $encryptedtext<br />";
$decryptedtext = $cipher->decrypt($encryptedtext);
echo "->decrypt = $decryptedtext<br />";
var_dump($cipher);
?>