mirror of
https://github.com/elder-plinius/P4RS3LT0NGV3.git
synced 2026-07-12 07:26:33 +02:00
ported Jason Haddix's additions, added transform settings
This commit is contained in:
@@ -4,6 +4,15 @@ import BaseTransformer from '../BaseTransformer.js';
|
||||
export default new BaseTransformer({
|
||||
name: 'Binary',
|
||||
priority: 300,
|
||||
inputKind: 'textarea',
|
||||
configurableOptions: [
|
||||
{
|
||||
id: 'byteSpacing',
|
||||
label: 'Space between bytes',
|
||||
type: 'boolean',
|
||||
default: true
|
||||
}
|
||||
],
|
||||
// Detector: Only 0s, 1s, and spaces
|
||||
detector: function(text) {
|
||||
const cleaned = text.trim();
|
||||
@@ -11,18 +20,21 @@ export default new BaseTransformer({
|
||||
return noSpaces.length >= 8 && /^[01\s]+$/.test(cleaned);
|
||||
},
|
||||
|
||||
func: function(text) {
|
||||
// Use TextEncoder to properly handle UTF-8 (including emoji)
|
||||
func: function(text, options) {
|
||||
options = options || {};
|
||||
const spacing = options.byteSpacing !== false;
|
||||
const encoder = new TextEncoder();
|
||||
const bytes = encoder.encode(text);
|
||||
return Array.from(bytes).map(b => b.toString(2).padStart(8, '0')).join(' ');
|
||||
const bits = Array.from(bytes).map(b => b.toString(2).padStart(8, '0'));
|
||||
return spacing ? bits.join(' ') : bits.join('');
|
||||
},
|
||||
preview: function(text) {
|
||||
preview: function(text, options) {
|
||||
if (!text) return '[binary]';
|
||||
const full = this.func(text);
|
||||
const full = this.func(text, options);
|
||||
return full.substring(0, 24) + (full.length > 24 ? '...' : '');
|
||||
},
|
||||
reverse: function(text) {
|
||||
reverse: function(text, options) {
|
||||
options = options || {};
|
||||
// Remove spaces and ensure we have valid binary
|
||||
const binText = text.replace(/\s+/g, '');
|
||||
const bytes = [];
|
||||
|
||||
@@ -4,24 +4,36 @@ import BaseTransformer from '../BaseTransformer.js';
|
||||
export default new BaseTransformer({
|
||||
name: 'Hexadecimal',
|
||||
priority: 290,
|
||||
inputKind: 'textarea',
|
||||
configurableOptions: [
|
||||
{
|
||||
id: 'pairSpacing',
|
||||
label: 'Space between byte pairs',
|
||||
type: 'boolean',
|
||||
default: true
|
||||
}
|
||||
],
|
||||
// Detector: Only hex characters (0-9, A-F)
|
||||
detector: function(text) {
|
||||
const cleaned = text.trim().replace(/\s/g, '');
|
||||
return cleaned.length >= 4 && /^[0-9A-Fa-f]+$/.test(cleaned);
|
||||
},
|
||||
|
||||
func: function(text) {
|
||||
// Use TextEncoder to properly handle UTF-8 (including emoji)
|
||||
func: function(text, options) {
|
||||
options = options || {};
|
||||
const spacing = options.pairSpacing !== false;
|
||||
const encoder = new TextEncoder();
|
||||
const bytes = encoder.encode(text);
|
||||
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(' ');
|
||||
const pairs = Array.from(bytes).map(b => b.toString(16).padStart(2, '0'));
|
||||
return spacing ? pairs.join(' ') : pairs.join('');
|
||||
},
|
||||
preview: function(text) {
|
||||
preview: function(text, options) {
|
||||
if (!text) return '[hex]';
|
||||
const full = this.func(text);
|
||||
const full = this.func(text, options);
|
||||
return full.substring(0, 20) + (full.length > 20 ? '...' : '');
|
||||
},
|
||||
reverse: function(text) {
|
||||
reverse: function(text, options) {
|
||||
options = options || {};
|
||||
const hexText = text.replace(/\s+/g, '');
|
||||
const bytes = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user