0% found this document useful (0 votes)
3 views2 pages

Caesar Cipher: Encode and Decode Methods

The document provides a Java implementation of the Caesar Cipher for encryption and decryption. It includes methods to encode and decode messages using a specified offset, demonstrating the functionality with the example input 'Anna University'. The output shows the encrypted and decrypted messages, confirming the correctness of the implementation.

Uploaded by

Surya Dharshini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Caesar Cipher: Encode and Decode Methods

The document provides a Java implementation of the Caesar Cipher for encryption and decryption. It includes methods to encode and decode messages using a specified offset, demonstrating the functionality with the example input 'Anna University'. The output shows the encrypted and decrypted messages, confirming the correctness of the implementation.

Uploaded by

Surya Dharshini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Encryption and Decryption Using Ceaser Cipher

[Link]
class caesarCipher {
public static String encode(String enc, int offset) {
offset = offset % 26 + 26;
StringBuilder encoded = new StringBuilder();
for (char i : [Link]()) {
if ([Link](i)) {
if ([Link](i)) {
[Link]((char) ('A' + (i - 'A' + offset) % 26));
} else {
[Link]((char) ('a' + (i - 'a' + offset) % 26));
}
} else {
[Link](i);
}
}
return [Link]();
}

public static String decode(String enc, int offset) {


return encode(enc, 26 - offset);
}

public static void main(String[] args) throws [Link] {


String msg = "Anna University";
[Link]("Simulating Caesar Cipher\n------------------------");
[Link]("Input : " + msg);
[Link]("Encrypted Message : ");
[Link]([Link](msg, 3));
[Link]("Decrypted Message : ");
[Link]([Link]([Link](msg, 3), 3));
}
}

OUTPUT:
Simulating Caesar Cipher
------------------------
Input : Anna University
Encrypted Message : Dqqd Xqlyhuvlwb
Decrypted Message : Anna University

You might also like