Java rot13 Hash rot13(String value)

Here you can find the source of rot13(String value)

Description

Replace every alpha character in a string with the character 13 over

License

Open Source License

Parameter

Parameter Description
value string to rotate

Return

rotated result

Declaration

public static String rot13(String value) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", LOWER = "abcdefghijklmnopqrstuvwxyz";

    /**// www . j av a  2s . co  m
     * Replace every alpha character in a string with the character 13 over  
     * @param value string to rotate
     * @return rotated result
     */
    public static String rot13(String value) {
        StringBuffer buffer = new StringBuffer(value.length());

        int count = value.length();
        int index;
        char c;
        for (int i = 0; i < count; i++) {
            c = value.charAt(i);

            if ((index = LOWER.indexOf(c)) >= 0) {
                buffer.append(LOWER.charAt((index + 13) % 26));
            } else if ((index = UPPER.indexOf(c)) >= 0) {
                buffer.append(UPPER.charAt((index + 13) % 26));
            } else {
                buffer.append(c);
            }
        }

        return buffer.toString();
    }
}

Related

  1. rot13(String input)
  2. rot13(String input)
  3. rot13(String s)
  4. rot13(String string)
  5. rot13(String text)