Skip to content

Commit

Permalink
Merge pull request #185 from aWZHY0yQH81uOYvH/main
Browse files Browse the repository at this point in the history
Added hex to ASCII conversion scripts
  • Loading branch information
IvanMathy authored Mar 16, 2021
2 parents 918c0cb + da7565e commit 87ec848
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Scripts/ASCIIToHex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
{
"api":1,
"name":"ASCII To Hex",
"description":"Converts ASCII characters to hex",
"author":"aWZHY0yQH81uOYvH",
"icon":"metamorphose",
"tags":"ascii,hex,convert"
}
**/

function main(state) {
buf = "";
for(i = 0; i < state.fullText.length; i ++) {
code = state.fullText.charCodeAt(i).toString(16);
if(code.length < 2) buf += "0";
buf += code;
}
state.fullText = buf.toUpperCase();
}
28 changes: 28 additions & 0 deletions Scripts/HexToASCII.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
{
"api":1,
"name":"Hex To ASCII",
"description":"Converts hex into ASCII characters",
"author":"aWZHY0yQH81uOYvH",
"icon":"metamorphose",
"tags":"hex,ascii,convert"
}
**/

function main(state) {
input = state.fullText.toUpperCase();
buf = "";
hexBuf = "";
for(i = 0; i < input.length; i ++) {
c = input.charAt(i);
if("0123456789ABCDEF".includes(c)) {
hexBuf += c;
if(hexBuf.length >= 2) {
buf += String.fromCharCode(parseInt(hexBuf, 16));
hexBuf = "";
}
} else if(c != ' ' && c != '\t' && c != '\n' && c != '\r')
throw "Not hex";
}
state.fullText = buf;
}

0 comments on commit 87ec848

Please sign in to comment.