function libdce_tests() { //Tests: test_add('<br><br><hr><br><h2>Begin test results</h2>'); //Input tests test_add('<h3>Begin input translator tests</h3>'); //CDCE test_add('<h4>Begin CDCE tests</h4>'); test_add('<h5>legacy_cdce</h5>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'legacy_cdce', 'dc'), '57,86,93,93,96,18,72,96,99,93,85,19'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'legacy_cdce', 'dc'), '57,86,93,93,96,18,1,72,96,99,93,85,8,19'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@8@!', 'legacy_cdce', 'dc'), '57,86,93,93,96,18,1,35,72,96,99,93,85,8,19'); test_add('<h5>cdce_lstrict</h5>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'cdce_lstrict', 'dc'), '57,86,93,93,96,18,72,96,99,93,85,19'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'cdce_lstrict', 'dc'), '57,86,93,93,96,18,1,72,96,99,93,85,8,19'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@8@!', 'cdce_lstrict', 'dc'), '57,86,93,93,96,18… CDCE decoding error!'); //DCE test_add('<h4>Begin DCE tests</h4>'); test_add('<h5>dce</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); //3_0a test_add('<h4>Begin DCE 3.0a tests</h4>'); test_add('<h5>3_0a</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), 'This document is not stored using the correct version of DCE.'); //3_01a //Needs UTF-8 encapsulation testing test_add('<h4>Begin DCE 3.01a tests</h4>'); test_add('<h5>3_01a</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), 'This document is not stored using the correct version of DCE.'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); //Dc test_add('<h4>Begin Dc tests</h4>'); test_add('<h5>dc</h5>'); test('Dc to Dc', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); //Output tests test_add('<br><br><h3>Begin output translator tests</h3>'); test_add('<h4>Begin Dc tests</h4>'); test_add('<h5>dc</h5>'); test('Dc to Dc', dce_convert('57,86,93,93,96,18,1,72,96,99,93,85,8,19', 'dc', 'dc'), '57,86,93,93,96,18,1,72,96,99,93,85,8,19'); global $testfail; if ($testfail) { test_add('<br><br><br><br><hr><br><br><br><br><h1><font color="red">SOME TESTS FAILED! LIBDCE DOES NOT APPEAR TO BE WORKING PROPERLY!</font></h1><br><br><br><br><hr><br><br><br><br>'); } test_add('<h3>End test results</h3><br><hr><br><br>'); }
function convert_utf8_dc64_enc_to_dc($data) { //DEPENDS: convert_utf8_dc64_to_dc if (substr($data, 0, 4) == '191,' && substr($data, strlen($data) - 4, 4) == ',192') { return dce_convert(substr($data, 4, strlen($data) - 8), 'utf8_dc64', 'dc'); } else { error_add('<font color="red">Error! This document is not stored using the specified format.</font>'); return 'This document is not stored using the specified format.'; } }
function convert_dce_to_dc($data) { //DEPENDS: all version-specific DCE translators supported by get_dce_version (currently supplied by dce_convert_1_43) $hex = strtolower(bin2hex($data)); if (substr($hex, 0, 12) !== '444345650201') { error_add('<font color="red">Error! This document is not stored using a supported format.</font>'); return 'This document is not stored using a supported format.'; } if (function_exists('convert_' . get_dce_version($data) . '_to_dc')) { return dce_convert($data, get_dce_version($data), 'dc'); } else { error_add('<font color="red">Error! This document does not appear to be stored using a supported version of DCE.</font>'); return 'This document does not appear to be stored using a supported version of DCE.'; } }
<?php //Request handler if (isset($_REQUEST['silenti'])) { if ($_REQUEST['hexadecimal'] == 1) { $result = hex2bin(dce_convert($_REQUEST['data'], $_REQUEST['source'], $_REQUEST['target'])); } else { $result = dce_convert($_REQUEST['data'], $_REQUEST['source'], $_REQUEST['target']); } echo 'Result: ' . $result; } else { }
function dceutils_tests() { //Tests: test_add('<br><br><hr><br><h2>Begin test results</h2>'); //Input tests test_add('<h3>Begin input translator tests</h3>'); //CDCE test_add('<h4>Begin CDCE tests</h4>'); test_add('<h5>cdce: This translator has not been implemented.</h5>'); test_add('<h5>legacy_cdce</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@13@@8@!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,1,35,72,96,99,93,85,1,35,37,1,8,19,115'); test_add('<h5>cdce_lstrict</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@13@@8@!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18… CDCE decoding error!'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc list to Legacy CDCE', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'legacy_cdce'), 'Hello World!'); test('Messy Dc list to Legacy CDCE', dce_convert('114,1,57,86,93,93,96,18,72,96,99,93,85,19,9,115', 'dc', 'legacy_cdce'), '@1@Hello World!@9@'); //DCE test_add('<h4>Begin DCE tests</h4>'); test_add('<h5>dce</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Hex DCE to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'dce', 'dc'), 'This document is not stored using the specified format.'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to DCE', dce_convert('Hello World!', 'utf8', 'dce'), hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03')); test_add('<h5>hex_dce</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_dce', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Mixed-case hex DCE 3.0a to Dc', dce_convert('44434565020101fd8048656c6C6F20576F726C642181FD03', 'hex_dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to Hex DCE', dce_convert('Hello World!', 'utf8', 'hex_dce'), '44434565020101FD8048656C6C6F20576F726C642181FD03'); //3_0a test_add('<h4>Begin DCE 3.0a tests</h4>'); test_add('<h5>3_0a</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), 'This document is not stored using the specified format.'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to DCE 3.0a', dce_convert('Hello World!', 'utf8', '3_0a'), hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03')); test_add('<h5>3_0a_raw</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), '3_0a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to DCE 3.0a Raw', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', '3_0a_raw'), hex2bin('8048656C6C6F20576F726C642181')); test_add('<h5>hex_3_0a</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_3_0a', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a', 'dc'), 'This document is not stored using the specified format.'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to Hex DCE 3.0a', dce_convert('Hello World!', 'utf8', 'hex_3_0a'), '44434565020101FD8048656C6C6F20576F726C642181FD03'); test_add('<h5>hex_3_0a_raw</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a Raw to Dc', dce_convert('8048656C6C6F20576F726C642181', 'hex_3_0a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to Hex DCE 3.0a Raw', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'hex_3_0a_raw'), '8048656C6C6F20576F726C642181'); //3_01a //Needs UTF-8 encapsulation testing test_add('<h4>Begin DCE 3.01a tests</h4>'); test_add('<h5>3_01a</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), 'This document is not stored using the specified version of DCE.'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test_add('3_01a: This translator currently does not work well.<br>'); //test('UTF-8 to DCE 3.01a', dce_convert('Hello World!', 'utf8', '3_01a'), hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03')); test_add('<h5>3_01a_raw</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Simple DCE 3.01a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), '3_01a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex DCE 3.01a Raw to Dc', dce_convert(hex2bin('80C501FE48656C6C6F20576F726C642181'), '3_01a_raw', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>hex_3_01a</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'hex_3_01a', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), 'This document is not stored using the specified version of DCE.'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex Hex DCE 3.01a to Dc', dce_convert('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test_add('3_01a: This translator currently does not work well.<br>'); //test('UTF-8 to Hex DCE 3.01a', dce_convert('Hello World!', 'utf8', 'hex_3_01a'), '44434565020102FD8048656C6C6F20576F726C642181FD03'); test_add('<h5>hex_3_01a_raw</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple DCE 3.01a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple Hex DCE 3.01a Raw to Dc', dce_convert('8048656C6C6F20576F726C642181', 'hex_3_01a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex Hex DCE 3.01a Raw to Dc', dce_convert('80C501FE48656C6C6F20576F726C642181', 'hex_3_01a_raw', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); //Dc test_add('<h4>Begin Dc tests</h4>'); test_add('<h5>dc</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Dc to Dc', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to Dc, simple', dce_convert('114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115', 'dc', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Dc to Dc, source missing boundedness markings', dce_convert('57,86,93,93,96,18,1,72,96,99,93,85,8,19', 'dc', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); //Unicode //These tests assume that Unicode encapsulation is not supported (it isn't, at the moment). test_add('<h4>Begin Unicode tests</h4>'); test_add('<h5>utf8</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('UTF-8 to Dc, simple', dce_convert('Hello World!', 'utf8', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-8 to Dc, messy', dce_convert('Hello— –World!', 'utf8', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-8 to Dc, non-BMP', dce_convert('🌄 Hello World! 🌄', 'utf8', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to UTF-8, simple', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'utf8'), 'Hello World!'); test('Dc to UTF-8, messy', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,8,19,115', 'dc', 'utf8'), 'Hello World�!'); test_add('<h5>utf8_base64</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Base64 UTF-8 to Dc, simple', dce_convert(base64_encode('Hello World!'), 'utf8_base64', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Base64 UTF-8 to Dc, messy', dce_convert(base64_encode('Hello— –World!'), 'utf8_base64', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Base64 UTF-8 to Dc, non-BMP', dce_convert(base64_encode('🌄 Hello World! 🌄'), 'utf8_base64', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to Base64 UTF-8, simple', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'utf8_base64'), 'SGVsbG8gV29ybGQh'); test('Dc to Base64 UTF-8, messy', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,8,19,115', 'dc', 'utf8_base64'), 'SGVsbG8gV29ybGTvv70h'); test_add('<h5>utf8_dc64</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('Raw Base64 Dc list encapsulated Unicode to Dc', dce_convert('145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160', 'utf8_dc64', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Dc to Dc', dce_convert('114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115', 'utf8_dc64', 'dc'), 'This document is not stored using the specified format.'); test('Base64 Dc list encapsulated Unicode to Dc', dce_convert('191,145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160,192', 'utf8_dc64', 'dc'), 'This document is not stored using the specified format.'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to raw UTF-8 Base64 Dc list', dce_convert('Hello World!', 'utf8', 'utf8_dc64'), '145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160'); test_add('<h5>utf8_dc64_enc</h5>'); //TODO: CHECK THIS TRANSLATOR! test_add('<small><i><b>Input:</b></i></small><br>'); test('Raw Base64 Dc list encapsulated Unicode to Dc', dce_convert('145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160', 'utf8_dc64_enc', 'dc'), 'This document is not stored using the specified format.'); test('Base64 Dc list encapsulated Unicode to Dc', dce_convert('191,145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160,192', 'utf8_dc64_enc', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to UTF-8 Base64 Dc list', dce_convert('Hello World!', 'utf8', 'utf8_dc64_enc'), '191,145,133,148,171,154,133,187,159,148,181,188,177,154,133,143,160,192'); test_add('<h5>utf8_dc64_bin</h5>'); //TODO: CHECK THIS TRANSLATOR! test_add('<small><i><b>Input:</b></i></small><br>'); test('Raw UTF-8 Base64 DCE binary fragment to Dc', dce_convert(hex2bin('948897AE9D88BEA297B8BFB49D8892A3'), 'utf8_dc64_bin', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to raw UTF-8 Base64 DCE binary fragment', dce_convert('Hello World!', 'utf8', 'utf8_dc64_bin'), hex2bin('948897AE9D88BEA297B8BFB49D8892A3')); test_add('<h5>utf8_dc64_bin_hex</h5>'); //TODO: CHECK THIS TRANSLATOR! test_add('<small><i><b>Input:</b></i></small><br>'); test('Raw UTF-8 Base64 DCE hex fragment to Dc', dce_convert('948897AE9D88BEA297B8BFB49D8892A3', 'utf8_dc64_bin_hex', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to raw UTF-8 Base64 DCE hex fragment', dce_convert('Hello World!', 'utf8', 'utf8_dc64_bin_hex'), '948897AE9D88BEA297B8BFB49D8892A3'); test_add('<h5>utf8_dc64_bin_enc</h5>'); //TODO: CHECK THIS TRANSLATOR! test_add('<small><i><b>Input:</b></i></small><br>'); test('Encapsulated UTF-8 Base64 DCE binary fragment to Dc', dce_convert(hex2bin('C3948897AE9D88BEA297B8BFB49D8892A3C4'), 'utf8_dc64_bin_enc', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to UTF-8 Base64 DCE encapsulated binary', dce_convert('Hello World!', 'utf8', 'utf8_dc64_bin_enc'), hex2bin('C3948897AE9D88BEA297B8BFB49D8892A3C4')); test_add('<h5>utf8_dc64_bin_enc_hex</h5>'); //TODO: CHECK THIS TRANSLATOR! test_add('<small><i><b>Input:</b></i></small><br>'); test('Encapsulated UTF-8 Base64 DCE hex fragment to Dc', dce_convert('C3948897AE9D88BEA297B8BFB49D8892A3C4', 'utf8_dc64_bin_enc_hex', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('UTF-8 to UTF-8 Base64 DCE encapsulated hex', dce_convert('Hello World!', 'utf8', 'utf8_dc64_bin_enc_hex'), 'C3948897AE9D88BEA297B8BFB49D8892A3C4'); test_add('<h5>utf32</h5>'); test_add('<small><i><b>Input:</b></i></small><br>'); test('UTF-8 to Dc', dce_convert('Hello World!', 'utf32', 'dc'), 'This document is not stored using the specified format.'); test('UTF-32 to Dc, simple', dce_convert(iconv('UTF-8', 'UTF-32BE', 'Hello World!'), 'utf32', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-32 to Dc, messy', dce_convert(iconv('UTF-8', 'UTF-32BE', 'Hello— –World!'), 'utf32', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-32 to Dc, non-BMP', dce_convert(iconv('UTF-8', 'UTF-32BE', '🌄 Hello World! 🌄'), 'utf32', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<small><i><b>Output:</b></i></small><br>'); test('Dc to UTF-32, simple', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'utf32'), iconv('UTF-8', 'UTF-32BE', 'Hello World!')); test('Dc to UTF-32, messy', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,8,19,115', 'dc', 'utf32'), iconv('UTF-8', 'UTF-32BE', 'Hello World�!')); //Miscellaneous tests test_add('<br><br><h3>Begin miscellaneous tests</h3>'); test('Nonexistent input format', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'foo', 'dc'), 'Unknown input format.'); test('Nonexistent output format', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'foo'), 'Unknown output format.'); test('Get DCE version: DCE 3.0a', get_dce_version(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03')), '3_0a'); test('Get DCE version: DCE 3.01a, complex', get_dce_version(hex2bin('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03')), '3_01a'); test('Get DCE version: Not DCE', get_dce_version('DOOM'), 'This document does not appear to be stored using DCE.'); //test('Raw Base64 Dc list encapsulated Unicode to Base64 Dc list encapsulated Unicode', dce_convert('156,133,148,178,156,127,195,195','utf8_dc64','utf8_dc64_enc'), '114,191,156,133,148,178,156,127,195,195,192,115'); global $testfail; if ($testfail) { test_add('<br><br><br><br><hr><br><br><br><br><h1><font color="red">SOME TESTS FAILED! LIBDCE DOES NOT APPEAR TO BE WORKING PROPERLY!</font></h1><br><br><br><br><hr><br><br><br><br>'); } test_add('<h3>End test results</h3><br><hr><br><br>'); }
function legacy_cdce_parse($content, $strict) { //$dc=$txt; $hex = bin2hex(iconv('UTF-8', 'UTF-32BE', $content)); //echo '<br>'; //echo '<br>'; //echo $data; //echo '<br>'; //echo '<br>'; //echo $hex; //echo '<br>'; //echo '<br>'; //echo dce_convert(hex2bin($hex), 'utf32', 'dc'); //echo '<br>'; //echo '<br>'; global $DcMap_Unicode_Lossy; global $cdce_html_legacy; $counter = 0; $txt = ''; while ($counter < strlen($hex)) { log_add('<br>'); log_add('Bytes: ' . substr($hex, $counter, 48) . '…<br>'); log_add('UTF-8: ' . hex2bin(ltrim(substr($hex, $counter, 192), '0')) . '<br>'); log_add('Dc: ' . dce_convert(hex2bin(ltrim(substr($hex, $counter, 192), '0')), 'utf8', 'dc') . '<br>'); if (substr($hex, $counter, 8) == '00000040') { //Conditions: //1char log_add('<br><br><font color="green">1 character CDCE conditions: <br>'); //echo ((int) substr($hex, $counter + 16, 8) == '00000040')+0; //echo ((int) substr($hex, $counter + 32, 8) == '00000040')+0; //fails incorrectly log_add(substr($hex, $counter + 0, 8) . '. Should be: 00000040<br>'); log_add(substr($hex, $counter + 16, 8) . '. Should be: 00000040<br>'); log_add(hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . '. Should be: greater than 0<br>'); log_add(hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . '. Should be: less than 13<br><br>→'); log_add(((int) substr($hex, $counter + 0, 8) == '00000040') + 0); //this works log_add(((int) substr($hex, $counter + 16, 8) == '00000040') + 0); //this works log_add(((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) > '0') + 0); log_add(((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) < '13') + 0); log_add('<br><br><br>2 character CDCE conditions: <br>'); //2char log_add(substr($hex, $counter + 0, 8) . '. Should be: 00000040<br>'); log_add(substr($hex, $counter + 24, 8) . '. Should be: 00000040<br>'); log_add(hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) . '. Should be: greater than 0<br>'); log_add(hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) . '. Should be: less than 13<br>'); //echo hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . '. Should be: greater than 0<br>'; //echo hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . '. Should be: less than 13<br>'; //echo hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) . '. Should be: greater than 0<br>'; //echo hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) . '. Should be: less than 13<br><br>→'; log_add(((int) substr($hex, $counter + 0, 8) == '00000040') + 0); log_add(((int) substr($hex, $counter + 24, 8) == '00000040') + 0); log_add(((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) > '0') + 0); log_add(((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) < '13') + 0); //echo ((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) > '0')+0; //echo ((int) hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) < '13')+0; //echo ((int) hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) > '0')+0; //echo ((int) hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) < '13')+0; log_add('<br><br></font>'); if (substr($hex, $counter + 0, 8) == '00000040' && substr($hex, $counter + 16, 8) == '00000040' && hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) > '0' && hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) < '13') { $append = hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . ','; $counter = $counter + 16; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. 1-character Dc appended (' . hex2bin(ltrim(substr($hex, $counter - 8, 8), '0')) . '): ' . $append . ' → ' . $txt . $append); log_add('<br></font>'); } else { if (substr($hex, $counter + 0, 8) == '00000040' && substr($hex, $counter + 24, 8) == '00000040' && hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) > 0 && hex2bin(ltrim(substr($hex, $counter + 8, 8), '0')) . hex2bin(ltrim(substr($hex, $counter + 16, 8), '0')) < 13) { $append = hex2bin(ltrim(substr($hex, $counter + 8, 8), '0') . ltrim(substr($hex, $counter + 16, 8), '0')) . ','; $counter = $counter + 24; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. 2-character Dc appended (' . hex2bin(ltrim(substr($hex, $counter - 16, 16), '0')) . '): ' . $append . ' → ' . $txt . $append); log_add('<br></font>'); } else { if ($strict) { log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. CDCE decoding error!' . ' → ' . $txt . $append); log_add('<br></font>'); return str_replace(',,', ',0,', preg_replace('/,\\Z/', '', $txt)) . '… CDCE decoding error!'; } else { if (strlen($DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))]) != 0) { $append = $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))] . ','; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. Unicode appended; attempting recovery of corrupted CDCE data: ' . $append . ' → ' . $txt . $append); log_add('<br></font>'); } else { $append = ''; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. Unicode not appended; attempting recovery of corrupted CDCE data' . ' → ' . $txt . $append); log_add('<br></font>'); } } } } } else { if (strlen($DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))]) != 0) { $append = $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))] . ','; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. Unicode appended: ' . $append . ' → ' . $txt . $append); log_add('<br></font>'); } else { $append = ''; log_add('<br><font color="red">'); log_add($counter / 8 + 1 . '. Unicode not appended' . ' → ' . $txt . $append); log_add('<br></font>'); } } // $txt = $txt . $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0')) ] . ','; $txt = $txt . $append; //$txt=$txt; $counter = $counter + 8; } //echo $txt; $dc = $txt; return $dc; }
function convert_utf8_dc64_to_dc($data) { global $Dc_to_Base64; $dcarray = explode_escaped(',', $data); // print_r($dcarray); $dcarray_size = count($dcarray); // echo $dcarray_size; $counter = 0; $dcb64 = ''; while ($counter < $dcarray_size) { //echo $Dc_to_Base64[$dcarray[$counter]]; $dcb64 = $dcb64 . $Dc_to_Base64[$dcarray[$counter]]; $counter++; } //echo $dcb64; return dce_convert(base64_decode($dcb64), 'utf8', 'dc'); }
function convert_utf8_dc64_bin_enc_hex_to_dc($data) { return dce_convert(substr($data, 2, -2), 'utf8_dc64_bin_hex', 'dc'); }
function dce_convert($data, $input_format, $output_format) { $html_opening = '<html><head><title></title></head><body>'; $html_closing = '</body></html>'; $onestep = false; $final = ''; //echo $output_format; /* if ($output_format == 'utf32') { header('Content-type: text/plain; charset=utf-32'); } else { header('Content-type: text/plain'); } */ //Ideally how this works: Convert the input into an array of Dc IDs, and then write that out using the selected translator. /* Input formats: dc, dce, 3_0a, utf32, utf8, cdce, legacy_cdce Output formats: dc, dce, 3_0a, utf32, utf8, html, cdce, legacy_cdce */ switch ($input_format) { case 'dc': $dc = $data; break; case 'dce': $hex = strtolower(bin2hex($data)); if (substr($hex, 0, 12) !== '444345650201') { return 'This document is not stored using a supported format.'; break; } switch (get_dce_version($data)) { //This next block is the old method. /*case '3_0a': //###################################################### //This is a DCE 3.0a file. It doesn't need to be updated. This case will though! global $dce3_0a_core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $dce3_0a_core[hexdec(substr($hex, $counter, 2)) ]; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } r: return $txt; $data = $data; break; */ case '3_0a': //###################################################### //This is a DCE 3.0a file. global $DcMap_dce3_0a_Core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $DcMap_dce3_0a_Core[strtoupper(substr($hex, $counter, 2))] . ','; //echo $txt; //$txt=$txt; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } //echo $txt; //echo '<br>'; //echo '<br>'; $txt = substr($txt, 3, strlen($txt) - 6); //echo $txt;echo '<br>';echo '<br>'; // return $txt; $dc = $txt; break; default: return 'This document is not stored using a supported version of DCE.'; break; } break; case 'utf32': $unicode = iconv('UTF-32BE', 'UTF-8', $data); return dce_convert($unicode, 'utf8', $output_format); break; case 'utf8': ini_set("display_errors", 0); $unicode = iconv('UTF-8', 'UTF-32BE', $data); $hex = bin2hex($unicode); //echo $hex; global $DcMap_Unicode_Lossy; $counter = 0; $txt = ''; while ($counter < strlen($hex)) { // $byte=strtoupper(ltrim(substr($hex, $counter, 8),'0')); // echo'<br>';echo $byte;echo'<br>'; //echo $txt; //echo '<br>'; //echo $counter; if (strlen($DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))]) != 0) { $append = $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))] . ','; } else { $append = ''; } // $txt = $txt . $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0')) ] . ','; $txt = $txt . $append; //echo $txt; //$txt=$txt; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 8; } //echo $txt; //echo '<br>'; //echo '<br>'; //$txt = substr($txt, 3, (strlen($txt) - 6)); //echo $txt;echo '<br>';echo '<br>'; // return $txt; $dc = $txt; break; case 'cdce': break; case 'legacy_cdce': // global $output_format; // global $onestep; // global $finished; // global $html_opening; // global $html_closing; switch ($output_format) { case 'html': // global $onestep; // global $finished; $onestep = 1; $finished = $html_opening . legacy_cdce_to_html_snippet($data) . $html_closing; echo $onestep; echo $finished; echo $html_opening; case 'html_snippet': // global $onestep; // global $finished; // global $html_opening; // global $html_closing; $onestep = 1; $finished = legacy_cdce_to_html_snippet($data); default: //$dc=$txt; } $dc = ''; break; default: $dc = ''; return 'Unknown input format: ' . $input_format . '. Available: dc, dce, 3_0a, utf8, utf32'; break; } //global $onestep; //$onestep="meuou"; //echo $onestep; if ($onestep == "1") { return $finished; //echo 'test'; echo 'doom'; } else { // echo 'doom 2'; $dc = preg_replace('/,\\Z/', '', $dc); $dc = str_replace(',,', ',0,', $dc); // echo '<br>'; // echo $dc; // echo '<br>'; $dc_array = explode_escaped(',', $dc); // print_r($dc_array); // echo '<br>'; $dc_size = count($dc_array); // echo $dc_size; // echo '<br>'; switch ($output_format) { case 'dc': return $dc; break; case 'dce': return dce_convert($dc, 'dc', '3_0a'); break; case '3_0a': global $DcMapSend_dce3_0a; $counter = 0; $txt = '44434565020101fd'; // echo '<br>'; while ($counter < $dc_size) { $txt = $txt . strtolower($DcMapSend_dce3_0a[$dc_array[$counter]]); // echo $counter; // echo ': '; // echo $txt; //$txt=$txt; // echo '<br>'; $counter++; } $txt = $txt . 'fd03'; //$txt = substr($txt, 0, (strlen($txt) - 1)); return hex2bin($txt); // $dc = $txt; break; case 'utf8': global $DcMapSend_Unicode; $counter = 0; $txt = ''; // echo '<br>'; while ($counter < $dc_size) { $txt = $txt . str_pad(strtolower($DcMapSend_Unicode[$dc_array[$counter]]), 8, "0", STR_PAD_LEFT); //echo '<br>'; //echo $dc_array[$counter] . ': ' . $txt; //echo '<br>'; // echo $counter; // echo ': '; // echo $txt; //$txt=$txt; // echo '<br>'; $counter++; } // $txt = $txt . 'fd03'; //$txt = substr($txt, 0, (strlen($txt) - 1)); return iconv('UTF-32BE', 'utf8', hex2bin($txt)); // $dc = $txt; // break; // return dce2txt($data); break; case 'utf32': $unicode = bin2hex(iconv('UTF-8', 'UTF-32BE', dce_convert($dc, 'dc', 'utf8'))); //echo dce_convert($dc, 'dc', 'utf8'); //echo $unicode; return hex2bin($unicode); break; case 'html': break; case 'cdce': break; case 'legacy_cdce': break; default: global $output_format; return 'Unknown output format: ' . $output_format . '. Available: dc, dce, 3_0a, utf8, html'; } } function x2dce($data, $format) { } function dce2x($data, $format) { //$hex=bin2hex($data); switch ($format) { case 'txt': return dce2txt($data); break; } } function get_dce_version($data) { $hex = strtolower(bin2hex($data)); if (substr($hex, 0, 12) !== '444345650201') { return 'This document is not stored using a supported format.'; break; } switch (substr($hex, 12, 2)) { case 01: //This is a DCE 3.0a file return '3_0a'; break; default: return 'This document is not stored using a supported version of DCE.'; } } function dce2txt($data) { $hex = strtolower(bin2hex($data)); // echo '<br>'; // echo $hex; // echo '<br>'; // echo substr($hex, 12, 2); // echo substr($hex, 0, 12); if (substr($hex, 0, 12) !== '444345650201') { return 'This document is not stored using a supported format.'; break; } switch (get_dce_version($data)) { case '3_0a': //This is a DCE 3.0a file global $dce3_0a_core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $dce3_0a_core[hexdec(substr($hex, $counter, 2))]; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } r: return $txt; break; default: return 'This document is not stored using a supported version of DCE.'; } } }
function convert_dc_to_utf32_output($data) { //DEPENDS: convert_dc_to_utf8_output $unicode = bin2hex(iconv('UTF-8', 'UTF-32BE', dce_convert($data, 'dc', 'utf8'))); return hex2bin($unicode); }
function dce_convert($data, $input_format, $output_format = "none", $output_log = false) { if ($input_format == "legacy_cdce") { $strict = false; } else { if ($input_format == "cdce_lstrict") { $strict = true; } } $html_opening = '<html><head><title></title></head><body>'; $html_closing = '</body></html>'; $onestep = false; $final = ''; //echo $output_format; /* if ($output_format == 'utf32') { header('Content-type: text/plain; charset=utf-32'); } else { header('Content-type: text/plain'); } */ //Ideally how this works: Convert the input into an array of Dc IDs, and then write that out using the selected translator. switch ($input_format) { case 'dc': $dc = $data; break; case 'utf8_base64': $dc = dce_convert(base64_decode($data), 'utf8', 'dc'); break; case 'utf8_dc64': $dc = dce_convert(base64_3_01a_to_unicode($data), 'utf8', 'dc'); break; case 'hex_dce': $dc = dce_convert(hex2bin($data), 'dce', 'dc'); break; case 'hex_3_0a': $dc = dce_convert(hex2bin($data), '3_0a', 'dc'); break; case 'hex_3_01a': $dc = dce_convert(hex2bin($data), '3_01a', 'dc'); break; case 'dce2txt': return dce2txt($data); break; case 'dce2hex': return dce2hex($data); break; case 'hex2dce': return hex2dce($data); break; case '3_0a_old': //This next block is the old decoder. //###################################################### //This is a DCE 3.0a file. It doesn't need to be updated. This case will though! global $dce3_0a_core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $dce3_0a_core[hexdec(substr($hex, $counter, 2))]; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } r: return $txt; $data = $data; break; case 'dce': $hex = strtolower(bin2hex($data)); if (substr($hex, 0, 12) !== '444345650201') { return 'This document is not stored using a supported format.'; break; } switch (get_dce_version($data)) { case '3_0a': //###################################################### //This is a DCE 3.0a file. global $DcMap_dce3_0a_Core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $DcMap_dce3_0a_Core[strtoupper(substr($hex, $counter, 2))] . ','; //echo $txt; //$txt=$txt; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } //echo $txt; //echo '<br>'; //echo '<br>'; $txt = substr($txt, 3, strlen($txt) - 6); //echo $txt;echo '<br>';echo '<br>'; // return $txt; $dc = $txt; break; case '3_01a': //###################################################### //This is a DCE 3.01a file. global $DcMap_dce3_01a_Core; global $DcMap_dce3_01a_Variant_Selectors; global $DcMap_dce3_01a_Semantic_Records; global $DcMap_dce3_01a_Mathematics; global $DcMap_dce3_01a_Whitespace_and_Punctuation; global $Dc_to_Base64; $counter = 14; $txt = ''; $state = 'Core'; $varAppend = 'DcMap_dce3_01a_'; while ($counter < strlen($hex)) { $action_last = $action; //log_add('<br><font color="red">' . ((($counter - 14) / 2) + 1) . ': </font><br>State: ' .$state. '<br>Hex position: ' . substr($hex, $counter, 2). '<br>Dc ID: '. $DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2)) ].'<br>Appending: '); //echo $state; echo '<br>'; //echo ''; echo '<br>'; $data_array_name = $varAppend . $state; $data_array = ${$data_array_name}; switch ($state) { case 'Core': if (substr($DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2))], 0, 1) == '>') { //Switch states $state = substr($DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2))], 1, strlen($DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2))]) - 1); $append = ''; $action = 'State switch out of Core) <br>'; //echo 'hit'; break; } else { ////////////////////////////////This is of no concern. Embedded Unicode should be preserved in its embedded state until being converted *out* of Dc. D'oh. /* if ($DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2)) ] == '191') { //Unicode embedded while (substr($hex, $counter + 2, 2) != 'C4') { $counter = $counter + 2; // $unicode_decode = $unicode_decode . $Dc_to_Base64[$DcMap_dce3_01a_Core[substr($hex, $counter, 2) ]]; } // $unicode = base64_decode($unicode_decode); // $txt = $txt . '' . $unicode . ''; } else */ $append = $DcMap_dce3_01a_Core[strtoupper(substr($hex, $counter, 2))] . ','; $action = 'Append from Core) <br>'; } break; case 'Variant_Selectors': if (substr($hex, $counter, 2) == 'fd' || substr($hex, $counter, 2) == 'fe') { $state = 'Core'; $append = ''; $action = 'State switch out of Variant_Selectors) <br>'; } else { $append = $DcMap_dce3_01a_Variant_Selectors[strtoupper(substr($hex, $counter, 2))] . ','; $action = 'Append from Variant_Selectors) <br>'; } break; case 'Semantic_Records': if (substr($hex, $counter, 2) == 'fd' || substr($hex, $counter, 2) == 'fe') { $state = 'Core'; $append = ''; $action = 'State switch out of Semantic_Records) <br>'; } else { $append = $DcMap_dce3_01a_Semantic_Records[strtoupper(substr($hex, $counter, 2))] . ','; $action = 'Append from Semantic_Records) <br>'; } break; case 'Mathematics': if (substr($hex, $counter, 2) == 'fd' || substr($hex, $counter, 2) == 'fe') { $state = 'Core'; $append = ''; $action = 'State switch out of Mathematics) <br>'; } else { $append = $DcMap_dce3_01a_Mathematics[strtoupper(substr($hex, $counter, 2))] . ','; $action = 'Append from Mathematics) . <br>'; } break; case 'Whitespace_and_Punctuation': if (substr($hex, $counter, 2) == 'fd' || substr($hex, $counter, 2) == 'fe') { $state = 'Core'; $append = ''; $action = 'State switch out of Whitespace_and_Punctuation) <br>'; } else { $append = $DcMap_dce3_01a_Whitespace_and_Punctuation[strtoupper(substr($hex, $counter, 2))] . ','; $action = 'Append from Whitespace_and_Punctuation) <br>'; } break; } //echo $txt; //$txt=$txt; //echo '<br>' . substr($hex, $counter + 2, 4) . '<br>' . $txt . '<br>'; if (substr($hex, $counter + 2, 4) == 'fd03') { $action = '<br>Halting. <br>'; break; } $txt = $txt . $append; // echo '<br><font color="red">' . ((($counter - 14) / 2) + 1) . ': ' . substr($hex, $counter, 2) . '</font> → ' . $txt . ' (Action: ' . $action; $counter = $counter + 2; //log_add(rtrim($append,',').'<br>Action: '.substr($action,0,(strlen($action)-6)) . '<br><font color="green">→ ' . $txt . '</font><br><br>'); //echo $action;echo '<br>'; } //log_add(rtrim($append,',').'<br>Action: '.substr($action,4,(strlen($action)-5)) . '<br><br><br><br>'); //echo $txt; //echo '<br>'; //echo '<br>'; $txt = substr($txt, 3, strlen($txt) - 4); //echo '<br>';echo $txt;echo '<br>'; //echo $txt;echo '<br>';echo '<br>'; // return $txt; $dc = $txt; break; default: return 'This document is not stored using a supported version of DCE.'; break; } break; case 'utf32': $unicode = iconv('UTF-32BE', 'UTF-8', $data); return dce_convert($unicode, 'utf8', $output_format); break; case 'utf8': ini_set("display_errors", 0); $unicode = iconv('UTF-8', 'UTF-32BE', $data); $hex = bin2hex($unicode); //echo $hex; global $DcMap_Unicode_Lossy; $counter = 0; $txt = ''; while ($counter < strlen($hex)) { // $byte=strtoupper(ltrim(substr($hex, $counter, 8),'0')); // echo'<br>';echo $byte;echo'<br>'; //echo $txt; //echo '<br>'; //echo $counter; if (strlen($DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))]) != 0) { $append = $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0'))] . ','; } else { $append = ''; } // $txt = $txt . $DcMap_Unicode_Lossy[strtoupper(ltrim(substr($hex, $counter, 8), '0')) ] . ','; $txt = $txt . $append; //echo $txt; //$txt=$txt; //if (substr($hex, $counter, 4) == 'fd03') { // break; // } $counter = $counter + 8; } //echo $txt; //echo '<br>'; //echo '<br>'; //$txt = substr($txt, 3, (strlen($txt) - 6)); //echo $txt;echo '<br>';echo '<br>'; // return $txt; $dc = $txt; break; case 'cdce': break; case 'legacy_cdce': // global $output_format; // global $onestep; // global $finished; // global $html_opening; // global $html_closing; switch ($output_format) { case 'html_l': // global $onestep; // global $finished; $onestep = 1; $finished = $html_opening . legacy_cdce_to_html_snippet($data) . $html_closing; //echo $onestep; //echo $finished; //echo $html_opening; break; case 'html_snippet_l': // global $onestep; // global $finished; // global $html_opening; // global $html_closing; $onestep = 1; $finished = legacy_cdce_to_html_snippet($data); break; default: $dc = legacy_cdce_parse($data, $strict); break; } case 'cdce_lstrict': // global $output_format; // global $onestep; // global $finished; // global $html_opening; // global $html_closing; switch ($output_format) { case 'html_l': // global $onestep; // global $finished; $onestep = 1; $finished = $html_opening . legacy_cdce_to_html_snippet($data) . $html_closing; return $finished; //echo $onestep; //echo $finished; //echo $html_opening; break; case 'html_snippet_l': // global $onestep; // global $finished; // global $html_opening; // global $html_closing; $onestep = 1; $finished = legacy_cdce_to_html_snippet($data); return $finished; break; default: $dc = legacy_cdce_parse($data, $strict); break; } break; default: $dc = ''; //echo $dc; return 'Unknown input format: ' . $input_format . '. Available: dc, dce, 3_0a, 3_01a, legacy_cdce, cdce_lstrict, utf8, utf32'; break; } //global $onestep; //$onestep="meuou"; //echo $onestep; if ($onestep == "1") { return $finished; //echo 'test'; //echo 'doom'; //##################################################################### //OUTPUT TRANSLATORS BEGIN HERE } else { // echo 'doom 2'; $dc = preg_replace('/,\\Z/', '', $dc); $dc = str_replace(',,', ',0,', $dc); // echo '<br>'; // echo $dc; // echo '<br>'; $dc_array = explode_escaped(',', $dc); // print_r($dc_array); // echo '<br>'; $dc_size = count($dc_array); // echo $dc_size; // echo '<br>'; switch ($output_format) { case 'none': break; case 'utf8_base64': return base64_encode(dce_convert($dc, 'dc', 'utf8')); break; case 'utf8_dc64': if ($input_format == 'utf8') { return unicode_to_base64_3_01a($data); } else { if ($input_format == 'ucs32') { return iconv('UTF-32BE', 'UTF-8', unicode_to_base64_3_01a($data)); } else { echo dce_convert($data), $input_format, 'utf8'; return unicode_to_base64_3_01a(dce_convert($data), $input_format, 'utf8'); } } break; case 'utf8_dc64_bin': $dc64 = dce_convert($data, $input_format, 'utf8_dc64'); //Unless the layout of the base64 encapsulation characters changes, the following line doesn't need to be updated with new DCE versions, I don't think… //global $DcMapSend_dce3_01a_Core; //$dcarray = explode_escaped(',', $dc64); // print_r($dcarray); //$dcarray_size = count($dcarray); // echo $dcarray_size; //$counter = 0; //$dcb64 = ''; //while ($counter < $dcarray_size) { //echo $Dc_to_Base64[$dcarray[$counter]]; //$dcb64 = $dcb64 . $DcMapSend_dce3_01a_Core[$dcarray[$counter]]; //$counter++; //} return DcMapSendSimple($dc64); break; case 'hex_dce': return bin2hex(dce_convert($dc, 'dc', 'dce')); break; case 'hex_3_0a': return bin2hex(dce_convert($dc, 'dc', '3_0a')); break; case 'hex_3_01a': return bin2hex(dce_convert($dc, 'dc', '3_01a')); break; case 'dc': return $dc; break; case 'dce': return dce_convert($dc, 'dc', '3_0a'); break; case '3_0a': //echo $dc; global $DcMapSend_dce3_0a; $counter = 0; $txt = '44434565020101fd'; // echo '<br>'; while ($counter < $dc_size) { $txt = $txt . strtolower($DcMapSend_dce3_0a[$dc_array[$counter]]); // echo $counter; // echo ': '; // echo $txt; //$txt=$txt; // echo '<br>'; $counter++; } $txt = $txt . 'fd03'; //echo $txt; //$txt = substr($txt, 0, (strlen($txt) - 1)); return hex2bin($txt); // $dc = $txt; break; case '3_01a': /* global $DcMapSend_dce3_01a; $counter = 0; $txt = '44434565020102fd'; // echo '<br>'; while ($counter < $dc_size) { $txt = $txt . strtolower($DcMapSend_dce3_01a[$dc_array[$counter]]); // echo $counter; // echo ': '; // echo $txt; //$txt=$txt; // echo '<br>'; $counter++; } $txt = $txt . 'fd03'; //$txt = substr($txt, 0, (strlen($txt) - 1)); // $dc = $txt;*/ //echo $dc; $Encoded = DcMapSendSimple($dc, '3_01a'); $txt = '44434565020102fd' . $Encoded . 'fd03'; return hex2bin($txt); break; case 'utf8': global $DcMapSend_Unicode; $counter = 0; $txt = ''; // echo '<br>'; while ($counter < $dc_size) { $txt = $txt . str_pad(strtolower($DcMapSend_Unicode[$dc_array[$counter]]), 8, "0", STR_PAD_LEFT); //echo '<br>'; //echo $dc_array[$counter] . ': ' . $txt; //echo '<br>'; // echo $counter; // echo ': '; // echo $txt; //$txt=$txt; // echo '<br>'; $counter++; } // $txt = $txt . 'fd03'; //$txt = substr($txt, 0, (strlen($txt) - 1)); return iconv('UTF-32BE', 'utf8', hex2bin($txt)); // $dc = $txt; // break; // return dce2txt($data); break; case 'utf32': $unicode = bin2hex(iconv('UTF-8', 'UTF-32BE', dce_convert($dc, 'dc', 'utf8'))); //echo dce_convert($dc, 'dc', 'utf8'); //echo $unicode; return hex2bin($unicode); break; case 'html_l': break; case 'cdce': break; case 'legacy_cdce': break; break; default: return 'Unknown output format: ' . $output_format . '. Available: dc, dce, 3_0a, 3_01a, utf8, html_l, html_snippet_l'; } } if ($output_log) { global $log; echo $log; } }
function dce_convert($data, $input_format, $output_format) { //Ideally how this works: Convert the input into an array of Dc IDs, and then write that out using the selected translator. /* Input formats: dce, unicode, cdce, legacy_cdce Output formats: dce, dce_3.0a, unicode, html, cdce, legacy_cdce */ switch ($input_format) { case 'dce': $hex = strtolower(bin2hex($data)); if (substr($hex, 0, 12) !== '444345650201') { return 'This document is not stored using a supported format.'; break; } switch (get_dce_version($data)) { case '3_0a': //###################################################### //This is a DCE 3.0a file. It doesn't need to be updated. This case will though! /* global $dce3_0a_core; $counter = 14; $txt = ''; while ($counter < strlen($hex)) { $txt = $txt . $dce3_0a_core[hexdec(substr($hex, $counter, 2)) ]; if (substr($hex, $counter, 4) == 'fd03') { break; } $counter = $counter + 2; } r: return $txt;*/ $data = $data; break; default: return 'This document is not stored using a supported version of DCE.'; } break; case 'unicode': break; case 'cdce': break; case 'legacy_cdce': break; default: return 'Unknown input format. Available: dce, unicode'; } switch ($output_format) { case 'dce': dce_convert($data, 'dce', 'dce_3.0a'); break; case 'dce_3.0a': break; case 'unicode': return dce2txt($data); break; case 'html': break; case 'cdce': break; case 'legacy_cdce': break; default: return 'Unknown output format. Available: dce, dce_3.0a, unicode, html'; } }
function libdce_tests() { //Tests: test_add('<br><br><hr><br><h2>Begin test results</h2>'); //Input tests test_add('<h3>Begin input translator tests</h3>'); //CDCE test_add('<h4>Begin CDCE tests</h4>'); test_add('<h5>legacy_cdce</h5>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@13@@8@!', 'legacy_cdce', 'dc'), '114,57,86,93,93,96,18,1,35,72,96,99,93,85,1,35,37,1,8,19,115'); test_add('<h5>cdce_lstrict</h5>'); test('Plain UTF-8 string to Dc', dce_convert('Hello World!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Plain CDCE string to Dc', dce_convert('Hello @1@World@8@!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Improper CDCE string to Dc', dce_convert('Hello @1World@13@@8@!', 'cdce_lstrict', 'dc'), '114,57,86,93,93,96,18… CDCE decoding error!'); //DCE test_add('<h4>Begin DCE tests</h4>'); test_add('<h5>dce</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Hex DCE to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'dce', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>hex_dce</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_dce', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_dce', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); //3_0a test_add('<h4>Begin DCE 3.0a tests</h4>'); test_add('<h5>3_0a</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_0a', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>3_0a_raw</h5>'); test('DCE 3.0a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), '3_0a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>hex_3_0a</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_3_0a', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>hex_3_0a_raw</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), 'hex_3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_0a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a Raw to Dc', dce_convert('8048656C6C6F20576F726C642181', 'hex_3_0a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); //3_01a //Needs UTF-8 encapsulation testing test_add('<h4>Begin DCE 3.01a tests</h4>'); test_add('<h5>3_01a</h5>'); test('DCE 3.0a to Dc', dce_convert(hex2bin('44434565020101FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), 'This document is not stored using the specified version of DCE.'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03'), '3_01a', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<h5>3_01a_raw</h5>'); test('Simple DCE 3.01a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), '3_01a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex DCE 3.01a Raw to Dc', dce_convert(hex2bin('80C501FE48656C6C6F20576F726C642181'), '3_01a_raw', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), '3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test_add('<h5>hex_3_01a</h5>'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'hex_3_01a', 'dc'), 'This document is not stored using the specified format.'); test('Hex DCE 3.0a to Dc', dce_convert('44434565020101FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), 'This document is not stored using the specified version of DCE.'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex Hex DCE 3.01a to Dc', dce_convert('44434565020102FD80C501FE48656C6C6F20576F726C642181FD03', 'hex_3_01a', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); test_add('<h5>hex_3_01a_raw</h5>'); test('Simple DCE 3.01a to Dc', dce_convert(hex2bin('44434565020102FD8048656C6C6F20576F726C642181FD03'), 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple DCE 3.01a Raw to Dc', dce_convert(hex2bin('8048656C6C6F20576F726C642181'), 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple Hex DCE 3.01a to Dc', dce_convert('44434565020102FD8048656C6C6F20576F726C642181FD03', 'hex_3_01a_raw', 'dc'), 'This document is not stored using the specified format.'); test('Simple Hex DCE 3.01a Raw to Dc', dce_convert('8048656C6C6F20576F726C642181', 'hex_3_01a_raw', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Complex Hex DCE 3.01a Raw to Dc', dce_convert('80C501FE48656C6C6F20576F726C642181', 'hex_3_01a_raw', 'dc'), '114,122,57,86,93,93,96,18,72,96,99,93,85,19,115'); //Dc test_add('<h4>Begin Dc tests</h4>'); test_add('<h5>dc</h5>'); test('Dc to Dc', dce_convert('114,57,86,93,93,96,18,72,96,99,93,85,19,115', 'dc', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); //Unicode //These tests assume that Unicode encapsulation is not supported (it isn't, at the moment). test_add('<h4>Begin Unicode tests</h4>'); test_add('<h5>utf8</h5>'); test('UTF-8 to Dc, simple', dce_convert('Hello World!', 'utf8', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-8 to Dc, messy', dce_convert('Hello— –World!', 'utf8', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-8 to Dc, non-BMP', dce_convert('🌄 Hello World! 🌄', 'utf8', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<h5>utf32</h5>'); test('UTF-8 to Dc', dce_convert('Hello World!', 'utf32', 'dc'), 'This document is not stored using the specified format.'); test('UTF-32 to Dc, simple', dce_convert(iconv('UTF-8', 'UTF-32BE', 'Hello World!'), 'utf32', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-32 to Dc, messy', dce_convert(iconv('UTF-8', 'UTF-32BE', 'Hello— –World!'), 'utf32', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('UTF-32 to Dc, non-BMP', dce_convert(iconv('UTF-8', 'UTF-32BE', '🌄 Hello World! 🌄'), 'utf32', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<h5>utf8_base64</h5>'); test('Base64 UTF-8 to Dc, simple', dce_convert(base64_encode('Hello World!'), 'utf8_base64', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Base64 UTF-8 to Dc, messy', dce_convert(base64_encode('Hello— –World!'), 'utf8_base64', 'dc'), '114,57,86,93,93,96,18,72,96,99,93,85,19,115'); test('Base64 UTF-8 to Dc, non-BMP', dce_convert(base64_encode('🌄 Hello World! 🌄'), 'utf8_base64', 'dc'), '114,18,57,86,93,93,96,18,72,96,99,93,85,19,18,115'); test_add('<h5>utf8_dc64</h5>'); test('Raw Base64 Dc list encapsulated Unicode to Dc', dce_convert('156,133,148,178,156,127,195,195', 'utf8_dc64', 'dc'), '114,101,86,100,101,115'); //Output tests test_add('<br><br><h3>Begin output translator tests</h3>'); test_add('<h4>Begin Dc tests</h4>'); test_add('<h5>dc</h5>'); test('Dc to Dc, simple', dce_convert('114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115', 'dc', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test('Dc to Dc, missing boundedness markings', dce_convert('57,86,93,93,96,18,1,72,96,99,93,85,8,19', 'dc', 'dc'), '114,57,86,93,93,96,18,1,72,96,99,93,85,8,19,115'); test_add('<h5>utf8_dc64_enc</h5>'); //test('Raw Base64 Dc list encapsulated Unicode to Base64 Dc list encapsulated Unicode', dce_convert('156,133,148,178,156,127,195,195','utf8_dc64','utf8_dc64_enc'), '114,191,156,133,148,178,156,127,195,195,192,115'); global $testfail; if ($testfail) { test_add('<br><br><br><br><hr><br><br><br><br><h1><font color="red">SOME TESTS FAILED! LIBDCE DOES NOT APPEAR TO BE WORKING PROPERLY!</font></h1><br><br><br><br><hr><br><br><br><br>'); } test_add('<h3>End test results</h3><br><hr><br><br>'); }