/* * Copyright (c) 2004 David Flanagan. All rights reserved. * This code is from the book Java Examples in a Nutshell, 3nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose, * including teaching and use in open-source projects. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book, * please visit http://www.davidflanagan.com/javaexamples3. */ import java.io.*; // We're doing input, so import I/O classes /** * This program reads lines of text from the user, encodes them using the * trivial "Rot13" substitution cipher, and then prints out the encoded lines. **/ public class Rot13Input { public Rot13Input(){} public static void main(String[] args) throws IOException { } /** * This method performs the Rot13 substitution cipher. It "rotates" * each letter 13 places through the alphabet. Since the Latin alphabet * has 26 letters, this method both encodes and decodes. **/ public char rot13(char c) { if ((c >= 'A') && (c <= 'Z')) { // For uppercase letters c += 13; // Rotate forward 13 if (c > 'Z') c -= 26; // And subtract 26 if necessary } if ((c >= 'a') && (c <= 'z')) { // Do the same for lowercase letters c += 13; if (c > 'z') c -= 26; } return c; } }