Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>PDU Converter</title>
- <style>
- * { font-family:Calibri }
- fieldset { margin-bottom: 15px; padding: 10px }
- legend { padding: 0px 3px; font-weight: bold; font-variant: small-caps }
- select { width: 254px }
- input[type=submit] { width: 170px; padding: 10px }
- </style>
- </head>
- <body>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
- <fieldset>
- <legend>Enter Text for encode to PDU format</legend>
- <textarea name="inputtext" cols="40" rows="5">
- <?php
- if (isset($_GET['inputtext']) && $_GET['inputtext'])
- {
- echo $_GET['inputtext'];
- }
- ?>
- </textarea>
- <textarea name="Text1" cols="40" rows="5" ... >
- <?php
- if (isset($_GET['inputtext']) && $_GET['inputtext'])
- {
- encodePDU($_GET['inputtext']);
- }
- ?>
- </textarea>
- </fieldset>
- <input type="submit" value="Encode">
- </form>
- <br>
- <br>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
- <fieldset>
- <legend>Enter PDU for decode to Text format</legend>
- <textarea name="inputpdu" cols="40" rows="5">
- <?php
- if (isset($_GET['inputpdu']) && $_GET['inputpdu'])
- {
- echo $_GET['inputpdu'];
- }
- ?>
- </textarea>
- <textarea name="Text2" cols="40" rows="5" ... >
- <?php
- if (isset($_GET['inputpdu']) && $_GET['inputpdu'])
- {
- decodePDU($_GET['inputpdu']);
- }
- ?>
- </textarea>
- </fieldset>
- <input type="submit" value="Decode">
- </form>
- </body>
- </html>
- <?php
- function decodePDU($in) {
- $b = 0; $d = 0;
- $out = "";
- foreach (str_split($in, 2) as $ss) {
- $byte = hexdec($ss);
- $c = (($byte & ((1 << 7-$d)-1)) << $d) | $b;
- $b = $byte >> (7-$d);
- $out .= chr($c);
- $d++;
- if ($d == 7) {
- $out .= chr($b);
- $d = 0; $b = 0;
- }
- }
- echo $out;
- }
- function encodePDU($in) {
- $out = "";
- for ($i = 0; $i < strlen($in); $i++) {
- $t = $i%8+1;
- if ($t == 8)
- continue;
- $c = ord($in[$i])>>($i%8);
- $oc = $c;
- $b = ord($in[$i+1]) & ((1 << $t)-1);
- $c = ($b << (8-$t)) | $c;
- $out .= strtoupper(str_pad(dechex($c), 2, '0', STR_PAD_LEFT));
- }
- echo $out;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement