Fundamentos de criptografÃa
Las cartas secretas de MarÃa Estuardo, reina de Escocia
Introducción a la CriptografÃa
Encripción y Estrategias de Ofuscación
CriptografÃa Clásica
Conceptos Criptográficos
Aleatoriedad
Manejo de Aleatoriedad en JavaScript
Cryptoanálisis y Seguridad de Cifrado
Seguridad Criptográfica
CriptografÃa Simétrica
Ciphers
Advanced Encryption Standard
Cifrar y descrifrar archivos con JavaScript
Seguridad a través de Hashes
Funciones de hash comunes
CriptografÃa Asimétrica
Aritmética modular en CriptotografÃa Asimétrica
Intercambio de llaves y el problema del logaritmo discreto
Algoritmo de Diffie-Hellman
Cifrar mensajes con el algoritmo de Deffie-Hellman.
RSA y firma digital
Implementar Algoritmo de RSA y firma digital
CriptografÃa de Curvas ElÃpticas
ECDSA y tipos de curvas
CriptografÃa Moderna
Infraestructura de llave pública (PKI)
Sistemas de pruebas interactivos
Computación Cuántica
Investigación en CriptografÃa
You don't have access to this class
Keep learning! Join and start boosting your career
In the programming world, randomness is a fundamental tool for various cryptographic systems and advanced practices. Here I will guide you step by step on how to create a pseudo-random number generation function using Node.js. If you use another programming language, you can opt for the standard libraries it offers. Most of these languages have libraries that allow you to work with these random number generation algorithms.
The first thing you will do is to configure and add a new command in our preconfigured command line. This command will be called prng
, which stands for "pseudo random number generation". This name is common in several sources. Below, we add a short description:
const argv = require('yargs/yargs')(process.argv.slice(2)).command('prng', 'Generate a random number', () => {}, (argv) => {}).argv;
This code base will allow you to expand the functionality as needed.
In the builder we will configure the options to customize the generation of numbers:
Randomness type: we will define three main choices:
bytes
integers
Size: Essential parameter to determine the length of our cryptographic key. Generally, a default size of 16 bytes is sufficient.
Maximum and minimum number: Applied only for integers, it allows to delimit the range of the generated numbers.
Encoding: Determines how the result will be displayed on the screen. The options are predefined and you can leave them in a configuration file to keep your code clean. The default value is hexadecimal
, as it is one of the most manageable formats for this type of project.
To begin with, we will create a new folder with a file to implement the functionality. Make sure you have the Node.js crypto
library, which is included natively:
const crypto = require('crypto');
function generatorPseudoRandomNumbers(type, size, min, max, encoding) { switch (type) { case 'bytes': return crypto.randomBytes(size).toString(encoding); case 'integers': return crypto.randomInt(min, max).toString(); case 'uuid': return crypto.randomUUID(); default: return null; }}
In this function the desired random type
is captured and processed according to the byte
, integer
or uuid
options.
Finally, export the function and call it from your command line. Make sure you extract and pass the parameters correctly:
console.log(generatorPseudoRandomNumbers(type, size, min, max, encoding));
Perform the necessary tests and verify that the numbers are generated as expected. It will also be useful to document which options are required for certain types of generation, such as min
and max
parameters only applicable to integers.
With this setup you can generate random numbers not only for personal projects, but also in work environments where numbers or secret keys are required. Experiment by trying different input values and expand the capabilities of your project! If you have new ideas for improving the generator, it would be wonderful if you could share them with your colleagues or implement them in your own projects.
Contributions 11
Questions 2
CAzadores en la red se convierten en los nuevos héroes, navegando a través de laberintos digitales para encontrar la clave que desactivará la omnipresente IA antes de que su control se vuelva inquebrantable
Gracias
Want to see more contributions, questions and answers from the community?