encodera
v1.0.0
Published
A simple library for encoding and decoding data with a key
Maintainers
Readme
Simple Encoder
A lightweight library for encoding and decoding data with a key that works in both browser and Node.js environments.
Installation
npm install simple-encoderUsage
In Node.js
const { encode, decode } = require('simple-encoder');
// Encode data
const encoded = encode('Hello World', 'my-secret-key');
console.log('Encoded:', encoded);
// Decode data
const decoded = decode(encoded, 'my-secret-key');
console.log('Decoded:', decoded); // Hello WorldIn Browser
<script src="node_modules/simple-encoder/dist/index.js"></script>
<script>
// Encode data
const encoded = SimpleEncoder.encode('Hello World', 'my-secret-key');
console.log('Encoded:', encoded);
// Decode data
const decoded = SimpleEncoder.decode(encoded, 'my-secret-key');
console.log('Decoded:', decoded); // Hello World
</script>Or using ES modules:
import { encode, decode } from 'simple-encoder';
// Encode data
const encoded = encode('Hello World', 'my-secret-key');
console.log('Encoded:', encoded);
// Decode data
const decoded = decode(encoded, 'my-secret-key');
console.log('Decoded:', decoded); // Hello WorldAPI
encode(input, key)
Encodes the input string using the provided key.
Parameters:
input(string): The string to encodekey(string): The key to use for encoding
Returns:
- (string): The encoded string
decode(encoded, key)
Decodes the encoded string using the provided key.
Parameters:
encoded(string): The encoded string to decodekey(string): The key used for encoding
Returns:
- (string): The decoded string
How it works
Simple Encoder uses a XOR-based algorithm to encode and decode strings securely. The key is repeated to match the length of the input, and each character in the input is XORed with the corresponding character in the key.
License
MIT
