{"record":{"id":"d375864474a6c087","repo":"TheAlgorithms/Java","slug":"encrypted-message-should-be-a-multiple-of-64-chara","errorCode":null,"errorMessage":"Encrypted message should be a multiple of 64 characters in length","messagePattern":"Encrypted message should be a multiple of 64 characters in length","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/ciphers/DES.java","lineNumber":237,"sourceCode":"            for (j = 0; j < 8; j++) {\n                bitBlock.append(pad(Integer.toBinaryString(bytes[j]), 8));\n            }\n            encryptedMessage.append(encryptBlock(bitBlock.toString(), subKeys));\n        }\n        return encryptedMessage.toString();\n    }\n\n    /**\n     * @param message The encrypted string. Expects it to be a multiple of 64 bits, in binary format\n     * @return The decrypted String, in plain English\n     */\n    public String decrypt(String message) {\n        StringBuilder decryptedMessage = new StringBuilder();\n        int l = message.length();\n        int i;\n        int j;\n        if (l % 64 != 0) {\n            throw new IllegalArgumentException(\"Encrypted message should be a multiple of 64 characters in length\");\n        }\n        for (i = 0; i < l; i += 64) {\n            String block = message.substring(i, i + 64);\n            String result = decryptBlock(block, subKeys);\n            byte[] res = new byte[8];\n            for (j = 0; j < 64; j += 8) {\n                res[j / 8] = (byte) Integer.parseInt(result.substring(j, j + 8), 2);\n            }\n            decryptedMessage.append(new String(res));\n        }\n        return decryptedMessage.toString().replace(\"\\0\", \"\"); // Get rid of the null bytes used for padding\n    }\n}\n","sourceCodeStart":219,"sourceCodeEnd":251,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/ciphers/DES.java#L219-L251","documentation":"Thrown by DES.decrypt(String) when the ciphertext length is not a multiple of 64. This implementation treats each 64-bit block as a 64-character binary substring and processes them in a loop; a length not divisible by 64 means the input is malformed or truncated.","triggerScenarios":"Passing ciphertext that is not in the library's 64-char-per-block binary-string format, or ciphertext that was truncated/corrupted so its length is no longer a multiple of 64.","commonSituations":"Feeding hex or Base64 ciphertext instead of the binary-string format; partial transmission; mixing this DES implementation's format with another tool's output.","solutions":["Ensure the ciphertext is the binary-string output produced by this DES implementation's encrypt method.","Verify length % 64 == 0 before calling decrypt.","If ciphertext was truncated, re-obtain a complete copy rather than decrypting a partial message."],"exampleFix":"// before\nString out = des.decrypt(received);\n\n// after\nif (received.length() % 64 != 0 || !received.matches(\"[01]+\")) {\n    throw new IllegalArgumentException(\"Ciphertext must be a binary string, length multiple of 64\");\n}\nString out = des.decrypt(received);","handlingStrategy":"validation","validationCode":"if (ciphertext == null || ciphertext.length() % 64 != 0\n        || !ciphertext.matches(\"[01]+\")) {\n    throw new IllegalArgumentException(\"Ciphertext must be a binary string with length % 64 == 0\");\n}\nString out = des.decrypt(ciphertext);","typeGuard":"static boolean isDesCiphertext(String s) {\n    return s != null && s.length() % 64 == 0 && s.matches(\"[01]+\");\n}","tryCatchPattern":"try {\n    String out = des.decrypt(ciphertext);\n} catch (IllegalArgumentException e) {\n    // malformed/truncated ciphertext; re-obtain a complete copy\n}","preventionTips":["Only feed ciphertext produced by this DES implementation's encrypt.","Check length % 64 == 0 and contents before decrypting.","Do not decrypt partial/truncated messages."],"tags":["cryptography","ciphers","des","java","validation","illegalargumentexception"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}