: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* XOR, or exclusive or, is a logical bitwise operation that stands for "exclusive or."
* In the context of binary numbers, XOR compares corresponding bits of two operands and
* produces a new result. The XOR operation returns true (or 1) for bits where the operands differ.
* Note: This class is a simple obfuscation technique and should not be used for securing sensitive data.
* Here's the truth table for XOR:
* In binary, XOR is often denoted by the symbol ^.
* Here's an example of XOR operation on binary numbers:
* ------------------------
* // Instantiate the plugin with a custom encryption key.
* const xorInstance = new WPFormsXOR({
* key: 55, // Use any number as the encryption key.
* // Example object to encrypt.
* const dataToEncrypt = {
* const encryptedValue = xorInstance.encrypt(dataToEncrypt);
* console.log('Encrypted:', encryptedValue);
* const decryptedObject = xorInstance.decrypt(encryptedValue);
* console.log('Decrypted:', decryptedObject);
( function( root, factory ) {
const pluginName = 'WPFormsXOR';
if ( typeof define === 'function' && define.amd ) {
define( [], factory( pluginName ) );
} else if ( typeof exports === 'object' ) {
module.exports = factory( pluginName );
root[ pluginName ] = factory( pluginName );
// eslint-disable-next-line max-lines-per-function
}( this, function( pluginName ) {
// eslint-disable-next-line strict
class PluginError extends Error {
* @param {string} message The error message.
// The encryption key is a crucial component in encryption algorithms,
// including the XOR encryption used in the provided code.
// The key is a value used to control the transformation
// of the data during encryption and decryption.
key: 42, // You can use any number.
* @param {Object} args The argument object.
// Merge the default settings with the provided settings.
this.args = Object.assign( {}, Plugin.defaults, args );
* Encrypt an object using XOR encryption.
* @param {Object} obj The object to encrypt.
* @return {string} The encrypted object as a string.
// Bail if the input is not an object.
if ( typeof obj !== 'object' ) {
throw new PluginError( 'Invalid input. Expected an object for encryption.' );
// Initialize an empty string to store the encrypted result.
// Convert the object to a JSON string.
const jsonString = JSON.stringify( obj );
// Iterate through each character of the JSON string.
for ( let i = 0; i < jsonString.length; i++ ) {
// XOR each character with the encryption key and append to the result.
// eslint-disable-next-line no-bitwise
result += String.fromCharCode( jsonString.charCodeAt( i ) ^ this.args.key );
// Throw a PluginError if there's an issue during JSON stringification.
throw new PluginError( 'Error during encryption. Unable to stringify the object.' );
* Decrypt a string using XOR encryption.
* @param {string} encryptedString The encrypted string.
* @return {Object} The decrypted object.
decrypt( encryptedString = '' ) {
// Bail if the input is not a string.
if ( typeof encryptedString !== 'string' ) {
throw new PluginError( 'Invalid input. Expected a string for decryption.' );
// Bail if there is no encrypted string.
if ( ! encryptedString ) {
return {}; // Return an empty object.
// Iterate through each character of the encrypted string.
for ( let i = 0; i < encryptedString.length; i++ ) {
// XOR each character with the decryption key and append to the result.
// eslint-disable-next-line no-bitwise
result += String.fromCharCode( encryptedString.charCodeAt( i ) ^ this.args.key );
// Parse the decrypted result as JSON or return an empty object if parsing fails.
return JSON.parse( result || '{}' );
// Throw an error if there's an issue during decryption or parsing.
throw new PluginError( 'Error during decryption. Unable to parse decrypted data.' );