Here are several examples of non-linear transformation functions that you can use to obfuscate numbers while preserving their relative order. Each function applies a different non-linear mathematical transformation to the input values. These transformations will make it more difficult to reverse engineer the original numbers.
This function applies an exponential transformation with a base, making the values grow rapidly as the input increases.
function obfuscateExponential(arr) {
const base = 1.2; // Base of the exponential growth
const obfuscatedArr = arr.map(num => Math.pow(base, num));
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscateExponential(numbers)); // Output: Exponentially transformed numbers
The sigmoid function maps inputs into a bounded range (typically between 0 and 1), creating an S-shaped curve. This is useful for compressing values within a fixed range while still maintaining non-linearity.
function sigmoid(x) {
return 1 / (1 + Math.exp(-x));
}
function obfuscateSigmoid(arr) {
const scaleFactor = 10; // Scaling factor for the sigmoid input
const obfuscatedArr = arr.map(num => sigmoid(num / scaleFactor));
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscateSigmoid(numbers)); // Output: Sigmoid-transformed numbers in the range [0, 1]
This transformation applies a polynomial function to the input values. The degree of the polynomial can be adjusted to control the non-linearity.
function obfuscatePolynomial(arr) {
const a = 0.1, b = 2.5, c = 5; // Polynomial coefficients
const polynomialTransform = num => a * Math.pow(num, 2) + b * num + c;
const obfuscatedArr = arr.map(polynomialTransform);
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscatePolynomial(numbers)); // Output: Polynomial-transformed numbers
A logarithmic transformation combined with a randomized offset makes it more difficult to deduce the original numbers.
function obfuscateLogarithmic(arr) {
const logBase = 10; // Logarithmic base
const randomFactor = () => Math.random() * 0.5; // Add randomization to the transformation
const obfuscatedArr = arr.map(num => Math.log(num) / Math.log(logBase) + randomFactor());
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscateLogarithmic(numbers)); // Output: Logarithmically transformed numbers with added noise
This example uses a sine wave to apply a non-linear transformation. Be aware that trigonometric functions introduce periodicity, so you need to adjust the scale to avoid too much repetition.
function obfuscateSine(arr) {
const amplitude = 100; // Amplitude of the sine wave
const frequency = 0.01; // Frequency of the wave
const sineTransform = num => amplitude * Math.sin(frequency * num);
const obfuscatedArr = arr.map(sineTransform);
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscateSine(numbers)); // Output: Sine-wave transformed numbers
This function splits the input range into different intervals, applying different transformations to each range. It creates non-linear effects while adding complexity to the transformation.
function obfuscatePiecewiseNonLinear(arr) {
const piecewiseTransform = (num) => {
if (num < 100) {
return Math.pow(num, 1.5) + 20; // Non-linear for small values
} else if (num < 1000) {
return Math.log(num) * 100 + 50; // Logarithmic transformation for medium values
} else {
return Math.pow(num, 0.5) * 200; // Square root scaling for large values
}
};
const obfuscatedArr = arr.map(piecewiseTransform);
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscatePiecewiseNonLinear(numbers)); // Output: Piecewise non-linear transformed numbers
The hyperbolic tangent function maps values between -1 and 1 and creates a smooth S-shaped curve. You can scale and shift the results as needed.
function obfuscateTanh(arr) {
const scaleFactor = 0.01; // Scale the input to control the steepness
const shiftFactor = 1.5; // Shift to make sure outputs are non-negative
const obfuscatedArr = arr.map(num => Math.tanh(num * scaleFactor) + shiftFactor);
return obfuscatedArr;
}
let numbers = [10, 100, 1000];
console.log(obfuscateTanh(numbers)); // Output: Tanh-transformed numbers
- Exponential Transformation: Rapid growth, hard to reverse.
- Sigmoid Transformation: Compresses numbers into a specific range.
- Polynomial Transformation: Provides flexibility with various non-linear coefficients.
- Logarithmic Scaling with Randomization: Applies randomness to log-based scaling for added obfuscation.
- Trigonometric (Sine) Transformation: Adds periodic non-linearity.
- Piecewise Non-linear Transformation: Applies different functions to different ranges.
- Tanh Transformation: Smooth non-linear function with bounded output.
By combining these methods, you can add multiple layers of complexity to make it very difficult for someone to reverse-engineer the original numbers while preserving their order.