{"record":{"id":"dce8ef68b9c63eea","repo":"TheAlgorithms/Python","slug":"plaintext-is-empty","errorCode":null,"errorMessage":"plaintext is empty","messagePattern":"plaintext is empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ciphers/autokey.py","lineNumber":44,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: plaintext is empty\n    >>> encrypt(\"coffee is good as python\", \"\")\n    Traceback (most recent call last):\n        ...\n    ValueError: key is empty\n    >>> encrypt(527.26, \"TheAlgorithms\")\n    Traceback (most recent call last):\n        ...\n    TypeError: plaintext must be a string\n    \"\"\"\n    if not isinstance(plaintext, str):\n        raise TypeError(\"plaintext must be a string\")\n    if not isinstance(key, str):\n        raise TypeError(\"key must be a string\")\n\n    if not plaintext:\n        raise ValueError(\"plaintext is empty\")\n    if not key:\n        raise ValueError(\"key is empty\")\n\n    key += plaintext\n    plaintext = plaintext.lower()\n    key = key.lower()\n    plaintext_iterator = 0\n    key_iterator = 0\n    ciphertext = \"\"\n    while plaintext_iterator < len(plaintext):\n        if (\n            ord(plaintext[plaintext_iterator]) < 97\n            or ord(plaintext[plaintext_iterator]) > 122\n        ):\n            ciphertext += plaintext[plaintext_iterator]\n            plaintext_iterator += 1\n        elif ord(key[key_iterator]) < 97 or ord(key[key_iterator]) > 122:\n            key_iterator += 1","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/ciphers/autokey.py#L26-L62","documentation":"Raised by autokey encrypt() when the plaintext is a str but empty (''). An empty plaintext would leave the autokey stream (key + plaintext) with nothing to encrypt and produce a meaningless empty ciphertext, so the function rejects it explicitly.","triggerScenarios":"Calling encrypt('', 'TheAlgorithms'). The isinstance checks pass because '' is a str; only the emptiness triggers this.","commonSituations":"Empty form fields, blank lines read from a file, or filtered data that reduced to zero characters reaching the cipher.","solutions":["Skip empty inputs upstream: if not plaintext: continue / return '' early in your loop.","Treat empty text as a no-op in your API: return '' without calling encrypt.","Validate combined conditions once: if not isinstance(p, str) or not p: raise ValueError(...)."],"exampleFix":"# before\nencrypt('', 'TheAlgorithms')  # ValueError: plaintext is empty\n\n# after\nif plaintext:\n    ciphertext = encrypt(plaintext, 'TheAlgorithms')\nelse:\n    ciphertext = ''","handlingStrategy":"validation","validationCode":"if not plaintext:\n    return ''  # nothing to encrypt\n# only now call encrypt(plaintext, key)","typeGuard":null,"tryCatchPattern":"try:\n    encrypt(p, k)\nexcept ValueError as e:\n    if 'empty' in str(e):\n        ciphertext = ''\n    else:\n        raise","preventionTips":["Short-circuit empty strings in message loops before encryption.","Filter blank lines/records at ingestion."],"tags":["cipher","validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}