Source for file xtea.php

Documentation is available at xtea.php

  1. <?php
  2. //
  3. // xtea.php
  4. //
  5. // $Header: /cvs/ext/pear/Crypt_Xtea/tests/Attic/xtea.php,v 1.2 2004/10/04 18:54:19 jeroend Exp $
  6. //
  7. /**
  8. * @package Crypt_Xtea_Test
  9. * @module xtea
  10. * @access public
  11. *
  12. * @version $Revision: 1.2 $
  13. * @since 2002/Sep/30
  14. * @author Jeroen Derks <jeroen@derks.it>
  15. */
  16.  
  17. /** Crypt_Xtea class */
  18. '../Xtea.php';
  19.  
  20. $flag_decrypt = false; // do encryption by default
  21. $msg = ''; // initialize message to encrypt/decrypt
  22. $key = ''; // initialize key to use
  23.  
  24. $prog = basename($_SERVER['argv'][0]); // program name
  25. $argc = $_SERVER['argc']; // number of command line arguments
  26. $argv = $_SERVER['argv']; // command line arguments array
  27. // process command line flags
  28. while (1 < $argc && '-' == $argv[1]{0})
  29. {
  30. $argc--;
  31. $arg = $argv[1];
  32. array_shift($argv);
  33. if ('--' == $arg)
  34. break;
  35.  
  36. $arg = substr($arg, 1);
  37. while (0 < strlen($arg))
  38. {
  39. switch ($arg{0})
  40. {
  41. case 'd': $flag_decrypt = true; break;
  42. case 'e': $flag_decrypt = false; break;
  43. }
  44. $arg = substr($arg, 1);
  45. }
  46. }
  47.  
  48. // check required parameters
  49. if (2 >= $argc)
  50. {
  51. echo "usage: $prog [-de] key msg [ msg ... ]\n" .
  52. "\t-d\tdecrypt message\n" .
  53. "\t-e\tencrypt message (default action)\n";
  54. exit(1);
  55. }
  56.  
  57. // get key
  58. $key = $argv[1];
  59. $argc--;
  60. array_shift($argv);
  61.  
  62. // get messages
  63. while (1 < $argc)
  64. {
  65. $obj = new Crypt_Xtea();
  66. $msg = $argv[1];
  67.  
  68. if ($flag_decrypt)
  69. {
  70. $binmsg = pack('H' . strlen($msg), $msg);
  71. $result = $obj->decrypt($binmsg, $key);
  72. }
  73. else
  74. {
  75. $binmsg = $obj->encrypt($msg, $key);
  76. $result = join('', unpack('H*', $binmsg));
  77. }
  78.  
  79. // output result
  80. echo $result;
  81.  
  82. // get next message
  83. $argc--;
  84. $arg = array_shift($argv);
  85. $msg = '';
  86. }
  87. ?>

Documentation generated on Thu, 25 May 2006 15:31:27 +0200 by phpDocumentor 1.3.0RC3