MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / decrypt

Method decrypt

src/main/java/com/thealgorithms/ciphers/DES.java:231–249  ·  view source on GitHub ↗

@param message The encrypted string. Expects it to be a multiple of 64 bits, in binary format @return The decrypted String, in plain English

(String message)

Source from the content-addressed store, hash-verified

229 * @return The decrypted String, in plain English
230 */
231 public String decrypt(String message) {
232 StringBuilder decryptedMessage = new StringBuilder();
233 int l = message.length();
234 int i;
235 int j;
236 if (l % 64 != 0) {
237 throw new IllegalArgumentException("Encrypted message should be a multiple of 64 characters in length");
238 }
239 for (i = 0; i < l; i += 64) {
240 String block = message.substring(i, i + 64);
241 String result = decryptBlock(block, subKeys);
242 byte[] res = new byte[8];
243 for (j = 0; j < 64; j += 8) {
244 res[j / 8] = (byte) Integer.parseInt(result.substring(j, j + 8), 2);
245 }
246 decryptedMessage.append(new String(res));
247 }
248 return decryptedMessage.toString().replace("\0", ""); // Get rid of the null bytes used for padding
249 }
250}

Callers

nothing calls this directly

Calls 6

decryptBlockMethod · 0.95
lengthMethod · 0.80
parseIntMethod · 0.80
replaceMethod · 0.80
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected