ROT13 Cipher in Java
import java.util.Scanner;
public class ROT13Cipher {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Taking input
System.out.print("Enter a text: ");
String input = scanner.nextLine();
int length = input.length();
// Checking length constraints
if (length <= 3 || length >= 100) {
System.out.println("Invalid input. Length must be greater than 3 and less
than 100.");
} else {
String cipherText = "";
// Encrypting the text using ROT13
for (int i = 0; i < length; i++) {
char c = input.charAt(i);
if (c >= 'a' && c <= 'z') {
c = (char) ((c - 'a' + 13) % 26 + 'a');
} else if (c >= 'A' && c <= 'Z') {
c = (char) ((c - 'A' + 13) % 26 + 'A');
}
cipherText += c; // Append the encrypted character
}
System.out.println("The cipher text is: " + cipherText);
}
scanner.close();
}
}