@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)
| 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 | } |