Languages
[Edit]
EN

JavaScript - One-time Pad encryption with XOR on strings

9 points
Created by:
Olivier-Myers
514

In this short article, we would like to show a simple JavaScript implementation of the most save encryption that was invented by humans - One-time Pad encryption with XOR on strings.

Encryption example:

 

Pactical example

Edit

In this section you can find example One-time Pad strings encryption. In the example we encode strings to UTF-8 bytes. To show the main idea we encoded 3 strings: abc, 123 and abc again - as we can see encoded text is always different that makes algorithm stronger.

Hint: the below algorithm source code extends this article - adds posibility to encrypt and decrypt strings.

The algorithm is as strong as perfectly random numbers have been used as secret keys.

Conclusions:

  • abc encrypted 2 times returned 2 different results: [143,169,133] and [90,104,10] - it is provided by once time secret key usage composed of random numbers.

 

See also

Edit
  1. JavaScript - One-time Pad encryption with XOR

  2. JavaScript - random bytes

  3. JavaScript - own random number generator (custom implementation)

  4. JavaScript - convert string to bytes array

  5. JavaScript - convert bytes array to string

Alternative titles

  1. JavaScript - One-time Pad encryption with XOR on string
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join