Class CaesarMessage
Object
OpenMessage
CaesarMessage
- All Implemented Interfaces:
EncryptedMessage,Message
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected KeyNote that all you need to declare here is messageKey, as to, from, subject, and body are handled in OpenMessage, which CaesarMessage inherits fom.Fields inherited from class OpenMessage
body, from, subject, to -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class OpenMessage
getBody, getFrom, getSubject, getTo, search, searchFrom, searchSubject, searchTo, toString
-
Field Details
-
messageKey
Note that all you need to declare here is messageKey, as to, from, subject, and body are handled in OpenMessage, which CaesarMessage inherits fom.
-
-
Constructor Details
-
CaesarMessage
-
-
Method Details
-
encrypt
Encrypts the String passed into it using a Caesar Cipher. Implemented in Lab 12, all you need to do is modify it from being in OpenMessage to being in CaesarMessage, specifically with the changes to Key.Example output:
Key key = new Key("hatter","3","C"); CaesarMessage message1 = new CaesarMessage("Hatter", "Red", "New Hat", "Hatter, I need a new hat, and if I don't get it, you won't need one.", key); System.out.println(message1.encrypt(message1.getBody(), key));- Code line prints Kdwwhu/#L#qhhg#d#qhz#kdw/#dqg#li#L#grq*w#jhw#lw/#|rx#zrq*w#qhhg#rqh1
- Specified by:
encryptin interfaceEncryptedMessage- Parameters:
message- String to encryptkey- Key used to encrypt the message- Returns:
- String containing encrypted message
-
decrypt
Decrypts the String passed in. Implemented in Lab 12. Only minor changes need to be made to make it fit CaesarMessage and the Key changes.Example output:
Key key = new Key("hatter","3","C"); CaesarMessage message1 = new CaesarMessage("Hatter", "Red", "New Hat", "Hatter, I need a new hat, and if I don't get it, you won't need one.", key); String encrypted = "Kdwwhu/#L#qhhg#d#qhz#kdw/#dqg#li#L#grq*w#jhw#lw/#|rx#zrq*w#qhhg#rqh1"; System.out.println(message1.decrypt(encrypted, key));- First line prints Hatter, I need a new hat, and if I don't get it, you won't need one.
- Specified by:
decryptin interfaceEncryptedMessage- Parameters:
message- String to decryptkey- Key used to decrypt the message- Returns:
- String containing decrypted message
-
main
-