sustitucion module implements a Caesar cipher algorithm that shifts letters in the Spanish alphabet (including Ñ) by a specified position.
Module constants
abecedario
A dictionary mapping Spanish alphabet letters (A-Z, including Ñ) to their numeric positions.dict[str, int]
abecedario_inverso
A reverse mapping dictionary that converts numeric positions back to letters. Generated automatically fromabecedario.
dict[int, str]
These dictionaries are used internally by the conversion functions but can be accessed directly if needed for custom operations.
convertiraNumero
Converts a message string into a list of numeric values based on the Spanish alphabet.The message to convert. Letters are automatically converted to uppercase. Non-alphabetic characters are ignored.
A list of integers representing each letter’s position in the alphabet (0-26). Ñ is position 14.
The Spanish alphabet mapping includes Ñ at position 14, making the total alphabet size 27 characters (A=0 through Z=26).
Example
cifrar
Encrypts a list of numeric values by shifting each number by a specified position using modular arithmetic.A list of numeric values to encrypt (typically from
convertiraNumero).The number of positions to shift each letter forward in the alphabet (the encryption key).
The encrypted list with each value shifted by
pos modulo 27.Example
descifrar
Decrypts a list of encrypted numeric values by shifting each number backwards by the specified position.A list of encrypted numeric values to decrypt.
The number of positions to shift each letter backwards in the alphabet (must match the encryption key).
The decrypted list with each value shifted backwards by
pos modulo 27.Example
convertiraLetra
Converts a list of numeric values back into a string of letters.A list of integers representing alphabet positions (0-26) to convert back to letters.
The string representation of the numeric values.
Example
Complete encryption workflow
Here’s a complete example showing how to encrypt and decrypt a message:Alphabet reference
The module uses the following Spanish alphabet mapping:| Letter | Value | Letter | Value | Letter | Value |
|---|---|---|---|---|---|
| A | 0 | J | 9 | S | 19 |
| B | 1 | K | 10 | T | 20 |
| C | 2 | L | 11 | U | 21 |
| D | 3 | M | 12 | V | 22 |
| E | 4 | N | 13 | W | 23 |
| F | 5 | Ñ | 14 | X | 24 |
| G | 6 | O | 15 | Y | 25 |
| H | 7 | P | 16 | Z | 26 |
| I | 8 | Q | 17 |