Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 106 lines (94 sloc) 2.883 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jeroen Derks <jeroen@derks.it> |
// +----------------------------------------------------------------------+
//
// $Id$

/**
* Simple xtea command line utility.
* Simple xtea command line utility.
*
* @package Crypt_Xtea_Test
* @modulegroup Crypt_Xtea_Test
* @module xteacmd
* @access public
*
* @version $Revision$
* @since 2004/Sep/30
* @author Jeroen Derks <jeroen@derks.it>
*/

/** Crypt_Xtea class */
require_once 'Crypt/Xtea.php';

$flag_decrypt = false; // do encryption by default
$msg = ''; // initialize message to encrypt/decrypt
$key = ''; // initialize key to use

$prog = basename($_SERVER['argv'][0]); // program name
$argc = $_SERVER['argc']; // number of command line arguments
$argv = $_SERVER['argv']; // command line arguments array

// process command line flags
while (1 < $argc && '-' == $argv[1]{0})
{
$argc--;
$arg = $argv[1];
array_shift($argv);
if ('--' == $arg)
break;

$arg = substr($arg, 1);
while (0 < strlen($arg))
{
switch ($arg{0})
{
case 'd': $flag_decrypt = true; break;
case 'e': $flag_decrypt = false; break;
}
$arg = substr($arg, 1);
}
}

// check required parameters
if (2 >= $argc)
{
echo "usage: $prog [-de] key msg [ msg ... ]\n" .
"\t-d\tdecrypt message\n" .
"\t-e\tencrypt message (default action)\n";
exit(1);
}

// get key
$key = $argv[1];
$argc--;
array_shift($argv);

// get messages
while (1 < $argc)
{
$msg = $argv[1];
$obj = new Crypt_Xtea();

if ($flag_decrypt)
{
$binmsg = pack('H' . strlen($msg), $msg);
$result = $obj->decrypt($binmsg, $key);
}
else
{
$binmsg = $obj->encrypt($msg, $key);
$result = join('', unpack('H*', $binmsg));
}

// output result
echo $result;

// get next message
$argc--;
$arg = array_shift($argv);
}
?>
Something went wrong with that request. Please try again.