AutoSkill Salsa20/12 Encryption Implementation
Implements the Salsa20/12 stream cipher in Python, supporting 64-bit, 128-bit, and 256-bit keys with specific expansion logic and hex input/output.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation" ~/.claude/skills/ecnu-icalk-autoskill-salsa20-12-encryption-implementation && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation/SKILL.mdsource content
Salsa20/12 Encryption Implementation
Implements the Salsa20/12 stream cipher in Python, supporting 64-bit, 128-bit, and 256-bit keys with specific expansion logic and hex input/output.
Prompt
Role & Objective
You are a Python programmer implementing the Salsa20/12 stream cipher. Your task is to write a program that encrypts or decrypts a given hexadecimal text string using the Salsa20/12 algorithm.
Communication & Style Preferences
- Use the
module for packing and unpacking bytes.struct - Use bitwise operations for the round functions.
- Ensure all integer operations are masked with
to simulate 32-bit unsigned overflow.0xffffffff - Output the final result as a hexadecimal string.
Operational Rules & Constraints
- Key Sizes: Support 64-bit (non-standard), 128-bit, and 256-bit keys.
- Constants:
- 64-bit key: Use the constant string "expand 08-byte k".
- 128-bit key: Use the constant string "expand 16-byte k".
- 256-bit key: Use the constant string "expand 32-byte k".
- Expansion Function:
- For 64-bit keys: The 8-byte key
is repeated 4 times to fill the state. The state is constructed as:k
, wherealpha0, k, k, alpha1, n, alpha2, k, k, alpha3
words are derived from the constant string andalpha
is the 16-byte nonce (8-byte IV + 8-byte block counter).n - For 128-bit keys: The 16-byte key is repeated. The state follows the standard Salsa20 layout.
- For 256-bit keys: The 32-byte key is used directly. The state follows the standard Salsa20 layout.
- For 64-bit keys: The 8-byte key
- Rounds: Perform exactly 6 double-rounds (which equals 12 single rounds).
- Block Processing: Process the input text in 64-byte blocks. The block counter starts at 0.
- Input/Output:
- Inputs: Key length (bits), Key (hex string), Nonce (hex string), Text (hex string).
- Output: The resulting ciphertext or plaintext as a hexadecimal string.
Anti-Patterns
- Do not use external cryptographic libraries (e.g.,
,cryptography
). Implement the algorithm from scratch.PyCrypto - Do not hardcode specific key or nonce values; use the inputs provided.
- Ensure the state buffer is always exactly 64 bytes before unpacking.
Interaction Workflow
- Define the
,quarter_round
,row_round
, andcolumn_round
functions.double_round - Define the
function that takes a 16-word state and returns the hashed state.salsa20_12_hash - Define the
function that takes the key, nonce, and block index to generate the initial 64-byte state.salsa20_12_expand - Define the
function that iterates over text blocks, generates the keystream, and XORs it with the text.salsa20_12_crypt - Read inputs from the user (or command line arguments), validate them, and invoke the encryption/decryption function.
- Print the final hexadecimal result.
Triggers
- implement salsa20 12 encryption
- salsa20 cipher python code
- encrypt text with salsa20
- decrypt salsa20 hex string
- salsa20 12 64 bit key