malformedUrl
This tag emulates a defective encoder found on a web site.
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Thursday, January 30, 2025 at 9:46:05 AM
Updated on: Friday, February 7, 2025 at 12:15:03 PM
Tag arguments
[]
Code
class malformedUrl {
encode(input) {
const nibbleCharMap = [
"0",
"!",
'"',
"^",
"$",
"5",
"&",
"'",
"(",
")",
"*",
"+",
",",
"-",
".",
"/",
];
return Array.from(input)
.map((ch) => {
const code = ch.codePointAt(0);
const adjusted = code - 16;
const high = adjusted >> 4;
const low = adjusted & 15;
return `%${nibbleCharMap[high]}${nibbleCharMap[low]}`;
})
.join("");
}
decode(input) {
return input.replace(/%(..)/gi, function ($0, c) {
return String.fromCodePoint(
parseInt(
(c.charAt(0).codePointAt(0) % 0x10).toString(16) +
(c.charAt(1).codePointAt(0) % 0x10).toString(16),
16,
),
);
});
}
}