{"record":{"id":"7bd198ac3e1ed92c","repo":"TheAlgorithms/Python","slug":"ciphertext-is-empty","errorCode":null,"errorMessage":"ciphertext is empty","messagePattern":"ciphertext is empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ciphers/autokey.py","lineNumber":109,"sourceCode":"    Traceback (most recent call last):\n        ...\n    TypeError: ciphertext must be a string\n    >>> decrypt(\"\", \"TheAlgorithms\")\n    Traceback (most recent call last):\n        ...\n    ValueError: ciphertext is empty\n    >>> decrypt(\"vvjfpk wj ohvp su ddylsv\", 2)\n    Traceback (most recent call last):\n        ...\n    TypeError: key must be a string\n    \"\"\"\n    if not isinstance(ciphertext, str):\n        raise TypeError(\"ciphertext must be a string\")\n    if not isinstance(key, str):\n        raise TypeError(\"key must be a string\")\n\n    if not ciphertext:\n        raise ValueError(\"ciphertext is empty\")\n    if not key:\n        raise ValueError(\"key is empty\")\n\n    key = key.lower()\n    ciphertext_iterator = 0\n    key_iterator = 0\n    plaintext = \"\"\n    while ciphertext_iterator < len(ciphertext):\n        if (\n            ord(ciphertext[ciphertext_iterator]) < 97\n            or ord(ciphertext[ciphertext_iterator]) > 122\n        ):\n            plaintext += ciphertext[ciphertext_iterator]\n        else:\n            plaintext += chr(\n                (ord(ciphertext[ciphertext_iterator]) - ord(key[key_iterator])) % 26\n                + 97\n            )","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/ciphers/autokey.py#L91-L127","documentation":"Raised by autokey decrypt() when the ciphertext is a str but empty (''). With no ciphertext there is nothing to decrypt and the key-extension loop would never run; the function rejects empty input explicitly rather than silently returning ''.","triggerScenarios":"Calling decrypt('', 'TheAlgorithms'). Type checks pass; only emptiness triggers the ValueError.","commonSituations":"Blank messages in test fixtures, reading past EOF into an empty string, or empty rows in a batch of encrypted records.","solutions":["Short-circuit empty input in the caller: return '' immediately if not ciphertext.","Filter empty entries before batch processing: [c for c in batch if c].","Log and skip rather than letting the ValueError abort a whole batch."],"exampleFix":"# before\ndecrypt('', 'TheAlgorithms')  # ValueError: ciphertext is empty\n\n# after\nplaintext = decrypt(ciphertext, 'TheAlgorithms') if ciphertext else ''","handlingStrategy":"validation","validationCode":"if not ciphertext:\n    return ''  # nothing to decrypt","typeGuard":null,"tryCatchPattern":"try:\n    decrypt(c, k)\nexcept ValueError as e:\n    if 'empty' in str(e):\n        plaintext = ''\n    else:\n        raise","preventionTips":["Skip empty records in batch decryption loops.","Test fixtures should include an empty-string case to lock in your chosen policy."],"tags":["cipher","validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}