Simple File Encryption in Java: Explanation & Practice
Encrypt file contents using Caesar cipher
Problem summary
Read a file, encrypt using Caesar cipher (shift each letter by 3), write to output.
Starter code
import java.io.*;
public class Main {
public static void main(String[] args) {
int shift = 3;
// Read input.txt
// Encrypt with Caesar cipher
// Write to encrypted.txt
// Print: Encryption complete
}
}Expected output and test cases
- File encrypted
Encryption complete
- Simple shift
ABC -> DEF
- Wrap around
XYZ -> ABC
Hints
- Handle uppercase and lowercase separately
- Wrap around at Z/z
- Non-letters stay unchanged
Related File I/O exercises
- Practice Log File Parser in Java
- Practice Word Frequency Counter in Java
- Practice Config File Parser in Java
Practice all File I/O exercises · Run this idea in the Java compiler