// for use in future crypto/ctf challenge; probably hilariously insecure, but that's kinda the point // callable like jQuery, e.g. Sha1StreamCipher('key_text').encrypt('super secret message').then((ct) => console.log(ct)); function Sha1StreamCipher (key) { function init (key) { async function getKeyStream (l) { var keyBytes = [], hash; // get first 20 bytes hash = await crypto.subtle.digest('SHA-1', key); keyBytes = keyBytes.slice.call(new Uint8Array(hash)); // get more until we have enough while (keyBytes.length < l) { hash = await crypto.subtle.digest('SHA-1', hash); keyBytes = keyBytes.concat(keyBytes.slice.call(new Uint8Array(hash))); } return keyBytes; } this.encrypt = async function (plaintext) { var keyBytes, ciphertext; plaintext = typeof plaintext == 'string' ? toUint8(plaintext) : plaintext; keyBytes = await getKeyStream(plaintext.length); ciphertext = new Uint8Array(plaintext.length); for (var i=0, il=plaintext.length; i