-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from aWZHY0yQH81uOYvH/main
Added hex to ASCII conversion scripts
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |