import assert from 'assert';
import { encode, decode } from './lib/crypto.js';

const inputs = [];
process.stdin.on('data', (data) => {
    const userInput = data.toString().trim();

    if (userInput.length === 0) {
        inputs.forEach(input => {
            const [encoded, mask] = encode(input);

            assert(decode(encoded, mask, input.length) === input, 'Decoded value does not match original input');

            console.log(`Input: ${input}`);
            console.log(`Encoded: ${encoded}`);
            console.log(`Mask: ${mask}`);
            console.log(`Length: ${input.length}`);
        });

        process.exit(0);
    }

    inputs.push(userInput);
    console.log(inputs);
});
