Crypto Module¶
The rite.crypto module provides cryptographic operations including hashing, ciphers, UUIDs, and secure random generation.
Overview¶
crypto ¶
Cryptography Module¶
Comprehensive cryptographic operations for hashing, encryption, random generation, and UUIDs.
This module provides four main categories:
- Hashing (hash submodule)
- MD5, SHA-1, SHA-2 (256, 384, 512)
- SHA-3 (256, 512)
- BLAKE2b, BLAKE2s
-
HMAC message authentication
-
Ciphers (cipher submodule)
- Classical ciphers: Caesar, Vigenère, Atbash, ROT13
- Transposition ciphers: Rail Fence, Scytale
- Substitution ciphers: Playfair, Four Square, Baconian
-
Modern: XOR, Autokey
-
Random (random submodule)
- Cryptographically secure random bytes, hex, strings
-
Random integers and choices
-
UUID (uuid submodule)
- UUID generation and validation
- UUID version detection
Examples¶
from rite.crypto import hash_sha256, random_hex hash_sha256("hello")[:16] '2cf24dba5fb0a30e' len(random_hex(16)) 32
Functions¶
decode_atbash_cipher ¶
Decode text using the Atbash cipher.
This is functionally identical to encoding, since Atbash is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Atbash-encoded string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded string (same as encoding). |
decode_autokey_cipher ¶
Decode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The original cipher key. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
decode_baconian_cipher ¶
Decode Baconian-encoded text (a/b) back into plaintext.
Ignores incomplete final segments and assumes input is clean (only 'a' and 'b').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
A string of 'a' and 'b' characters, in chunks of 5. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
decode_caesar_cipher ¶
Decode Caesar cipher text by reversing the shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
shift
|
int
|
The original shift used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
decode_four_square_cipher ¶
Decode ciphertext encoded with the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encrypted message to decode. |
required |
key1
|
str
|
Key used for the top-right square. |
required |
key2
|
str
|
Key used for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
decode_playfair_cipher ¶
Decode Playfair-encoded ciphertext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string. |
required |
key
|
str
|
Cipher key used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext (not automatically de-padded). |
decode_rail_fence_cipher ¶
Decode a Rail Fence-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string to decode. |
required |
num_rails
|
int
|
Number of rails used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The original decoded plaintext string. |
decode_rot13_cipher ¶
Decode text using the Rot13 cipher.
This is functionally identical to encoding, as Rot13 is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Rot13-encoded text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded text. |
decode_scytale_cipher ¶
Decode a Scytale-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
diameter
|
int
|
Number of columns used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
decode_transposition_cipher ¶
Decode text from a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The transposed text to decode. |
required |
key
|
int
|
The number of columns used in encoding. |
required |
strip_padding
|
bool
|
Whether to strip trailing padding spaces (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded (original) text. |
decode_vigenere_cipher ¶
Decode text from the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The keyword originally used to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
decode_xor_cipher ¶
Decode XOR-encoded text using the same key.
This function is equivalent to encode_xor_cipher().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The XOR-encoded string. |
required |
key
|
str
|
The encryption key used for encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext string. |
encode_atbash_cipher ¶
Encode (or decode) text using the Atbash cipher.
Since Atbash is symmetric, the same function can be used for encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Atbash-encoded/decoded string. |
encode_autokey_cipher ¶
Encode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The cipher key (only letters are used). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_baconian_cipher ¶
Encode plaintext using the Baconian cipher.
Non-alphabetic characters are ignored. All letters are converted to lowercase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of 'a' and 'b' representing the encoded text. |
encode_caesar_cipher ¶
Encode text using the Caesar cipher.
Only alphabetic characters are shifted. Case is preserved. Other characters remain unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext string to encode. |
required |
shift
|
int
|
The number of positions to shift (can be positive or negative). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
encode_four_square_cipher ¶
Encode text using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key1
|
str
|
Key for the top-right square. |
required |
key2
|
str
|
Key for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
encode_playfair_cipher ¶
Encode plaintext using the Playfair cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input plaintext. |
required |
key
|
str
|
Cipher key for generating the Playfair square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_rail_fence_cipher ¶
Encode text using the Rail Fence cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
num_rails
|
int
|
Number of rails (rows) to use in the zigzag pattern. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
encode_rot13_cipher ¶
Encode or decode text using the Rot13 cipher.
Since Rot13 is symmetric, this function is used for both encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transformed text. |
encode_scytale_cipher ¶
Encode a string using the Scytale cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input plaintext. |
required |
diameter
|
int
|
Number of columns (characters per wrap-around). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_transposition_cipher ¶
Encode text using a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
int
|
The number of columns (i.e., transposition key). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded (scrambled) text. |
encode_vigenere_cipher ¶
Encode text using the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The keyword used to perform letter shifts. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
encode_xor_cipher ¶
Encode or decode text using the XOR cipher.
Since XOR is symmetric, this function performs both encryption and decryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext or ciphertext string. |
required |
key
|
str
|
The encryption key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str
|
A string with the result of XOR encryption/decryption. |
|
Note |
str
|
Non-printable characters may be present in the result. |
four_square_cipher_pair ¶
four_square_cipher_pair(pair: str, square_tl: list[list[str]], square_tr: list[list[str]], square_bl: list[list[str]], square_br: list[list[str]], mode: str = 'encode') -> str
Encode or decode a letter pair using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
str
|
A two-character string. |
required |
square_tl
|
list[list[str]]
|
Top-left square (standard). |
required |
square_tr
|
list[list[str]]
|
Top-right square (key 1). |
required |
square_bl
|
list[list[str]]
|
Bottom-left square (key 2). |
required |
square_br
|
list[list[str]]
|
Bottom-right square (standard). |
required |
mode
|
str
|
'encode' or 'decode'. |
'encode'
|
Returns:
| Type | Description |
|---|---|
str
|
Encoded or decoded letter pair. |
hash_sha256_hmac ¶
Compute SHA-256 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-256 string. |
Examples:
hash_sha512_hmac ¶
Compute SHA-512 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-512 string. |
Examples:
is_valid_uuid ¶
Check if uuid_to_test is a valid UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_to_test
|
str
|
String to validate as UUID |
required |
version
|
int
|
UUID version to check (1, 2, 3, or 4) |
4
|
Returns:
| Type | Description |
|---|---|
bool
|
True if valid UUID, False otherwise |
Example
is_valid_uuid('550e8400-e29b-41d4-a716-446655440000') True is_valid_uuid('invalid') False
Modules¶
cipher ¶
Rite - Cryptography - Cipher Module¶
This module serves as the central import hub for all classical ciphers implemented in the Rite cryptography toolkit. It exposes both encode and decode functions for a variety of historical and educational ciphers.
Available ciphers
- Atbash
- Autokey
- Baconian
- Caesar
- Four-Square
- Playfair
- Rail Fence
- Rot13
- Scytale
- Transposition
- Vigenère
- XOR
Functions¶
decode_atbash_cipher ¶
Decode text using the Atbash cipher.
This is functionally identical to encoding, since Atbash is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Atbash-encoded string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded string (same as encoding). |
decode_autokey_cipher ¶
Decode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The original cipher key. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
decode_baconian_cipher ¶
Decode Baconian-encoded text (a/b) back into plaintext.
Ignores incomplete final segments and assumes input is clean (only 'a' and 'b').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
A string of 'a' and 'b' characters, in chunks of 5. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
decode_caesar_cipher ¶
Decode Caesar cipher text by reversing the shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
shift
|
int
|
The original shift used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
decode_four_square_cipher ¶
Decode ciphertext encoded with the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encrypted message to decode. |
required |
key1
|
str
|
Key used for the top-right square. |
required |
key2
|
str
|
Key used for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
decode_playfair_cipher ¶
Decode Playfair-encoded ciphertext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string. |
required |
key
|
str
|
Cipher key used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext (not automatically de-padded). |
decode_rail_fence_cipher ¶
Decode a Rail Fence-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string to decode. |
required |
num_rails
|
int
|
Number of rails used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The original decoded plaintext string. |
decode_rot13_cipher ¶
Decode text using the Rot13 cipher.
This is functionally identical to encoding, as Rot13 is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Rot13-encoded text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded text. |
decode_scytale_cipher ¶
Decode a Scytale-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
diameter
|
int
|
Number of columns used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
decode_transposition_cipher ¶
Decode text from a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The transposed text to decode. |
required |
key
|
int
|
The number of columns used in encoding. |
required |
strip_padding
|
bool
|
Whether to strip trailing padding spaces (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded (original) text. |
decode_vigenere_cipher ¶
Decode text from the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The keyword originally used to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
decode_xor_cipher ¶
Decode XOR-encoded text using the same key.
This function is equivalent to encode_xor_cipher().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The XOR-encoded string. |
required |
key
|
str
|
The encryption key used for encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext string. |
encode_atbash_cipher ¶
Encode (or decode) text using the Atbash cipher.
Since Atbash is symmetric, the same function can be used for encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Atbash-encoded/decoded string. |
encode_autokey_cipher ¶
Encode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The cipher key (only letters are used). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_baconian_cipher ¶
Encode plaintext using the Baconian cipher.
Non-alphabetic characters are ignored. All letters are converted to lowercase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of 'a' and 'b' representing the encoded text. |
encode_caesar_cipher ¶
Encode text using the Caesar cipher.
Only alphabetic characters are shifted. Case is preserved. Other characters remain unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext string to encode. |
required |
shift
|
int
|
The number of positions to shift (can be positive or negative). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
encode_four_square_cipher ¶
Encode text using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key1
|
str
|
Key for the top-right square. |
required |
key2
|
str
|
Key for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
encode_playfair_cipher ¶
Encode plaintext using the Playfair cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input plaintext. |
required |
key
|
str
|
Cipher key for generating the Playfair square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_rail_fence_cipher ¶
Encode text using the Rail Fence cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
num_rails
|
int
|
Number of rails (rows) to use in the zigzag pattern. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
encode_rot13_cipher ¶
Encode or decode text using the Rot13 cipher.
Since Rot13 is symmetric, this function is used for both encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transformed text. |
encode_scytale_cipher ¶
Encode a string using the Scytale cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input plaintext. |
required |
diameter
|
int
|
Number of columns (characters per wrap-around). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
encode_transposition_cipher ¶
Encode text using a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
int
|
The number of columns (i.e., transposition key). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded (scrambled) text. |
encode_vigenere_cipher ¶
Encode text using the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The keyword used to perform letter shifts. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
encode_xor_cipher ¶
Encode or decode text using the XOR cipher.
Since XOR is symmetric, this function performs both encryption and decryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext or ciphertext string. |
required |
key
|
str
|
The encryption key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str
|
A string with the result of XOR encryption/decryption. |
|
Note |
str
|
Non-printable characters may be present in the result. |
four_square_cipher_pair ¶
four_square_cipher_pair(pair: str, square_tl: list[list[str]], square_tr: list[list[str]], square_bl: list[list[str]], square_br: list[list[str]], mode: str = 'encode') -> str
Encode or decode a letter pair using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
str
|
A two-character string. |
required |
square_tl
|
list[list[str]]
|
Top-left square (standard). |
required |
square_tr
|
list[list[str]]
|
Top-right square (key 1). |
required |
square_bl
|
list[list[str]]
|
Bottom-left square (key 2). |
required |
square_br
|
list[list[str]]
|
Bottom-right square (standard). |
required |
mode
|
str
|
'encode' or 'decode'. |
'encode'
|
Returns:
| Type | Description |
|---|---|
str
|
Encoded or decoded letter pair. |
Modules¶
cipher_atbash ¶
Rite - Cryptography - Cipher - Atbash Cipher Module¶
Provides functionality to encode and decode text using the Atbash cipher.
The Atbash cipher is a classical substitution cipher that reverses the alphabet (A ↔ Z, B ↔ Y, ..., a ↔ z).
References¶
Decode text using the Atbash cipher.
This is functionally identical to encoding, since Atbash is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Atbash-encoded string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded string (same as encoding). |
Encode (or decode) text using the Atbash cipher.
Since Atbash is symmetric, the same function can be used for encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Atbash-encoded/decoded string. |
cipher_autokey ¶
Rite - Cryptography - Cipher - Autokey Cipher Module¶
Provides functionality to encode and decode text using the Autokey cipher.
The Autokey cipher is a polyalphabetic substitution cipher that extends the key with the plaintext itself during encoding, and with the decoded text during decoding.
References¶
Decode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The original cipher key. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
Encode text using the Autokey cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The cipher key (only letters are used). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
cipher_baconian ¶
Rite - Cryptography - Cipher - Baconian Cipher Module¶
Provides functionality to encode and decode text using the Baconian cipher.
The Baconian cipher encodes each letter of the alphabet using a unique 5-letter combination of 'a' and 'b'. It is a classical steganographic cipher.
References¶
Decode Baconian-encoded text (a/b) back into plaintext.
Ignores incomplete final segments and assumes input is clean (only 'a' and 'b').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
A string of 'a' and 'b' characters, in chunks of 5. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext. |
Encode plaintext using the Baconian cipher.
Non-alphabetic characters are ignored. All letters are converted to lowercase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of 'a' and 'b' representing the encoded text. |
cipher_caesar ¶
Rite - Cryptography - Cipher - Caesar Cipher Module¶
Provides functionality to encode and decode text using the Caesar cipher.
The Caesar cipher is a substitution cipher that shifts characters by a fixed offset.
References¶
Decode Caesar cipher text by reversing the shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
shift
|
int
|
The original shift used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
Encode text using the Caesar cipher.
Only alphabetic characters are shifted. Case is preserved. Other characters remain unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext string to encode. |
required |
shift
|
int
|
The number of positions to shift (can be positive or negative). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
cipher_four_square ¶
Rite - Cryptography - Cipher - Four-Square Cipher Module¶
Provides functionality to encode and decode text using the Four-Square cipher.
This classical cipher uses four 5x5 matrices to encode letter pairs.
References¶
Decode ciphertext encoded with the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encrypted message to decode. |
required |
key1
|
str
|
Key used for the top-right square. |
required |
key2
|
str
|
Key used for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
Encode text using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key1
|
str
|
Key for the top-right square. |
required |
key2
|
str
|
Key for the bottom-left square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
Find the (row, col) position of a letter in a 5x5 matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
letter
|
str
|
The letter to locate. |
required |
square
|
list[list[str]]
|
A 5x5 matrix. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
(row_index, col_index) of the letter. |
four_square_cipher_pair(pair: str, square_tl: list[list[str]], square_tr: list[list[str]], square_bl: list[list[str]], square_br: list[list[str]], mode: str = 'encode') -> str
Encode or decode a letter pair using the Four-Square cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
str
|
A two-character string. |
required |
square_tl
|
list[list[str]]
|
Top-left square (standard). |
required |
square_tr
|
list[list[str]]
|
Top-right square (key 1). |
required |
square_bl
|
list[list[str]]
|
Bottom-left square (key 2). |
required |
square_br
|
list[list[str]]
|
Bottom-right square (standard). |
required |
mode
|
str
|
'encode' or 'decode'. |
'encode'
|
Returns:
| Type | Description |
|---|---|
str
|
Encoded or decoded letter pair. |
Generate a 5x5 matrix for the Four-Square cipher using a key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Keyword to populate the matrix. |
required |
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
A 5x5 list of characters (J is merged with I). |
cipher_playfair ¶
Rite - Cryptography - Cipher - Playfair Cipher Module¶
Provides functionality to encode and decode text using the Playfair cipher.
This classical digraph cipher uses a 5x5 matrix to substitute pairs of letters.
References¶
Create a 5x5 Playfair square using the given key.
J is omitted (merged with I), and duplicates are removed in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The keyword to use for square generation. |
required |
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
A 5x5 list of characters. |
Decode Playfair-encoded ciphertext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string. |
required |
key
|
str
|
Cipher key used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext (not automatically de-padded). |
Encode plaintext using the Playfair cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input plaintext. |
required |
key
|
str
|
Cipher key for generating the Playfair square. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
Find (row, col) of a letter in the Playfair square.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
letter
|
str
|
The letter to locate. |
required |
square
|
list[list[str]]
|
The 5x5 matrix. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (row_index, col_index) |
Encode or decode a digraph using the Playfair cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
str
|
Two-letter string. |
required |
square
|
list[list[str]]
|
The Playfair square. |
required |
mode
|
str
|
'encode' or 'decode'. |
'encode'
|
Returns:
| Type | Description |
|---|---|
str
|
Encoded or decoded two-letter string. |
Prepare text for Playfair encoding.
Replaces J with I, removes non-alphabetic characters, inserts 'X' between duplicate letters, and pads the end if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw input text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Cleaned and paired text ready for encoding. |
cipher_rail_fence ¶
Rite - Cryptography - Cipher - Rail Fence Cipher Module¶
Provides functionality to encode and decode text using the Rail Fence cipher.
The Rail Fence cipher is a transposition cipher that rearranges characters in a zigzag pattern across a fixed number of rails (rows).
References¶
Decode a Rail Fence-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The encoded string to decode. |
required |
num_rails
|
int
|
Number of rails used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The original decoded plaintext string. |
Encode text using the Rail Fence cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
num_rails
|
int
|
Number of rails (rows) to use in the zigzag pattern. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
cipher_rot13 ¶
Rite - Cryptography - Cipher - Rot13 Cipher Module¶
Provides functionality to encode and decode text using the Rot13 cipher.
The Rot13 cipher shifts each letter 13 places in the alphabet and is symmetric (i.e., encoding and decoding are the same operation).
References¶
Decode text using the Rot13 cipher.
This is functionally identical to encoding, as Rot13 is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Rot13-encoded text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded text. |
Encode or decode text using the Rot13 cipher.
Since Rot13 is symmetric, this function is used for both encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transformed text. |
cipher_scytale ¶
Rite - Cryptography - Cipher - Scytale Cipher Module¶
The Scytale cipher wraps text around a rod (cylinder) of fixed diameter, writing along its length and reading across its circumference.
References¶
Decode a Scytale-encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
diameter
|
int
|
Number of columns used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
Encode a string using the Scytale cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input plaintext. |
required |
diameter
|
int
|
Number of columns (characters per wrap-around). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext. |
cipher_transposition ¶
Rite - Cryptography - Cipher - Transposition Cipher Module¶
Provides functionality to encode and decode text using a columnar transposition cipher.
The transposition cipher rearranges the characters of the plaintext based on a fixed number of columns (key).
References¶
Decode text from a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The transposed text to decode. |
required |
key
|
int
|
The number of columns used in encoding. |
required |
strip_padding
|
bool
|
Whether to strip trailing padding spaces (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded (original) text. |
Encode text using a simple columnar transposition cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
int
|
The number of columns (i.e., transposition key). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded (scrambled) text. |
cipher_vigenere ¶
Rite - Cryptography - Cipher - Vigenère Cipher Module¶
Provides functionality to encode and decode text using the Vigenère cipher.
The Vigenère cipher is a method of encrypting alphabetic text by using a simple form of polyalphabetic substitution based on a keyword.
References¶
Decode text from the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The keyword originally used to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
Encode text using the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The keyword used to perform letter shifts. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
cipher_xor ¶
Rite - Cryptography - Cipher - XOR Cipher Module¶
Provides functionality to encode and decode text using the XOR cipher.
The XOR cipher is a symmetric key encryption technique that uses the XOR (bitwise exclusive OR) operation between the plaintext and a repeating key.
References¶
Decode XOR-encoded text using the same key.
This function is equivalent to encode_xor_cipher().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The XOR-encoded string. |
required |
key
|
str
|
The encryption key used for encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext string. |
Encode or decode text using the XOR cipher.
Since XOR is symmetric, this function performs both encryption and decryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext or ciphertext string. |
required |
key
|
str
|
The encryption key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str
|
A string with the result of XOR encryption/decryption. |
|
Note |
str
|
Non-printable characters may be present in the result. |
hash ¶
Hash Module¶
Cryptographic hash functions and message authentication.
This submodule provides hash functions including MD5, SHA family, BLAKE2, and SHA-3, as well as HMAC message authentication.
Examples¶
from rite.crypto.hash import hash_sha256, hash_blake2b hash_sha256("hello")[:16] '2cf24dba5fb0a30e' len(hash_blake2b("data")) 128
Functions¶
hash_sha256_hmac ¶
Compute SHA-256 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-256 string. |
Examples:
hash_sha512_hmac ¶
Compute SHA-512 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-512 string. |
Examples:
Modules¶
hash_blake2b ¶
BLAKE2b Hash¶
Compute BLAKE2b hash (fast, secure alternative to SHA).
Examples¶
from rite.crypto.hash import hash_blake2b len(hash_blake2b("hello")) 128
Compute BLAKE2b hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-64). |
64
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2b hash string. |
Examples:
>>> len(hash_blake2b("hello"))
128
>>> len(hash_blake2b("hello", digest_size=32))
64
>>> hash_blake2b("test")[:16]
'928b20366943e2ae'
Notes
BLAKE2b is faster than MD5, SHA-1, SHA-2, and SHA-3 while being at least as secure as SHA-3.
hash_blake2s ¶
BLAKE2s Hash¶
Compute BLAKE2s hash (optimized for 8-32 bit platforms).
Examples¶
from rite.crypto.hash import hash_blake2s len(hash_blake2s("hello")) 64
Compute BLAKE2s hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-32). |
32
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2s hash string. |
Examples:
>>> len(hash_blake2s("hello"))
64
>>> len(hash_blake2s("hello", digest_size=16))
32
>>> hash_blake2s("test")[:16]
'6b5935c36085c006'
Notes
BLAKE2s is optimized for 8-32 bit platforms and produces smaller hashes than BLAKE2b.
hash_md5 ¶
MD5 Hash¶
Compute MD5 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_md5 hash_md5("hello") '5d41402abc4b2a76b9719d911017c592'
Compute MD5 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal MD5 hash string. |
Examples:
>>> hash_md5("hello")
'5d41402abc4b2a76b9719d911017c592'
>>> hash_md5(b"hello")
'5d41402abc4b2a76b9719d911017c592'
Warning
MD5 is cryptographically broken. Use only for checksums, not for security purposes.
hash_sha1 ¶
SHA-1 Hash¶
Compute SHA-1 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_sha1 hash_sha1("hello") 'aaf4c61'
Compute SHA-1 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-1 hash string. |
Examples:
>>> hash_sha1("hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
>>> hash_sha1(b"hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
Warning
SHA-1 is deprecated for cryptographic use. Use SHA-256 or SHA-512 for security purposes.
hash_sha256 ¶
SHA-256 Hash¶
Compute SHA-256 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha256 len(hash_sha256("hello")) 64 hash_sha256_hmac("key", "message")[:16] '6e40a5e7a8b7'
Compute SHA-256 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-256 hash string (64 characters). |
Examples:
Compute SHA-256 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-256 string. |
Examples:
hash_sha384 ¶
SHA-384 Hash¶
Compute SHA-384 hash.
Examples¶
from rite.crypto.hash import hash_sha384 len(hash_sha384("hello")) 96
hash_sha3_256 ¶
SHA-3-256 Hash¶
Compute SHA-3-256 hash.
Examples¶
from rite.crypto.hash import hash_sha3_256 len(hash_sha3_256("hello")) 64
hash_sha3_512 ¶
SHA-3-512 Hash¶
Compute SHA-3-512 hash.
Examples¶
from rite.crypto.hash import hash_sha3_512 len(hash_sha3_512("hello")) 128
hash_sha512 ¶
SHA-512 Hash¶
Compute SHA-512 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha512 len(hash_sha512("hello")) 128 hash_sha512_hmac("key", "message")[:16] 'b42af09057bac1e2'
Compute SHA-512 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-512 hash string (128 characters). |
Examples:
Compute SHA-512 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-512 string. |
Examples:
hash_blake2b ¶
BLAKE2b Hash¶
Compute BLAKE2b hash (fast, secure alternative to SHA).
Examples¶
from rite.crypto.hash import hash_blake2b len(hash_blake2b("hello")) 128
Functions¶
hash_blake2b ¶
Compute BLAKE2b hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-64). |
64
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2b hash string. |
Examples:
>>> len(hash_blake2b("hello"))
128
>>> len(hash_blake2b("hello", digest_size=32))
64
>>> hash_blake2b("test")[:16]
'928b20366943e2ae'
Notes
BLAKE2b is faster than MD5, SHA-1, SHA-2, and SHA-3 while being at least as secure as SHA-3.
hash_blake2s ¶
BLAKE2s Hash¶
Compute BLAKE2s hash (optimized for 8-32 bit platforms).
Examples¶
from rite.crypto.hash import hash_blake2s len(hash_blake2s("hello")) 64
Functions¶
hash_blake2s ¶
Compute BLAKE2s hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-32). |
32
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2s hash string. |
Examples:
>>> len(hash_blake2s("hello"))
64
>>> len(hash_blake2s("hello", digest_size=16))
32
>>> hash_blake2s("test")[:16]
'6b5935c36085c006'
Notes
BLAKE2s is optimized for 8-32 bit platforms and produces smaller hashes than BLAKE2b.
hash_md5 ¶
MD5 Hash¶
Compute MD5 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_md5 hash_md5("hello") '5d41402abc4b2a76b9719d911017c592'
Functions¶
hash_md5 ¶
Compute MD5 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal MD5 hash string. |
Examples:
>>> hash_md5("hello")
'5d41402abc4b2a76b9719d911017c592'
>>> hash_md5(b"hello")
'5d41402abc4b2a76b9719d911017c592'
Warning
MD5 is cryptographically broken. Use only for checksums, not for security purposes.
hash_sha1 ¶
SHA-1 Hash¶
Compute SHA-1 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_sha1 hash_sha1("hello") 'aaf4c61'
Functions¶
hash_sha1 ¶
Compute SHA-1 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-1 hash string. |
Examples:
>>> hash_sha1("hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
>>> hash_sha1(b"hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
Warning
SHA-1 is deprecated for cryptographic use. Use SHA-256 or SHA-512 for security purposes.
hash_sha256 ¶
SHA-256 Hash¶
Compute SHA-256 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha256 len(hash_sha256("hello")) 64 hash_sha256_hmac("key", "message")[:16] '6e40a5e7a8b7'
Functions¶
hash_sha256 ¶
Compute SHA-256 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-256 hash string (64 characters). |
Examples:
hash_sha256_hmac ¶
Compute SHA-256 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-256 string. |
Examples:
hash_sha384 ¶
SHA-384 Hash¶
Compute SHA-384 hash.
Examples¶
from rite.crypto.hash import hash_sha384 len(hash_sha384("hello")) 96
hash_sha3_256 ¶
SHA-3-256 Hash¶
Compute SHA-3-256 hash.
Examples¶
from rite.crypto.hash import hash_sha3_256 len(hash_sha3_256("hello")) 64
hash_sha3_512 ¶
SHA-3-512 Hash¶
Compute SHA-3-512 hash.
Examples¶
from rite.crypto.hash import hash_sha3_512 len(hash_sha3_512("hello")) 128
hash_sha512 ¶
SHA-512 Hash¶
Compute SHA-512 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha512 len(hash_sha512("hello")) 128 hash_sha512_hmac("key", "message")[:16] 'b42af09057bac1e2'
Functions¶
hash_sha512 ¶
Compute SHA-512 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-512 hash string (128 characters). |
Examples:
hash_sha512_hmac ¶
Compute SHA-512 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-512 string. |
Examples:
random ¶
Random Module¶
Cryptographically secure random generation.
This submodule provides secure random generation using Python's secrets module for cryptographic purposes.
Examples¶
from rite.crypto.random import random_bytes, random_hex len(random_bytes(16)) 16 len(random_hex(16)) 32
Modules¶
random_bytes ¶
Random Bytes Generation¶
Generate cryptographically secure random bytes.
Examples¶
from rite.crypto.random import random_bytes len(random_bytes(16)) 16 len(random_bytes(32)) 32
random_choice ¶
Random Choice Selection¶
Cryptographically secure random choice from sequence.
Examples¶
from rite.crypto.random import random_choice random_choice(['a', 'b', 'c']) in ['a', 'b', 'c'] True random_choice("ABC") in "ABC" True
Choose random element from sequence (cryptographically secure).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence[T]
|
Non-empty sequence to choose from. |
required |
Returns:
| Type | Description |
|---|---|
T
|
Randomly selected element. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If sequence is empty. |
Examples:
random_hex ¶
Random Hex String Generation¶
Generate cryptographically secure random hex strings.
Examples¶
from rite.crypto.random import random_hex len(random_hex(16)) 32 len(random_hex(32)) 64
random_int ¶
Random Integer Generation¶
Generate cryptographically secure random integers.
Examples¶
from rite.crypto.random import random_int 0 <= random_int(0, 100) <= 100 True random_int(1, 6) in range(1, 7) True
random_urlsafe ¶
Random URL-Safe String Generation¶
Generate cryptographically secure URL-safe random strings.
Examples¶
from rite.crypto.random import random_urlsafe len(random_urlsafe(16)) 24 len(random_urlsafe(32)) 43
Generate cryptographically secure URL-safe string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbytes
|
int
|
Number of random bytes (output length varies). |
32
|
Returns:
| Type | Description |
|---|---|
str
|
Random URL-safe base64 string. |
Examples:
>>> token = random_urlsafe()
>>> len(token) > 40
True
>>> token = random_urlsafe(16)
>>> '-' not in token or '_' not in token
True
Notes
Output uses base64url encoding (A-Z, a-z, 0-9, -, _). Length is approximately 4/3 of nbytes.
random_bytes ¶
Random Bytes Generation¶
Generate cryptographically secure random bytes.
Examples¶
from rite.crypto.random import random_bytes len(random_bytes(16)) 16 len(random_bytes(32)) 32
random_choice ¶
Random Choice Selection¶
Cryptographically secure random choice from sequence.
Examples¶
from rite.crypto.random import random_choice random_choice(['a', 'b', 'c']) in ['a', 'b', 'c'] True random_choice("ABC") in "ABC" True
Functions¶
random_choice ¶
Choose random element from sequence (cryptographically secure).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence[T]
|
Non-empty sequence to choose from. |
required |
Returns:
| Type | Description |
|---|---|
T
|
Randomly selected element. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If sequence is empty. |
Examples:
random_hex ¶
Random Hex String Generation¶
Generate cryptographically secure random hex strings.
Examples¶
from rite.crypto.random import random_hex len(random_hex(16)) 32 len(random_hex(32)) 64
random_int ¶
Random Integer Generation¶
Generate cryptographically secure random integers.
Examples¶
from rite.crypto.random import random_int 0 <= random_int(0, 100) <= 100 True random_int(1, 6) in range(1, 7) True
random_urlsafe ¶
Random URL-Safe String Generation¶
Generate cryptographically secure URL-safe random strings.
Examples¶
from rite.crypto.random import random_urlsafe len(random_urlsafe(16)) 24 len(random_urlsafe(32)) 43
Functions¶
random_urlsafe ¶
Generate cryptographically secure URL-safe string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbytes
|
int
|
Number of random bytes (output length varies). |
32
|
Returns:
| Type | Description |
|---|---|
str
|
Random URL-safe base64 string. |
Examples:
>>> token = random_urlsafe()
>>> len(token) > 40
True
>>> token = random_urlsafe(16)
>>> '-' not in token or '_' not in token
True
Notes
Output uses base64url encoding (A-Z, a-z, 0-9, -, _). Length is approximately 4/3 of nbytes.
uuid ¶
Identity Module¶
This module provides unique identifier generation similar to Python's uuid module.
Functions will include: - UUID generation and utilities
Example
from rite.identity import generate_uuid generate_uuid() 'a1b2c3d4-e5f6-...'
Functions¶
is_valid_uuid ¶
Check if uuid_to_test is a valid UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_to_test
|
str
|
String to validate as UUID |
required |
version
|
int
|
UUID version to check (1, 2, 3, or 4) |
4
|
Returns:
| Type | Description |
|---|---|
bool
|
True if valid UUID, False otherwise |
Example
is_valid_uuid('550e8400-e29b-41d4-a716-446655440000') True is_valid_uuid('invalid') False
Modules¶
uuid_from_name ¶
Rite - UUID Module¶
uuid_get_version ¶
uuid_is_random ¶
uuid_is_valid ¶
UUID Validation¶
Validate UUID strings.
Check if uuid_to_test is a valid UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_to_test
|
str
|
String to validate as UUID |
required |
version
|
int
|
UUID version to check (1, 2, 3, or 4) |
4
|
Returns:
| Type | Description |
|---|---|
bool
|
True if valid UUID, False otherwise |
Example
is_valid_uuid('550e8400-e29b-41d4-a716-446655440000') True is_valid_uuid('invalid') False
uuid_random ¶
uuid_from_name ¶
Rite - UUID Module¶
uuid_get_version ¶
uuid_is_random ¶
uuid_random ¶
Submodules¶
Hashing¶
Cryptographic hash functions.
Hash Module¶
Cryptographic hash functions and message authentication.
This submodule provides hash functions including MD5, SHA family, BLAKE2, and SHA-3, as well as HMAC message authentication.
Examples¶
from rite.crypto.hash import hash_sha256, hash_blake2b hash_sha256("hello")[:16] '2cf24dba5fb0a30e' len(hash_blake2b("data")) 128
Modules¶
hash_md5 ¶
MD5 Hash¶
Compute MD5 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_md5 hash_md5("hello") '5d41402abc4b2a76b9719d911017c592'
Functions¶
hash_md5 ¶
Compute MD5 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal MD5 hash string. |
Examples:
>>> hash_md5("hello")
'5d41402abc4b2a76b9719d911017c592'
>>> hash_md5(b"hello")
'5d41402abc4b2a76b9719d911017c592'
Warning
MD5 is cryptographically broken. Use only for checksums, not for security purposes.
hash_sha1 ¶
SHA-1 Hash¶
Compute SHA-1 hash (for non-cryptographic purposes).
Examples¶
from rite.crypto.hash import hash_sha1 hash_sha1("hello") 'aaf4c61'
Functions¶
hash_sha1 ¶
Compute SHA-1 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-1 hash string. |
Examples:
>>> hash_sha1("hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
>>> hash_sha1(b"hello")
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
Warning
SHA-1 is deprecated for cryptographic use. Use SHA-256 or SHA-512 for security purposes.
hash_sha256 ¶
SHA-256 Hash¶
Compute SHA-256 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha256 len(hash_sha256("hello")) 64 hash_sha256_hmac("key", "message")[:16] '6e40a5e7a8b7'
Functions¶
hash_sha256 ¶
Compute SHA-256 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-256 hash string (64 characters). |
Examples:
hash_sha256_hmac ¶
Compute SHA-256 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-256 string. |
Examples:
hash_sha384 ¶
SHA-384 Hash¶
Compute SHA-384 hash.
Examples¶
from rite.crypto.hash import hash_sha384 len(hash_sha384("hello")) 96
hash_sha512 ¶
SHA-512 Hash¶
Compute SHA-512 hash and HMAC.
Examples¶
from rite.crypto.hash import hash_sha512 len(hash_sha512("hello")) 128 hash_sha512_hmac("key", "message")[:16] 'b42af09057bac1e2'
Functions¶
hash_sha512 ¶
Compute SHA-512 hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-512 hash string (128 characters). |
Examples:
hash_sha512_hmac ¶
Compute SHA-512 HMAC of message with key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes
|
Secret key for HMAC. |
required |
msg
|
str | bytes
|
Message to authenticate. |
required |
encoding
|
str
|
Text encoding if inputs are strings. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal HMAC-SHA-512 string. |
Examples:
hash_sha3_256 ¶
SHA-3-256 Hash¶
Compute SHA-3-256 hash.
Examples¶
from rite.crypto.hash import hash_sha3_256 len(hash_sha3_256("hello")) 64
hash_sha3_512 ¶
SHA-3-512 Hash¶
Compute SHA-3-512 hash.
Examples¶
from rite.crypto.hash import hash_sha3_512 len(hash_sha3_512("hello")) 128
hash_blake2b ¶
BLAKE2b Hash¶
Compute BLAKE2b hash (fast, secure alternative to SHA).
Examples¶
from rite.crypto.hash import hash_blake2b len(hash_blake2b("hello")) 128
Functions¶
hash_blake2b ¶
Compute BLAKE2b hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-64). |
64
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2b hash string. |
Examples:
>>> len(hash_blake2b("hello"))
128
>>> len(hash_blake2b("hello", digest_size=32))
64
>>> hash_blake2b("test")[:16]
'928b20366943e2ae'
Notes
BLAKE2b is faster than MD5, SHA-1, SHA-2, and SHA-3 while being at least as secure as SHA-3.
hash_blake2s ¶
BLAKE2s Hash¶
Compute BLAKE2s hash (optimized for 8-32 bit platforms).
Examples¶
from rite.crypto.hash import hash_blake2s len(hash_blake2s("hello")) 64
Functions¶
hash_blake2s ¶
Compute BLAKE2s hash of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
String or bytes to hash. |
required |
digest_size
|
int
|
Hash size in bytes (1-32). |
32
|
encoding
|
str
|
Text encoding if data is string. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal BLAKE2s hash string. |
Examples:
>>> len(hash_blake2s("hello"))
64
>>> len(hash_blake2s("hello", digest_size=16))
32
>>> hash_blake2s("test")[:16]
'6b5935c36085c006'
Notes
BLAKE2s is optimized for 8-32 bit platforms and produces smaller hashes than BLAKE2b.
UUID Generation¶
Generate and validate UUIDs.
Identity Module¶
This module provides unique identifier generation similar to Python's uuid module.
Functions will include: - UUID generation and utilities
Example
from rite.identity import generate_uuid generate_uuid() 'a1b2c3d4-e5f6-...'
Modules¶
uuid_random ¶
uuid_from_name ¶
Rite - UUID Module¶
uuid_is_valid ¶
UUID Validation¶
Validate UUID strings.
Functions¶
is_valid_uuid ¶
Check if uuid_to_test is a valid UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_to_test
|
str
|
String to validate as UUID |
required |
version
|
int
|
UUID version to check (1, 2, 3, or 4) |
4
|
Returns:
| Type | Description |
|---|---|
bool
|
True if valid UUID, False otherwise |
Example
is_valid_uuid('550e8400-e29b-41d4-a716-446655440000') True is_valid_uuid('invalid') False
uuid_is_random ¶
Secure Random¶
Cryptographically secure random generation.
Random Module¶
Cryptographically secure random generation.
This submodule provides secure random generation using Python's secrets module for cryptographic purposes.
Examples¶
from rite.crypto.random import random_bytes, random_hex len(random_bytes(16)) 16 len(random_hex(16)) 32
Modules¶
random_bytes ¶
Random Bytes Generation¶
Generate cryptographically secure random bytes.
Examples¶
from rite.crypto.random import random_bytes len(random_bytes(16)) 16 len(random_bytes(32)) 32
random_int ¶
Random Integer Generation¶
Generate cryptographically secure random integers.
Examples¶
from rite.crypto.random import random_int 0 <= random_int(0, 100) <= 100 True random_int(1, 6) in range(1, 7) True
random_hex ¶
Random Hex String Generation¶
Generate cryptographically secure random hex strings.
Examples¶
from rite.crypto.random import random_hex len(random_hex(16)) 32 len(random_hex(32)) 64
random_choice ¶
Random Choice Selection¶
Cryptographically secure random choice from sequence.
Examples¶
from rite.crypto.random import random_choice random_choice(['a', 'b', 'c']) in ['a', 'b', 'c'] True random_choice("ABC") in "ABC" True
Functions¶
random_choice ¶
Choose random element from sequence (cryptographically secure).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence[T]
|
Non-empty sequence to choose from. |
required |
Returns:
| Type | Description |
|---|---|
T
|
Randomly selected element. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If sequence is empty. |
Examples:
random_urlsafe ¶
Random URL-Safe String Generation¶
Generate cryptographically secure URL-safe random strings.
Examples¶
from rite.crypto.random import random_urlsafe len(random_urlsafe(16)) 24 len(random_urlsafe(32)) 43
Functions¶
random_urlsafe ¶
Generate cryptographically secure URL-safe string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbytes
|
int
|
Number of random bytes (output length varies). |
32
|
Returns:
| Type | Description |
|---|---|
str
|
Random URL-safe base64 string. |
Examples:
>>> token = random_urlsafe()
>>> len(token) > 40
True
>>> token = random_urlsafe(16)
>>> '-' not in token or '_' not in token
True
Notes
Output uses base64url encoding (A-Z, a-z, 0-9, -, _). Length is approximately 4/3 of nbytes.
Ciphers¶
Classical cipher implementations.
Rite - Cryptography - Cipher Module¶
This module serves as the central import hub for all classical ciphers implemented in the Rite cryptography toolkit. It exposes both encode and decode functions for a variety of historical and educational ciphers.
Available ciphers
- Atbash
- Autokey
- Baconian
- Caesar
- Four-Square
- Playfair
- Rail Fence
- Rot13
- Scytale
- Transposition
- Vigenère
- XOR
Modules¶
cipher_caesar ¶
Rite - Cryptography - Cipher - Caesar Cipher Module¶
Provides functionality to encode and decode text using the Caesar cipher.
The Caesar cipher is a substitution cipher that shifts characters by a fixed offset.
References¶
Functions¶
decode_caesar_cipher ¶
Decode Caesar cipher text by reversing the shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
shift
|
int
|
The original shift used during encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded plaintext string. |
encode_caesar_cipher ¶
Encode text using the Caesar cipher.
Only alphabetic characters are shifted. Case is preserved. Other characters remain unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext string to encode. |
required |
shift
|
int
|
The number of positions to shift (can be positive or negative). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded ciphertext string. |
cipher_rot13 ¶
Rite - Cryptography - Cipher - Rot13 Cipher Module¶
Provides functionality to encode and decode text using the Rot13 cipher.
The Rot13 cipher shifts each letter 13 places in the alphabet and is symmetric (i.e., encoding and decoding are the same operation).
References¶
Functions¶
decode_rot13_cipher ¶
Decode text using the Rot13 cipher.
This is functionally identical to encoding, as Rot13 is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Rot13-encoded text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded text. |
encode_rot13_cipher ¶
Encode or decode text using the Rot13 cipher.
Since Rot13 is symmetric, this function is used for both encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transformed text. |
cipher_vigenere ¶
Rite - Cryptography - Cipher - Vigenère Cipher Module¶
Provides functionality to encode and decode text using the Vigenère cipher.
The Vigenère cipher is a method of encrypting alphabetic text by using a simple form of polyalphabetic substitution based on a keyword.
References¶
Functions¶
decode_vigenere_cipher ¶
Decode text from the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_text
|
str
|
The ciphertext to decode. |
required |
key
|
str
|
The keyword originally used to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext. |
encode_vigenere_cipher ¶
Encode text using the Vigenère cipher.
Non-alphabet characters are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext to encode. |
required |
key
|
str
|
The keyword used to perform letter shifts. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The encoded ciphertext. |
cipher_atbash ¶
Rite - Cryptography - Cipher - Atbash Cipher Module¶
Provides functionality to encode and decode text using the Atbash cipher.
The Atbash cipher is a classical substitution cipher that reverses the alphabet (A ↔ Z, B ↔ Y, ..., a ↔ z).
References¶
Functions¶
decode_atbash_cipher ¶
Decode text using the Atbash cipher.
This is functionally identical to encoding, since Atbash is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Atbash-encoded string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded string (same as encoding). |
encode_atbash_cipher ¶
Encode (or decode) text using the Atbash cipher.
Since Atbash is symmetric, the same function can be used for encoding and decoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string to encode or decode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Atbash-encoded/decoded string. |
cipher_xor ¶
Rite - Cryptography - Cipher - XOR Cipher Module¶
Provides functionality to encode and decode text using the XOR cipher.
The XOR cipher is a symmetric key encryption technique that uses the XOR (bitwise exclusive OR) operation between the plaintext and a repeating key.
References¶
Functions¶
decode_xor_cipher ¶
Decode XOR-encoded text using the same key.
This function is equivalent to encode_xor_cipher().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The XOR-encoded string. |
required |
key
|
str
|
The encryption key used for encoding. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The decoded plaintext string. |
encode_xor_cipher ¶
Encode or decode text using the XOR cipher.
Since XOR is symmetric, this function performs both encryption and decryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The plaintext or ciphertext string. |
required |
key
|
str
|
The encryption key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str
|
A string with the result of XOR encryption/decryption. |
|
Note |
str
|
Non-printable characters may be present in the result. |
Examples¶
Hashing¶
from rite.crypto import hash_sha256, hash_blake2b
# SHA-256 hash
data = "sensitive data"
hashed = hash_sha256(data)
# BLAKE2b hash
hashed_b = hash_blake2b(data.encode())
UUID Operations¶
from rite.crypto import (
uuid_random,
uuid_hex,
uuid_is_valid,
uuid_from_name
)
# Generate random UUID
random_id = uuid_random()
# Get hex representation
hex_id = uuid_hex(random_id)
# Validate UUID
is_valid = uuid_is_valid(hex_id)
# Generate UUID from name
namespace_uuid = uuid_random()
name_uuid = uuid_from_name(namespace_uuid, "example.com")