1
0
Fork 0
forked from svrjs/svrjs

Remove unmaintained and undocumented hexstrbase64 library

This commit is contained in:
Dorian Niemiec 2023-09-08 19:12:42 +02:00
parent 2d733b70bf
commit 7f2da5b12a
28 changed files with 0 additions and 1412 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

View file

@ -1,124 +0,0 @@
//Base64.js for hexstrbase64 library for Node.js
/*
* Copyright (c) 2012 Miles Shang <mail@mshang.ca>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Usage:
* Set your settings:
* base64.settings.char62 = "-";
* base64.settings.char63 = "_";
* etc.
*
* Then:
* base64.encode(str) takes a string and returns the base64 encoding of it.
* base64.decode(str) does the reverse.
*/
/* TODO:
* Add a "padding_mandatory" flag to check for bad padding in the decoder.
* Add test cases that throw errors.
*/
var base64 = new Object();
base64.settings = { // defaults
"char62" : "+",
"char63" : "/",
"pad" : "=",
"ascii" : false
};
/*
* Settings:
* If "pad" is not null or undefined, then it will be used for encoding.
*
* If "ascii" is set to true, then the encoder
* will assume that plaintext is in 8-bit chars (the standard).
* In this case, for every 3 chars in plaintext, you get 4 chars of base64.
* Any non-8-bit chars will cause an error.
* Otherwise, assume that all plaintext can be in the full range
* of Javascript chars, i.e. 16 bits. Get 8 chars of base64 for 3 chars
* of plaintext. Any possible JS string can be encoded.
*/
base64.encode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
for (var i = 0; i < str.length; ++i) {
var c_num = str.charCodeAt(i);
if (this.settings.ascii)
if (c_num >= 256)
throw "Not an 8-bit char.";
var c_bin = c_num.toString(2);
while (c_bin.length < (this.settings.ascii ? 8 : 16))
c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= 6) {
var sextet = buf.slice(0, 6);
buf = buf.slice(6);
output += this.char_set.charAt(parseInt(sextet, 2));
}
}
if (buf) { // not empty
while (buf.length < 6) buf += "0";
output += this.char_set.charAt(parseInt(buf, 2));
}
if (this.settings.pad)
while (output.length % (this.settings.ascii ? 4 : 8) != 0)
output += this.settings.pad;
return output;
}
base64.decode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
var bits = (this.settings.ascii ? 8 : 16);
for (var i = 0; i < str.length; ++i) {
if (str[i] == this.settings.pad) break;
var c_num = this.char_set.indexOf(str.charAt(i));
if (c_num == -1) throw "Not base64.";
var c_bin = c_num.toString(2);
while (c_bin.length < 6) c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= bits) {
var octet = buf.slice(0, bits);
buf = buf.slice(bits);
output += String.fromCharCode(parseInt(octet, 2));
}
}
return output;
}
module.exports = base64;

View file

@ -1,123 +0,0 @@
//Base64.js for hexstrbase64 library for browser
/*
* Copyright (c) 2012 Miles Shang <mail@mshang.ca>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Usage:
* Set your settings:
* base64.settings.char62 = "-";
* base64.settings.char63 = "_";
* etc.
*
* Then:
* base64.encode(str) takes a string and returns the base64 encoding of it.
* base64.decode(str) does the reverse.
*/
/* TODO:
* Add a "padding_mandatory" flag to check for bad padding in the decoder.
* Add test cases that throw errors.
*/
var base64 = new Object();
base64.settings = { // defaults
"char62" : "+",
"char63" : "/",
"pad" : "=",
"ascii" : false
};
/*
* Settings:
* If "pad" is not null or undefined, then it will be used for encoding.
*
* If "ascii" is set to true, then the encoder
* will assume that plaintext is in 8-bit chars (the standard).
* In this case, for every 3 chars in plaintext, you get 4 chars of base64.
* Any non-8-bit chars will cause an error.
* Otherwise, assume that all plaintext can be in the full range
* of Javascript chars, i.e. 16 bits. Get 8 chars of base64 for 3 chars
* of plaintext. Any possible JS string can be encoded.
*/
base64.encode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
for (var i = 0; i < str.length; ++i) {
var c_num = str.charCodeAt(i);
if (this.settings.ascii)
if (c_num >= 256)
throw "Not an 8-bit char.";
var c_bin = c_num.toString(2);
while (c_bin.length < (this.settings.ascii ? 8 : 16))
c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= 6) {
var sextet = buf.slice(0, 6);
buf = buf.slice(6);
output += this.char_set.charAt(parseInt(sextet, 2));
}
}
if (buf) { // not empty
while (buf.length < 6) buf += "0";
output += this.char_set.charAt(parseInt(buf, 2));
}
if (this.settings.pad)
while (output.length % (this.settings.ascii ? 4 : 8) != 0)
output += this.settings.pad;
return output;
}
base64.decode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
var bits = (this.settings.ascii ? 8 : 16);
for (var i = 0; i < str.length; ++i) {
if (str[i] == this.settings.pad) break;
var c_num = this.char_set.indexOf(str.charAt(i));
if (c_num == -1) throw "Not base64.";
var c_bin = c_num.toString(2);
while (c_bin.length < 6) c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= bits) {
var octet = buf.slice(0, bits);
buf = buf.slice(bits);
output += String.fromCharCode(parseInt(octet, 2));
}
}
return output;
}

View file

@ -1,129 +0,0 @@
//Requires base64
var base64 = require('./base64.js');
var HexStrBase64Buffer = {
from: function(s, e) {
var type = e;
var value = '';
if (e == 'base64') {
value = base64.decode(s);
} else if (e == 'hex') {
try {
var escaped = "";
var hex = "";
if(s.length%4 > 0) {
for(i=0;i<(4-(s.length%4));i++) {
hex += "0";
}
}
hex += s;
for(var i = 0;i<hex.length;i += 4) {
escaped += new String("%u" + hex.charAt(i) + hex.charAt(i + 1) + hex.charAt(i + 2) + hex.charAt(i + 3)).toString().split("undefined").join("");
}
value = unescape(escaped).split(unescape("%00")).join("");
} catch (ex) {
var modex = ex.toString().split('Error: ');
modex[0] = '';
if (typeof modex == 'object') {
throw new Error(
'Invaild hex input: ' + s + '. Reason: ' + modex.join('')
);
} else {
throw new Error('Invaild hex input: ' + s + '. Reason: ' + ex);
}
}
} else {
value = Buffer.from(s, 'utf8').toString(e);
}
function toString(en) {
//function toStringE(en,type) {
if (en == 'base64') {
return base64.encode(value);
} else if (en == 'hex') {
var result = "";
for(var i=0;i<value.length;i++) {
var unicode = escape(value.charAt(i));
var hex = "";
if(value.charAt(i) == "\n") {
hex = "000a";
} else if(value.charAt(i) == "\r") {
hex = "000d";
} else if(value.charAt(i) == " ") {
hex = "0020";
} else if(value.charAt(i) == "\0") {
hex = "";
} else if(unicode == value.charAt(i)) {
var oldhex = value.charCodeAt(i).toString(16);
var newhex = "";
if(oldhex.length < 4) {
for(var j=0;j<4-(oldhex.length%4);j++) {
newhex += "0";
}
newhex += oldhex;
} else {
newhex = oldhex;
}
hex = newhex;
} else {
hex = unicode.split("%u").join("");
}
if(hex.length == 4 || hex === "") {
result += hex;
} else if(hex.length > 4) {
result += hex.substring(hex.length-5,hex.length-1);
} else if(hex.length < 4) {
for(var j=0;j<=4-(hex.length%4);j++) {
result += "0";
}
result += hex;
}
}
return result.split("undefined").join("").split("%").join("");
} else {
//return Buffer.from(value, type).toString(en);
return Buffer.from(value,"utf8").toString(en);
}
}
//}
//function toString(en) {
//return toStringE(en,type);
//}
return { type: type, value: value, toString: toString };
}
};
var hexstrbase64 = {
strtobase64: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('base64');
},
base64tostr: function(b) {
return HexStrBase64Buffer.from(b, 'base64').toString('utf8');
},
strtohex: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('hex');
},
hextostr: function(h) {
return HexStrBase64Buffer.from(h, 'hex').toString('utf8');
},
hextobase64: function(h) {
return hexstrbase64.strtobase64(hexstrbase64.hextostr(h));
},
base64tohex: function(b) {
return hexstrbase64.strtohex(hexstrbase64.base64tostr(b));
},
cipher: function() {
this.strtobase64 = hexstrbase64.strtobase64;
this.base64tostr = hexstrbase64.base64tostr;
this.strtohex = hexstrbase64.strtohex;
this.hextostr = hexstrbase64.hextostr;
this.hextobase64 = hextobase64.hextobase64;
this.base64tohex = hextobase64.base64tohex;
},
native: {
btoa: function(b) {
return hexstrbase64.strtobase64(b);
},
atob: function(a) {
return hexstrbase64.base64tostr(a);
}
}
};
module.exports = hexstrbase64;

View file

@ -1,126 +0,0 @@
//Requires base64_browser.js
var HexStrBase64Buffer = {
from: function(s, e) {
var type = e;
var value = '';
if (e == 'base64') {
value = base64.decode(s);
} else if (e == 'hex') {
try {
var escaped = "";
var hex = "";
if(s.length%4 > 0) {
for(i=0;i<(4-(s.length%4));i++) {
hex += "0";
}
}
hex += s;
for(var i = 0;i<hex.length;i += 4) {
escaped += new String("%u" + hex.charAt(i) + hex.charAt(i + 1) + hex.charAt(i + 2) + hex.charAt(i + 3)).toString().split("undefined").join("");
}
value = unescape(escaped).split(unescape("%00")).join("");
} catch (ex) {
var modex = ex.toString().split('Error: ');
modex[0] = '';
if (typeof modex == 'object') {
throw new Error(
'Invaild hex input: ' + s + '. Reason: ' + modex.join('')
);
} else {
throw new Error('Invaild hex input: ' + s + '. Reason: ' + ex);
}
}
} else {
value = new TextDecoder(e).decode(new TextEncoder('utf8').encode(s));
}
//function toStringE(en,type) {
function toString(en) {
if (en == 'base64') {
return base64.encode(value);
} else if (en == 'hex') {
var result = "";
for(var i=0;i<value.length;i++) {
var unicode = escape(value.charAt(i));
var hex = "";
if(value.charAt(i) == "\n") {
hex = "000a";
} else if(value.charAt(i) == "\r") {
hex = "000d";
} else if(value.charAt(i) == " ") {
hex = "0020";
} else if(value.charAt(i) == "\0") {
hex = "";
} else if(unicode == value.charAt(i)) {
var oldhex = value.charCodeAt(i).toString(16);
var newhex = "";
if(oldhex.length < 4) {
for(var j=0;j<4-(oldhex.length%4);j++) {
newhex += "0";
}
newhex += oldhex;
} else {
newhex = oldhex;
}
hex = newhex;
} else {
hex = unicode.split("%u").join("");
}
if(hex.length == 4 || hex === "") {
result += hex;
} else if(hex.length > 4) {
result += hex.substring(hex.length-5,hex.length-1);
} else if(hex.length < 4) {
for(var j=0;j<=4-(hex.length%4);j++) {
result += "0";
}
result += hex;
}
}
return result.split("undefined").join("").split("%").join("");
} else {
//return new TextDecoder(en).decode(new TextEncoder(type).encode(value));
return new TextDecoder(en).decode(new TextEncoder("utf8").encode(value));
}
}
//function toString(en) {
//return toStringE(en,type);
//}
return { type: type, value: value, toString: toString };
}
};
var hexstrbase64 = {
strtobase64: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('base64');
},
base64tostr: function(b) {
return HexStrBase64Buffer.from(b, 'base64').toString('utf8');
},
strtohex: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('hex');
},
hextostr: function(h) {
return HexStrBase64Buffer.from(h, 'hex').toString('utf8');
},
hextobase64: function(h) {
return hexstrbase64.strtobase64(hexstrbase64.hextostr(h));
},
base64tohex: function(b) {
return hexstrbase64.strtohex(hexstrbase64.base64tostr(b));
},
cipher: function() {
this.strtobase64 = hexstrbase64.strtobase64;
this.base64tostr = hexstrbase64.base64tostr;
this.strtohex = hexstrbase64.strtohex;
this.hextostr = hexstrbase64.hextostr;
this.hextobase64 = hextobase64.hextobase64;
this.base64tohex = hextobase64.base64tohex;
},
native: {
btoa: function(b) {
return hexstrbase64.strtobase64(b);
},
atob: function(a) {
return hexstrbase64.base64tostr(a);
}
}
};

View file

@ -1,11 +0,0 @@
let hexstrbase64 = require("./hexstrbase64/main.js");
function decodeBase(b) {
return hexstrbase64.native.atob(b);
}
function encodeStr(s) {
return hexstrbase64.native.btoa(s);
}
var m = Object.create(hexstrbase64);
m.decodeBase = decodeBase;
m.encodeBase = encodeStr;
module.exports = m;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

View file

@ -1,8 +0,0 @@
.code {
border-width: 5px;
border-color: #BEBEBE;
border-style: solid;
color:black;
background-color: #7F7F7F;
font-family: Hack,Consolas,Monaco,monospace;
}

View file

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>HexStrBase64 Readme</title>
<link rel="stylesheet" href="readme.css">
</head>
<body>
<h1>hexstrbase64</h1>
<h2>How to install?</h2>
<h3>Node.js</h3>
<ol>
<li>Download library from <a href="https://repl.it/@DorianNiemiec/Hex-String-Base64-NodeJS-Library.zip" download>here</a>.</li>
<li>Modify index.js</li>
<li>Write header in program (replace <b>./hexstrbase64</b> with your path to hexstrbase64 library):</li>
<div class="code">
var hexstrbase64 = require("<b>./hexstrbase64</b>/index.js");<br/>
</div>
<li>Now hexstrbase64 library added to program!</li>
</ol>
<h3>Browser Javascript</h3>
<ol>
<li>Download library from <a href="https://repl.it/@DorianNiemiec/Hex-String-Base64-NodeJS-Library.zip" download>here</a>.</li>
<li>Write this code in &lt;head&gt; element (replace <b>hexstrbase64/</b> with your path to hexstrbase64 library):</li>
<div class="code">
&lt;script src="<b>hexstrbase64/</b>hexstrbase64/base64_browser.js"&gt;&lt;/script&gt;<br/>
&lt;script src="<b>hexstrbase64/</b>hexstrbase64/main_browser.js"&gt;&lt;/script&gt;
</div>
<li>Now hexstrbase64 library added to HTML!</li>
</ol>
</body>
</html>

View file

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>hexstrbase64 base64 test</title>
<script src="../hexstrbase64/base64_browser.js"></script>
<script src="../hexstrbase64/main_browser.js"></script>
<script src="base64.js"></script>
<script>
testStart();
</script>
</head>
</html>

View file

@ -1,56 +0,0 @@
function nameObj(n, v) {
return {name:n, value:v};
}
function testStart() {
document.write('<meta charset="UTF-8">');
document.write('<title>hexstrbase64 base64 test</title>');
console.log("TESTING STARTED");
for (var i = 0; i < 3; i++) {
document.write('<h1>' + enccases[i].name + '</h1>');
console.log("SWITCH " + enccases[i].name);
for (var j = 0; j < 2; j++) {
document.write('<h2>' + enccases[i].value[j].name + '</h2>');
console.log("CASE " + enccases[i].value[j].name);
console.log("MUST BE: " + enccases[i].value[j].value);
console.log("IS : " + hexstrbase64.strtobase64(enccases[i].value[j].name));
if (hexstrbase64.strtobase64(enccases[i].value[j].name) == enccases[i].value[j].value) {
document.write('<p><img src="../ok.png"></img>Equals</p>');
console.log("EQUALS");
} else {
document.write('<p><img src="../fail.png"></img>Not Equals</p>');
console.log("NOT EQUALS");
}
console.log("CASE " + enccases[i].value[j].name + " ENDED");
}
console.log("SWITCH " + enccases[i].name + " ENDED");
}
console.log("TESTING ENDED");
}
var enccases = [
nameObj('Ascii', [
nameObj('Hello world!', 'AEgAZQBsAGwAbwAgAHcAbwByAGwAZAAh'),
nameObj('Lorem ipsum', 'AEwAbwByAGUAbQAgAGkAcABzAHUAbQ==')
]),
nameObj('Ascii More Than 64 Bytes', [
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum fermentum ac nisl a sollicitudin. Cras interdum dui turpis, non scelerisque.',
'AEwAbwByAGUAbQAgAGkAcABzAHUAbQAgAGQAbwBsAG8AcgAgAHMAaQB0ACAAYQBtAGUAdAAsACAAYwBvAG4AcwBlAGMAdABlAHQAdQByACAAYQBkAGkAcABpAHMAYwBpAG4AZwAgAGUAbABpAHQALgAgAFYAZQBzAHQAaQBiAHUAbAB1AG0AIABmAGUAcgBtAGUAbgB0AHUAbQAgAGEAYwAgAG4AaQBzAGwAIABhACAAcwBvAGwAbABpAGMAaQB0AHUAZABpAG4ALgAgAEMAcgBhAHMAIABpAG4AdABlAHIAZAB1AG0AIABkAHUAaQAgAHQAdQByAHAAaQBzACwAIABuAG8AbgAgAHMAYwBlAGwAZQByAGkAcwBxAHUAZQAu'
),
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus volutpat ligula at pulvinar. Etiam consequat mi fringilla facilisis eleifend.',
'AEwAbwByAGUAbQAgAGkAcABzAHUAbQAgAGQAbwBsAG8AcgAgAHMAaQB0ACAAYQBtAGUAdAAsACAAYwBvAG4AcwBlAGMAdABlAHQAdQByACAAYQBkAGkAcABpAHMAYwBpAG4AZwAgAGUAbABpAHQALgAgAFAAaABhAHMAZQBsAGwAdQBzACAAZABhAHAAaQBiAHUAcwAgAHYAbwBsAHUAdABwAGEAdAAgAGwAaQBnAHUAbABhACAAYQB0ACAAcAB1AGwAdgBpAG4AYQByAC4AIABFAHQAaQBhAG0AIABjAG8AbgBzAGUAcQB1AGEAdAAgAG0AaQAgAGYAcgBpAG4AZwBpAGwAbABhACAAZgBhAGMAaQBsAGkAcwBpAHMAIABlAGwAZQBpAGYAZQBuAGQALg=='
)
]),
nameObj('Unicode UTF8', [
nameObj(
'DorianTech Hex String Base64转换器',
'AEQAbwByAGkAYQBuAFQAZQBjAGgAIABIAGUAeAAgAFMAdAByAGkAbgBnACAAQgBhAHMAZQA2ADSPbGNiVmg====='
),
nameObj(
'DorianTech Hex String Base64转换器用于由DorianTech提供的Node.js',
'AEQAbwByAGkAYQBuAFQAZQBjAGgAIABIAGUAeAAgAFMAdAByAGkAbgBnACAAQgBhAHMAZQA2ADSPbGNiVmj/DHUoTo51MQBEAG8AcgBpAGEAbgBUAGUAYwBoY9BPm3aEAE4AbwBkAGUALgBqAHM====='
)
])
];

View file

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>hexstrbase64 hex test</title>
<script src="../hexstrbase64/base64_browser.js"></script>
<script src="../hexstrbase64/main_browser.js"></script>
<script src="hex.js"></script>
<script>
testStart();
</script>
</head>
</html>

View file

@ -1,56 +0,0 @@
function nameObj(n, v) {
return {name:n, value:v};
}
function testStart() {
document.write('<meta charset="UTF-8">');
document.write('<title>hexstrbase64 hex test</title>');
console.log("TESTING STARTED");
for (var i = 0; i < 3; i++) {
document.write('<h1>' + enccases[i].name + '</h1>');
console.log("SWITCH " + enccases[i].name);
for (var j = 0; j < 2; j++) {
document.write('<h2>' + enccases[i].value[j].name + '</h2>');
console.log("CASE " + enccases[i].value[j].name);
console.log("MUST BE: " + enccases[i].value[j].value);
console.log("IS : " + hexstrbase64.strtohex(enccases[i].value[j].name));
if (hexstrbase64.strtohex(enccases[i].value[j].name) == enccases[i].value[j].value) {
document.write('<p><img src="../ok.png"></img>Equals</p>');
console.log("EQUALS");
} else {
document.write('<p><img src="../fail.png"></img>Not Equals</p>');
console.log("NOT EQUALS");
}
console.log("CASE " + enccases[i].value[j].name + " ENDED");
}
console.log("SWITCH " + enccases[i].name + " ENDED");
}
console.log("TESTING ENDED");
}
var enccases = [
nameObj('Ascii', [
nameObj('Hello world!', '00480065006c006c006f00200077006f0072006c00640021'),
nameObj('Lorem ipsum', '004c006f00720065006d00200069007000730075006d')
]),
nameObj('Ascii More Than 64 Bytes', [
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum fermentum ac nisl a sollicitudin. Cras interdum dui turpis, non scelerisque.',
'004c006f00720065006d00200069007000730075006d00200064006f006c006f0072002000730069007400200061006d00650074002C00200063006f006e00730065006300740065007400750072002000610064006900700069007300630069006e006700200065006c00690074002e00200056006500730074006900620075006c0075006d0020006600650072006d0065006e00740075006d0020006100630020006e00690073006c0020006100200073006f006c006c0069006300690074007500640069006e002e0020004300720061007300200069006e00740065007200640075006d00200064007500690020007400750072007000690073002C0020006e006f006e0020007300630065006c0065007200690073007100750065002e'
),
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus volutpat ligula at pulvinar. Etiam consequat mi fringilla facilisis eleifend.',
'004c006f00720065006d00200069007000730075006d00200064006f006c006f0072002000730069007400200061006d00650074002C00200063006f006e00730065006300740065007400750072002000610064006900700069007300630069006e006700200065006c00690074002e002000500068006100730065006c006c007500730020006400610070006900620075007300200076006f006c007500740070006100740020006c006900670075006c0061002000610074002000700075006c00760069006e00610072002e00200045007400690061006d00200063006f006e0073006500710075006100740020006d00690020006600720069006e00670069006c006c006100200066006100630069006c006900730069007300200065006c0065006900660065006e0064002e'
)
]),
nameObj('Unicode UTF8', [
nameObj(
'DorianTech Hex String Base64转换器',
'0044006f007200690061006e0054006500630068002000480065007800200053007400720069006e006700200042006100730065003600348F6C63625668'
),
nameObj(
'DorianTech Hex String Base64转换器用于由DorianTech提供的Node.js',
'0044006f007200690061006e0054006500630068002000480065007800200053007400720069006e006700200042006100730065003600348F6C63625668FF0C75284E8E75310044006f007200690061006e005400650063006863D04F9B7684004e006f00640065002e006a0073'
)
])
];

View file

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>hexstrbase64 test</title>
<style>
iframe {
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<iframe src="base64.html"></iframe>
<iframe src="hex.html"></iframe>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

View file

@ -1,124 +0,0 @@
//Base64.js for hexstrbase64 library for Node.js
/*
* Copyright (c) 2012 Miles Shang <mail@mshang.ca>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Usage:
* Set your settings:
* base64.settings.char62 = "-";
* base64.settings.char63 = "_";
* etc.
*
* Then:
* base64.encode(str) takes a string and returns the base64 encoding of it.
* base64.decode(str) does the reverse.
*/
/* TODO:
* Add a "padding_mandatory" flag to check for bad padding in the decoder.
* Add test cases that throw errors.
*/
var base64 = new Object();
base64.settings = { // defaults
"char62" : "+",
"char63" : "/",
"pad" : "=",
"ascii" : false
};
/*
* Settings:
* If "pad" is not null or undefined, then it will be used for encoding.
*
* If "ascii" is set to true, then the encoder
* will assume that plaintext is in 8-bit chars (the standard).
* In this case, for every 3 chars in plaintext, you get 4 chars of base64.
* Any non-8-bit chars will cause an error.
* Otherwise, assume that all plaintext can be in the full range
* of Javascript chars, i.e. 16 bits. Get 8 chars of base64 for 3 chars
* of plaintext. Any possible JS string can be encoded.
*/
base64.encode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
for (var i = 0; i < str.length; ++i) {
var c_num = str.charCodeAt(i);
if (this.settings.ascii)
if (c_num >= 256)
throw "Not an 8-bit char.";
var c_bin = c_num.toString(2);
while (c_bin.length < (this.settings.ascii ? 8 : 16))
c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= 6) {
var sextet = buf.slice(0, 6);
buf = buf.slice(6);
output += this.char_set.charAt(parseInt(sextet, 2));
}
}
if (buf) { // not empty
while (buf.length < 6) buf += "0";
output += this.char_set.charAt(parseInt(buf, 2));
}
if (this.settings.pad)
while (output.length % (this.settings.ascii ? 4 : 8) != 0)
output += this.settings.pad;
return output;
}
base64.decode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
var bits = (this.settings.ascii ? 8 : 16);
for (var i = 0; i < str.length; ++i) {
if (str[i] == this.settings.pad) break;
var c_num = this.char_set.indexOf(str.charAt(i));
if (c_num == -1) throw "Not base64.";
var c_bin = c_num.toString(2);
while (c_bin.length < 6) c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= bits) {
var octet = buf.slice(0, bits);
buf = buf.slice(bits);
output += String.fromCharCode(parseInt(octet, 2));
}
}
return output;
}
module.exports = base64;

View file

@ -1,123 +0,0 @@
//Base64.js for hexstrbase64 library for browser
/*
* Copyright (c) 2012 Miles Shang <mail@mshang.ca>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Usage:
* Set your settings:
* base64.settings.char62 = "-";
* base64.settings.char63 = "_";
* etc.
*
* Then:
* base64.encode(str) takes a string and returns the base64 encoding of it.
* base64.decode(str) does the reverse.
*/
/* TODO:
* Add a "padding_mandatory" flag to check for bad padding in the decoder.
* Add test cases that throw errors.
*/
var base64 = new Object();
base64.settings = { // defaults
"char62" : "+",
"char63" : "/",
"pad" : "=",
"ascii" : false
};
/*
* Settings:
* If "pad" is not null or undefined, then it will be used for encoding.
*
* If "ascii" is set to true, then the encoder
* will assume that plaintext is in 8-bit chars (the standard).
* In this case, for every 3 chars in plaintext, you get 4 chars of base64.
* Any non-8-bit chars will cause an error.
* Otherwise, assume that all plaintext can be in the full range
* of Javascript chars, i.e. 16 bits. Get 8 chars of base64 for 3 chars
* of plaintext. Any possible JS string can be encoded.
*/
base64.encode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
for (var i = 0; i < str.length; ++i) {
var c_num = str.charCodeAt(i);
if (this.settings.ascii)
if (c_num >= 256)
throw "Not an 8-bit char.";
var c_bin = c_num.toString(2);
while (c_bin.length < (this.settings.ascii ? 8 : 16))
c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= 6) {
var sextet = buf.slice(0, 6);
buf = buf.slice(6);
output += this.char_set.charAt(parseInt(sextet, 2));
}
}
if (buf) { // not empty
while (buf.length < 6) buf += "0";
output += this.char_set.charAt(parseInt(buf, 2));
}
if (this.settings.pad)
while (output.length % (this.settings.ascii ? 4 : 8) != 0)
output += this.settings.pad;
return output;
}
base64.decode = function (str) {
this.char_set =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+ this.settings.char62 + this.settings.char63;
var output = ""; // final output
var buf = ""; // binary buffer
var bits = (this.settings.ascii ? 8 : 16);
for (var i = 0; i < str.length; ++i) {
if (str[i] == this.settings.pad) break;
var c_num = this.char_set.indexOf(str.charAt(i));
if (c_num == -1) throw "Not base64.";
var c_bin = c_num.toString(2);
while (c_bin.length < 6) c_bin = "0" + c_bin;
buf += c_bin;
while (buf.length >= bits) {
var octet = buf.slice(0, bits);
buf = buf.slice(bits);
output += String.fromCharCode(parseInt(octet, 2));
}
}
return output;
}

View file

@ -1,129 +0,0 @@
//Requires base64
var base64 = require('./base64.js');
var HexStrBase64Buffer = {
from: function(s, e) {
var type = e;
var value = '';
if (e == 'base64') {
value = base64.decode(s);
} else if (e == 'hex') {
try {
var escaped = "";
var hex = "";
if(s.length%4 > 0) {
for(i=0;i<(4-(s.length%4));i++) {
hex += "0";
}
}
hex += s;
for(var i = 0;i<hex.length;i += 4) {
escaped += new String("%u" + hex.charAt(i) + hex.charAt(i + 1) + hex.charAt(i + 2) + hex.charAt(i + 3)).toString().split("undefined").join("");
}
value = unescape(escaped).split(unescape("%00")).join("");
} catch (ex) {
var modex = ex.toString().split('Error: ');
modex[0] = '';
if (typeof modex == 'object') {
throw new Error(
'Invaild hex input: ' + s + '. Reason: ' + modex.join('')
);
} else {
throw new Error('Invaild hex input: ' + s + '. Reason: ' + ex);
}
}
} else {
value = Buffer.from(s, 'utf8').toString(e);
}
function toString(en) {
//function toStringE(en,type) {
if (en == 'base64') {
return base64.encode(value);
} else if (en == 'hex') {
var result = "";
for(var i=0;i<value.length;i++) {
var unicode = escape(value.charAt(i));
var hex = "";
if(value.charAt(i) == "\n") {
hex = "000a";
} else if(value.charAt(i) == "\r") {
hex = "000d";
} else if(value.charAt(i) == " ") {
hex = "0020";
} else if(value.charAt(i) == "\0") {
hex = "";
} else if(unicode == value.charAt(i)) {
var oldhex = value.charCodeAt(i).toString(16);
var newhex = "";
if(oldhex.length < 4) {
for(var j=0;j<4-(oldhex.length%4);j++) {
newhex += "0";
}
newhex += oldhex;
} else {
newhex = oldhex;
}
hex = newhex;
} else {
hex = unicode.split("%u").join("");
}
if(hex.length == 4 || hex === "") {
result += hex;
} else if(hex.length > 4) {
result += hex.substring(hex.length-5,hex.length-1);
} else if(hex.length < 4) {
for(var j=0;j<=4-(hex.length%4);j++) {
result += "0";
}
result += hex;
}
}
return result.split("undefined").join("").split("%").join("");
} else {
//return Buffer.from(value, type).toString(en);
return Buffer.from(value,"utf8").toString(en);
}
}
//}
//function toString(en) {
//return toStringE(en,type);
//}
return { type: type, value: value, toString: toString };
}
};
var hexstrbase64 = {
strtobase64: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('base64');
},
base64tostr: function(b) {
return HexStrBase64Buffer.from(b, 'base64').toString('utf8');
},
strtohex: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('hex');
},
hextostr: function(h) {
return HexStrBase64Buffer.from(h, 'hex').toString('utf8');
},
hextobase64: function(h) {
return hexstrbase64.strtobase64(hexstrbase64.hextostr(h));
},
base64tohex: function(b) {
return hexstrbase64.strtohex(hexstrbase64.base64tostr(b));
},
cipher: function() {
this.strtobase64 = hexstrbase64.strtobase64;
this.base64tostr = hexstrbase64.base64tostr;
this.strtohex = hexstrbase64.strtohex;
this.hextostr = hexstrbase64.hextostr;
this.hextobase64 = hextobase64.hextobase64;
this.base64tohex = hextobase64.base64tohex;
},
native: {
btoa: function(b) {
return hexstrbase64.strtobase64(b);
},
atob: function(a) {
return hexstrbase64.base64tostr(a);
}
}
};
module.exports = hexstrbase64;

View file

@ -1,126 +0,0 @@
//Requires base64_browser.js
var HexStrBase64Buffer = {
from: function(s, e) {
var type = e;
var value = '';
if (e == 'base64') {
value = base64.decode(s);
} else if (e == 'hex') {
try {
var escaped = "";
var hex = "";
if(s.length%4 > 0) {
for(i=0;i<(4-(s.length%4));i++) {
hex += "0";
}
}
hex += s;
for(var i = 0;i<hex.length;i += 4) {
escaped += new String("%u" + hex.charAt(i) + hex.charAt(i + 1) + hex.charAt(i + 2) + hex.charAt(i + 3)).toString().split("undefined").join("");
}
value = unescape(escaped).split(unescape("%00")).join("");
} catch (ex) {
var modex = ex.toString().split('Error: ');
modex[0] = '';
if (typeof modex == 'object') {
throw new Error(
'Invaild hex input: ' + s + '. Reason: ' + modex.join('')
);
} else {
throw new Error('Invaild hex input: ' + s + '. Reason: ' + ex);
}
}
} else {
value = new TextDecoder(e).decode(new TextEncoder('utf8').encode(s));
}
//function toStringE(en,type) {
function toString(en) {
if (en == 'base64') {
return base64.encode(value);
} else if (en == 'hex') {
var result = "";
for(var i=0;i<value.length;i++) {
var unicode = escape(value.charAt(i));
var hex = "";
if(value.charAt(i) == "\n") {
hex = "000a";
} else if(value.charAt(i) == "\r") {
hex = "000d";
} else if(value.charAt(i) == " ") {
hex = "0020";
} else if(value.charAt(i) == "\0") {
hex = "";
} else if(unicode == value.charAt(i)) {
var oldhex = value.charCodeAt(i).toString(16);
var newhex = "";
if(oldhex.length < 4) {
for(var j=0;j<4-(oldhex.length%4);j++) {
newhex += "0";
}
newhex += oldhex;
} else {
newhex = oldhex;
}
hex = newhex;
} else {
hex = unicode.split("%u").join("");
}
if(hex.length == 4 || hex === "") {
result += hex;
} else if(hex.length > 4) {
result += hex.substring(hex.length-5,hex.length-1);
} else if(hex.length < 4) {
for(var j=0;j<=4-(hex.length%4);j++) {
result += "0";
}
result += hex;
}
}
return result.split("undefined").join("").split("%").join("");
} else {
//return new TextDecoder(en).decode(new TextEncoder(type).encode(value));
return new TextDecoder(en).decode(new TextEncoder("utf8").encode(value));
}
}
//function toString(en) {
//return toStringE(en,type);
//}
return { type: type, value: value, toString: toString };
}
};
var hexstrbase64 = {
strtobase64: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('base64');
},
base64tostr: function(b) {
return HexStrBase64Buffer.from(b, 'base64').toString('utf8');
},
strtohex: function(s) {
return HexStrBase64Buffer.from(s, 'utf8').toString('hex');
},
hextostr: function(h) {
return HexStrBase64Buffer.from(h, 'hex').toString('utf8');
},
hextobase64: function(h) {
return hexstrbase64.strtobase64(hexstrbase64.hextostr(h));
},
base64tohex: function(b) {
return hexstrbase64.strtohex(hexstrbase64.base64tostr(b));
},
cipher: function() {
this.strtobase64 = hexstrbase64.strtobase64;
this.base64tostr = hexstrbase64.base64tostr;
this.strtohex = hexstrbase64.strtohex;
this.hextostr = hexstrbase64.hextostr;
this.hextobase64 = hextobase64.hextobase64;
this.base64tohex = hextobase64.base64tohex;
},
native: {
btoa: function(b) {
return hexstrbase64.strtobase64(b);
},
atob: function(a) {
return hexstrbase64.base64tostr(a);
}
}
};

View file

@ -1,11 +0,0 @@
let hexstrbase64 = require("./hexstrbase64/main.js");
function decodeBase(b) {
return hexstrbase64.native.atob(b);
}
function encodeStr(s) {
return hexstrbase64.native.btoa(s);
}
var m = Object.create(hexstrbase64);
m.decodeBase = decodeBase;
m.encodeBase = encodeStr;
module.exports = m;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

View file

@ -1,8 +0,0 @@
.code {
border-width: 5px;
border-color: #BEBEBE;
border-style: solid;
color:black;
background-color: #7F7F7F;
font-family: Hack,Consolas,Monaco,monospace;
}

View file

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>HexStrBase64 Readme</title>
<link rel="stylesheet" href="readme.css">
</head>
<body>
<h1>hexstrbase64</h1>
<h2>How to install?</h2>
<h3>Node.js</h3>
<ol>
<li>Download library from <a href="https://repl.it/@DorianNiemiec/Hex-String-Base64-NodeJS-Library.zip" download>here</a>.</li>
<li>Modify index.js</li>
<li>Write header in program (replace <b>./hexstrbase64</b> with your path to hexstrbase64 library):</li>
<div class="code">
var hexstrbase64 = require("<b>./hexstrbase64</b>/index.js");<br/>
</div>
<li>Now hexstrbase64 library added to program!</li>
</ol>
<h3>Browser Javascript</h3>
<ol>
<li>Download library from <a href="https://repl.it/@DorianNiemiec/Hex-String-Base64-NodeJS-Library.zip" download>here</a>.</li>
<li>Write this code in &lt;head&gt; element (replace <b>hexstrbase64/</b> with your path to hexstrbase64 library):</li>
<div class="code">
&lt;script src="<b>hexstrbase64/</b>hexstrbase64/base64_browser.js"&gt;&lt;/script&gt;<br/>
&lt;script src="<b>hexstrbase64/</b>hexstrbase64/main_browser.js"&gt;&lt;/script&gt;
</div>
<li>Now hexstrbase64 library added to HTML!</li>
</ol>
</body>
</html>

View file

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>hexstrbase64 base64 test</title>
<script src="../hexstrbase64/base64_browser.js"></script>
<script src="../hexstrbase64/main_browser.js"></script>
<script src="base64.js"></script>
<script>
testStart();
</script>
</head>
</html>

View file

@ -1,56 +0,0 @@
function nameObj(n, v) {
return {name:n, value:v};
}
function testStart() {
document.write('<meta charset="UTF-8">');
document.write('<title>hexstrbase64 base64 test</title>');
console.log("TESTING STARTED");
for (var i = 0; i < 3; i++) {
document.write('<h1>' + enccases[i].name + '</h1>');
console.log("SWITCH " + enccases[i].name);
for (var j = 0; j < 2; j++) {
document.write('<h2>' + enccases[i].value[j].name + '</h2>');
console.log("CASE " + enccases[i].value[j].name);
console.log("MUST BE: " + enccases[i].value[j].value);
console.log("IS : " + hexstrbase64.strtobase64(enccases[i].value[j].name));
if (hexstrbase64.strtobase64(enccases[i].value[j].name) == enccases[i].value[j].value) {
document.write('<p><img src="../ok.png"></img>Equals</p>');
console.log("EQUALS");
} else {
document.write('<p><img src="../fail.png"></img>Not Equals</p>');
console.log("NOT EQUALS");
}
console.log("CASE " + enccases[i].value[j].name + " ENDED");
}
console.log("SWITCH " + enccases[i].name + " ENDED");
}
console.log("TESTING ENDED");
}
var enccases = [
nameObj('Ascii', [
nameObj('Hello world!', 'AEgAZQBsAGwAbwAgAHcAbwByAGwAZAAh'),
nameObj('Lorem ipsum', 'AEwAbwByAGUAbQAgAGkAcABzAHUAbQ==')
]),
nameObj('Ascii More Than 64 Bytes', [
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum fermentum ac nisl a sollicitudin. Cras interdum dui turpis, non scelerisque.',
'AEwAbwByAGUAbQAgAGkAcABzAHUAbQAgAGQAbwBsAG8AcgAgAHMAaQB0ACAAYQBtAGUAdAAsACAAYwBvAG4AcwBlAGMAdABlAHQAdQByACAAYQBkAGkAcABpAHMAYwBpAG4AZwAgAGUAbABpAHQALgAgAFYAZQBzAHQAaQBiAHUAbAB1AG0AIABmAGUAcgBtAGUAbgB0AHUAbQAgAGEAYwAgAG4AaQBzAGwAIABhACAAcwBvAGwAbABpAGMAaQB0AHUAZABpAG4ALgAgAEMAcgBhAHMAIABpAG4AdABlAHIAZAB1AG0AIABkAHUAaQAgAHQAdQByAHAAaQBzACwAIABuAG8AbgAgAHMAYwBlAGwAZQByAGkAcwBxAHUAZQAu'
),
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus volutpat ligula at pulvinar. Etiam consequat mi fringilla facilisis eleifend.',
'AEwAbwByAGUAbQAgAGkAcABzAHUAbQAgAGQAbwBsAG8AcgAgAHMAaQB0ACAAYQBtAGUAdAAsACAAYwBvAG4AcwBlAGMAdABlAHQAdQByACAAYQBkAGkAcABpAHMAYwBpAG4AZwAgAGUAbABpAHQALgAgAFAAaABhAHMAZQBsAGwAdQBzACAAZABhAHAAaQBiAHUAcwAgAHYAbwBsAHUAdABwAGEAdAAgAGwAaQBnAHUAbABhACAAYQB0ACAAcAB1AGwAdgBpAG4AYQByAC4AIABFAHQAaQBhAG0AIABjAG8AbgBzAGUAcQB1AGEAdAAgAG0AaQAgAGYAcgBpAG4AZwBpAGwAbABhACAAZgBhAGMAaQBsAGkAcwBpAHMAIABlAGwAZQBpAGYAZQBuAGQALg=='
)
]),
nameObj('Unicode UTF8', [
nameObj(
'DorianTech Hex String Base64转换器',
'AEQAbwByAGkAYQBuAFQAZQBjAGgAIABIAGUAeAAgAFMAdAByAGkAbgBnACAAQgBhAHMAZQA2ADSPbGNiVmg====='
),
nameObj(
'DorianTech Hex String Base64转换器用于由DorianTech提供的Node.js',
'AEQAbwByAGkAYQBuAFQAZQBjAGgAIABIAGUAeAAgAFMAdAByAGkAbgBnACAAQgBhAHMAZQA2ADSPbGNiVmj/DHUoTo51MQBEAG8AcgBpAGEAbgBUAGUAYwBoY9BPm3aEAE4AbwBkAGUALgBqAHM====='
)
])
];

View file

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>hexstrbase64 hex test</title>
<script src="../hexstrbase64/base64_browser.js"></script>
<script src="../hexstrbase64/main_browser.js"></script>
<script src="hex.js"></script>
<script>
testStart();
</script>
</head>
</html>

View file

@ -1,56 +0,0 @@
function nameObj(n, v) {
return {name:n, value:v};
}
function testStart() {
document.write('<meta charset="UTF-8">');
document.write('<title>hexstrbase64 hex test</title>');
console.log("TESTING STARTED");
for (var i = 0; i < 3; i++) {
document.write('<h1>' + enccases[i].name + '</h1>');
console.log("SWITCH " + enccases[i].name);
for (var j = 0; j < 2; j++) {
document.write('<h2>' + enccases[i].value[j].name + '</h2>');
console.log("CASE " + enccases[i].value[j].name);
console.log("MUST BE: " + enccases[i].value[j].value);
console.log("IS : " + hexstrbase64.strtohex(enccases[i].value[j].name));
if (hexstrbase64.strtohex(enccases[i].value[j].name) == enccases[i].value[j].value) {
document.write('<p><img src="../ok.png"></img>Equals</p>');
console.log("EQUALS");
} else {
document.write('<p><img src="../fail.png"></img>Not Equals</p>');
console.log("NOT EQUALS");
}
console.log("CASE " + enccases[i].value[j].name + " ENDED");
}
console.log("SWITCH " + enccases[i].name + " ENDED");
}
console.log("TESTING ENDED");
}
var enccases = [
nameObj('Ascii', [
nameObj('Hello world!', '00480065006c006c006f00200077006f0072006c00640021'),
nameObj('Lorem ipsum', '004c006f00720065006d00200069007000730075006d')
]),
nameObj('Ascii More Than 64 Bytes', [
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum fermentum ac nisl a sollicitudin. Cras interdum dui turpis, non scelerisque.',
'004c006f00720065006d00200069007000730075006d00200064006f006c006f0072002000730069007400200061006d00650074002C00200063006f006e00730065006300740065007400750072002000610064006900700069007300630069006e006700200065006c00690074002e00200056006500730074006900620075006c0075006d0020006600650072006d0065006e00740075006d0020006100630020006e00690073006c0020006100200073006f006c006c0069006300690074007500640069006e002e0020004300720061007300200069006e00740065007200640075006d00200064007500690020007400750072007000690073002C0020006e006f006e0020007300630065006c0065007200690073007100750065002e'
),
nameObj(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus volutpat ligula at pulvinar. Etiam consequat mi fringilla facilisis eleifend.',
'004c006f00720065006d00200069007000730075006d00200064006f006c006f0072002000730069007400200061006d00650074002C00200063006f006e00730065006300740065007400750072002000610064006900700069007300630069006e006700200065006c00690074002e002000500068006100730065006c006c007500730020006400610070006900620075007300200076006f006c007500740070006100740020006c006900670075006c0061002000610074002000700075006c00760069006e00610072002e00200045007400690061006d00200063006f006e0073006500710075006100740020006d00690020006600720069006e00670069006c006c006100200066006100630069006c006900730069007300200065006c0065006900660065006e0064002e'
)
]),
nameObj('Unicode UTF8', [
nameObj(
'DorianTech Hex String Base64转换器',
'0044006f007200690061006e0054006500630068002000480065007800200053007400720069006e006700200042006100730065003600348F6C63625668'
),
nameObj(
'DorianTech Hex String Base64转换器用于由DorianTech提供的Node.js',
'0044006f007200690061006e0054006500630068002000480065007800200053007400720069006e006700200042006100730065003600348F6C63625668FF0C75284E8E75310044006f007200690061006e005400650063006863D04F9B7684004e006f00640065002e006a0073'
)
])
];

View file

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>hexstrbase64 test</title>
<style>
iframe {
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<iframe src="base64.html"></iframe>
<iframe src="hex.html"></iframe>
</body>
</html>