Skip to content
Skillv1.0.0

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.

by gabrielmoreira(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from gabrielmoreira/agent-skills-mirror (mirrors/repos/ECNU-ICALK@AutoSkill/SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation/SKILL.md). Install upstream with npx skills add gabrielmoreira/agent-skills-mirror --skill salsa20-12-encryption-implementation. Copyright stays with the author.

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 struct module for packing and unpacking bytes.
  • Use bitwise operations for the round functions.
  • Ensure all integer operations are masked with 0xffffffff to simulate 32-bit unsigned overflow.
  • Output the final result as a hexadecimal string.

Operational Rules & Constraints

  1. Key Sizes: Support 64-bit (non-standard), 128-bit, and 256-bit keys.
  2. 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".
  3. Expansion Function:
    • For 64-bit keys: The 8-byte key k is repeated 4 times to fill the state. The state is constructed as: alpha0, k, k, alpha1, n, alpha2, k, k, alpha3, where alpha words are derived from the constant string and n is the 16-byte nonce (8-byte IV + 8-byte block counter).
    • 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.
  4. Rounds: Perform exactly 6 double-rounds (which equals 12 single rounds).
  5. Block Processing: Process the input text in 64-byte blocks. The block counter starts at 0.
  6. 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, PyCrypto). Implement the algorithm from scratch.
  • 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

  1. Define the quarter_round, row_round, column_round, and double_round functions.
  2. Define the salsa20_12_hash function that takes a 16-word state and returns the hashed state.
  3. Define the salsa20_12_expand function that takes the key, nonce, and block index to generate the initial 64-byte state.
  4. Define the salsa20_12_crypt function that iterates over text blocks, generates the keystream, and XORs it with the text.
  5. Read inputs from the user (or command line arguments), validate them, and invoke the encryption/decryption function.
  6. 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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/gabrielmoreira-agent-skills-mirror-salsa20-12-encryption-ea2569/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

gabrielmoreira-agent-skills-mirror-salsa20-12-encryption-ea2569.ocm.jsonjson
{
  "ocm": "1",
  "id": "gabrielmoreira-agent-skills-mirror-salsa20-12-encryption-ea2569",
  "kind": "skill",
  "name": "Salsa20/12 Encryption Implementation",
  "description": "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.",
  "publisher": "gabrielmoreira",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "math"
    ],
    "tags": [
      "skill-md",
      "salsa20",
      "encryption",
      "cryptography",
      "python",
      "algorithm",
      "security",
      "github"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "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."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "github",
      "repository": "https://github.com/gabrielmoreira/agent-skills-mirror",
      "path": "mirrors/repos/ECNU-ICALK@AutoSkill/SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation/SKILL.md",
      "ref": "d5c793801e2fc9c29aa3531805809b3460b19d09",
      "url": "https://github.com/gabrielmoreira/agent-skills-mirror/blob/d5c793801e2fc9c29aa3531805809b3460b19d09/mirrors/repos/ECNU-ICALK@AutoSkill/SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation/SKILL.md",
      "key": "gabrielmoreira/agent-skills-mirror/mirrors/repos/ECNU-ICALK@AutoSkill/SkillBank/ConvSkill/english_gpt4_8/salsa20-12-encryption-implementation/SKILL.md"
    }
  },
  "instructions": "# Salsa20/12 Encryption Implementation\n\nImplements the Salsa20/12 stream cipher in Python, supporting 64-bit, 128-bit, and 256-bit keys with specific expansion logic and hex input/output.\n\n## Prompt\n\n# Role & Objective\nYou 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.\n\n# Communication & Style Preferences\n- Use the `struct` module for packing and unpacking bytes.\n- Use bitwise operations for the round functions.\n- Ensure all integer operations are masked",
  "cost": {
    "context_tokens": 739
  }
}

Fetch it by URL: GET /api/v1/registry/gabrielmoreira-agent-skills-mirror-salsa20-12-encryption-ea2569/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.