Java rot13 Hash rot13(String input)

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

Description

rot

License

Apache License

Declaration

public static String rot13(String input) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static final String HEXES = "0123456789abcdef";

    public static String rot13(String input) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c >= 'a' && c <= 'm')
                c += 13;//from w  ww.j a va2 s.  c  o  m
            else if (c >= 'n' && c <= 'z')
                c -= 13;
            else if (c >= 'A' && c <= 'M')
                c += 13;
            else if (c >= 'A' && c <= 'Z')
                c -= 13;
            sb.append(c);
        }

        return sb.toString();
    }

    /**
     * Try and provide some nice formatting for this object
     */
    private static String toString(Object fieldValue) {
        String toString;

        if (fieldValue instanceof byte[]) {
            toString = toHex((byte[]) fieldValue);
        } else {
            toString = fieldValue.toString();
        }

        return toString;
    }

    public static String toHex(byte[] raw) {
        if (raw == null) {
            return null;
        }
        int index = 0;
        final StringBuilder hex = new StringBuilder(2 * raw.length);
        for (final byte b : raw) {
            hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));

            if (index < raw.length - 1) {
                hex.append(" ");
            }

            index++;
        }
        return hex.toString();
    }
}

Related

  1. rot13(final byte b)
  2. rot13(String _input)
  3. rot13(String argInput)
  4. rot13(String input)
  5. rot13(String s)
  6. rot13(String string)
  7. rot13(String text)
  8. rot13(String value)