Last active
May 20, 2026 06:59
-
-
Save gkucmierz/ddcd4ce55612052d320b4b3f57935fb5 to your computer and use it in GitHub Desktop.
Run this code instantly in your browser: https://instacode.app/gist/ddcd4ce55612052d320b4b3f57935fb5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://hackernoon.com/how-does-rsa-work-f44918df914b | |
| const key = { | |
| mod: 14, | |
| pub: 5, | |
| prv: 11, | |
| }; | |
| const msg = 'hello'; | |
| const bits = [...msg].map(c => c.charCodeAt().toString(2).padStart(8, '0')).join(''); | |
| const bits2 = bits.match(/../g).map(c => parseInt(c, 2)); | |
| const enc = bits2.map(c => { | |
| return (c ** key.pub) % key.mod; | |
| }); | |
| const dec = enc.map(n => { | |
| return (n ** key.prv) % key.mod; | |
| }); | |
| console.log( | |
| dec | |
| .map(n => n.toString(2).padStart(2, '0')).join('') | |
| .match(/.{8}/g).map(b => String.fromCharCode(parseInt(b, 2))) | |
| .join('') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment