PageRenderTime 33ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Auth_Yubico-2.4/example/Modhex_Calculator.php

#
PHP | 134 lines | 118 code | 7 blank | 9 comment | 25 complexity | 48374eb15d2972db96be0b2725dd76a4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * Created on May 25, 2009
  4. *
  5. */
  6. require_once 'Modhex.php';
  7. $FMT_TEXT = 'Plain text';
  8. $FMT_DEC = 'Number';
  9. $FMT_MODHEX = 'Modhex';
  10. $FMT_B64 = 'Base64';
  11. $FMT_HEX = 'Hex';
  12. $FMT_OTP = 'OTP';
  13. ?>
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  15. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  16. <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  17. <head>
  18. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  19. <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
  20. <title>Modehex Calculator</title>
  21. <link rel="stylesheet" type="text/css" href="style.css" />
  22. <style type="text/css">
  23. input[type="radio"] {
  24. width: 45px;
  25. }
  26. </style>
  27. </head>
  28. <body onLoad="document.getElementById('srctext').focus();">
  29. <div id="stripe">
  30. &nbsp;
  31. </div>
  32. <div id="container">
  33. <div id="logoArea">
  34. <img src="yubicoLogo.gif" alt="yubicoLogo" width="150" height="75"/>
  35. </div>
  36. <div id="greenBarContent">
  37. <div id="greenBarImage">
  38. <img src="yubikey.jpg" alt="yubikey" width="150" height="89"/>
  39. </div>
  40. <div id="greenBarText">
  41. <h3>
  42. Modhex Calculator
  43. </h3>
  44. </div>
  45. </div>
  46. <div id="bottomContent">
  47. <?php
  48. $srctext = trim($_REQUEST["srctext"]);
  49. $srcfmt = $_REQUEST["srcfmt"];
  50. $srcfmt_org = $srcfmt? $srcfmt: "P";
  51. $srcfmt_desc = '';
  52. if (strlen($srctext) > 0) {
  53. if($srcfmt == "O") {
  54. $srcfmt_desc = $FMT_OTP;
  55. $srctext = substr($srctext, 0, 12);
  56. $srcfmt = "M";
  57. }
  58. $b64txt = $srctext;
  59. if($srcfmt == "P") {
  60. $srcfmt_desc = $FMT_TEXT;
  61. $b64txt = base64_encode($srctext);
  62. } else if ($srcfmt == "H") {
  63. $srcfmt_desc = $FMT_HEX;
  64. $hexval = $srctext;
  65. $b64txt = hexToB64($hexval);
  66. //echo 'Test B64 : '.$b64txt.' :: '.$hexval;
  67. } else if ($srcfmt == "M") {
  68. if($srcfmt_desc == '') {
  69. $srcfmt_desc = $FMT_MODHEX;
  70. }
  71. if((strlen($srctext) % 2) == 1) {
  72. $srctext = 'c' . $srctext;
  73. }
  74. $b64txt = modhexToB64($srctext);
  75. } else if ($srcfmt == "N") {
  76. $srcfmt_desc = $FMT_DEC;
  77. //$numval = intval($srctext);
  78. $numval = gmp_init($srctext, 10);
  79. $hexval = gmp_strval($numval,16);
  80. //echo 'Test Val : '.$numval.' :: '.$hexval;
  81. $b64txt = hexToB64($hexval);
  82. //echo 'Test B64 : '.$b64txt;
  83. } else {
  84. $srcfmt_desc = $FMT_B64;
  85. }
  86. //$devId_b64 = modhexToB64($devId);
  87. ?>
  88. <fieldset>
  89. <legend><b>Result</b></legend>
  90. <b>Input string: </b><?php echo $srctext;?> (<?php echo $srcfmt_desc;?>)<br/><br>
  91. <b>Output string</b> (in various formats):
  92. <ul>
  93. <li><?php echo $FMT_TEXT . ': ' . base64_decode($b64txt); ?></li>
  94. <li><?php echo $FMT_DEC . ': ' . gmp_strval(gmp_init(b64ToHex($b64txt),16)); ?></li>
  95. <li><?php echo $FMT_MODHEX . ' encoded: ' . b64ToModhex($b64txt); ?></li>
  96. <li><?php echo $FMT_B64 . ' encoded: ' . $b64txt; ?></li>
  97. <li><?php echo $FMT_HEX . ' encoded: ' . b64ToHex($b64txt); ?></li>
  98. </ul>
  99. </fieldset>
  100. <br>
  101. <?php
  102. }
  103. ?>
  104. <form action=Modhex_Calculator.php method=post autocomplete=off>
  105. <fieldset>
  106. <legend><b>Number scheme calculator</b></legend>
  107. <ol>
  108. <li>Choose format.</li>
  109. <li>Enter string.</li>
  110. <li>Press &quot;Convert to all formats&quot; button.</li>
  111. </ol>
  112. <b>Source format:</b><br/>
  113. <input type="radio" name="srcfmt" value="P" <?php echo ($srcfmt_org == "P")?'checked':''; ?>>Plain text<br/>
  114. <input type="radio" name="srcfmt" value="N" <?php echo ($srcfmt_org == "N")?'checked':''; ?>>Number<br/>
  115. <input type="radio" name="srcfmt" value="B" <?php echo ($srcfmt_org == "B")?'checked':''; ?>>Base64<br/>
  116. <input type="radio" name="srcfmt" value="H" <?php echo ($srcfmt_org == "H")?'checked':''; ?>>Hex<br/>
  117. <input type="radio" name="srcfmt" value="O" <?php echo ($srcfmt_org == "O")?'checked':''; ?>>OTP<br/>
  118. <input type="radio" name="srcfmt" value="M" <?php echo ($srcfmt_org == "M")?'checked':''; ?>>Modhex<br/><br/>
  119. <b>String:</b>&nbsp;
  120. <input name="srctext" id="srctext" value="<?php echo $srctext?>" size=50 maxlength=50><br/><br/>
  121. <input type="submit" value="Convert to all formats">
  122. </fieldset>
  123. </form>
  124. </div>
  125. </div>
  126. </body>
  127. </html>