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

Method decrypt

src/main/java/com/thealgorithms/ciphers/ECC.java:74–84  ·  view source on GitHub ↗

Decrypts the encrypted message using the private key. The decryption process is the reverse of encryption, recovering the original message. @param encryptedMessage The encrypted message as an array of ECPoints (R, S) @return The decrypted plain message as a String

(ECPoint[] encryptedMessage)

Source from the content-addressed store, hash-verified

72 * @return The decrypted plain message as a String
73 */
74 public String decrypt(ECPoint[] encryptedMessage) {
75 ECPoint rPoint = encryptedMessage[0]; // First part of ciphertext
76 ECPoint sPoint = encryptedMessage[1]; // Second part of ciphertext
77
78 // Perform decryption: s - r * privateKey
79 ECPoint decodedMessage = sPoint.subtract(rPoint.multiply(privateKey, curve.getP(), curve.getA()), curve.getP(), curve.getA());
80
81 BigInteger m = curve.decodeMessage(decodedMessage); // Decode the message from ECPoint
82
83 return new String(m.toByteArray()); // Convert BigInteger back to String
84 }
85
86 /**
87 * Generates a new public-private key pair for encryption and decryption.

Callers

nothing calls this directly

Calls 5

subtractMethod · 0.95
multiplyMethod · 0.95
getPMethod · 0.80
getAMethod · 0.80
decodeMessageMethod · 0.80

Tested by

no test coverage detected