All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.xseris.jca.cryptography.rot.Rot47 Maven / Gradle / Ivy

The newest version!
package it.xseris.jca.cryptography.rot;

public class Rot47 {

	/**
	 * Encode the text using ROT-47.
	 * 
	 * @param text
	 *            The input text.
	 * @return The result.
	 */
	public static String encode(String text) {
		StringBuilder ret = new StringBuilder();
		for (int i = 0; i < text.length(); i++) {
			char c = text.charAt(i);
			if (c != ' ') {
				c += 47;
				if (c > '~') {
					c -= 94;
				}
			}
			ret.append(c);
		}
		return ret.toString();
	}

	/**
	 * Decode the text using ROT-47.
	 * 
	 * @param text
	 *            The input text.
	 * @return The result.
	 */
	public static String decode(String text) {
		return encode(text);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy