Published
Edited
Apr 4, 2020
2 forks
2 stars
Insert cell
Insert cell
{
// Encode a string 26 times simultaneously, once for each key of the classical Caesar Cipher.
const gpu = new GPU();
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
const plaintext = 'helloworld';
const plaintextIntegerArray = plaintext.split('').map(letter => alphabet.indexOf(letter));
const caesarCipher = gpu.createKernel(function (plaintextIntegerArray, alphabetLength) {
return (plaintextIntegerArray[this.thread.x] + this.thread.y) % alphabetLength;
})
.setOutput([plaintext.length, alphabet.length]);
return caesarCipher(plaintextIntegerArray, alphabet.length)
.map(ciphertexts => [...ciphertexts]
.map(index => alphabet[index]).join(''));
}
Insert cell
GPU = (await require('gpu.js@latest')).GPU
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more