Cifrado ROOT13

[aux_code language=»javascript» theme=»tomorrow» title=»Cifrado ROOT13″ extra_classes=»»]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String o;
        do {
            try {
                System.out.println("Cifrar, descifrar o salir (C|D|S):");
                o = br.readLine().toUpperCase();
                switch (o) {
                    case "C":
                        System.out.println("Cifrar:");
                        System.out.println(cifrar(br.readLine()));
                        break;
                    case "D":
                        System.out.println("Descifrar:");
                        System.out.println(descifrar(br.readLine()));
                        break;
                    case "S":
                        System.out.println("Me despido!");
                        break;
                    default:
                        System.out.println("Opción no válida.");
                        break;
                }
            } catch (IOException e) {
                System.out.println("Hubo un error");
                o = "";
            }
        } while (!o.equals("S"));
    }

    private static String descifrar(String d) {
        StringBuilder dato = new StringBuilder();
        for (int x = 0; x < d.length(); x++) {
            char v = d.charAt(x);
            if (v >= 97 && v <= 109 || v >= 65 && v <= 77) {
                v = (char) (v + 13);
            } else if (v >= 110 && v <= 123 || v >= 78 && v <= 92) {
                v = (char) (v - 13);
            }
            dato.append(v);
        }
        return dato.toString();
    }

    private static String cifrar(String d) {
        return descifrar(d);
    }
}
[/aux_code]
Etiquetas: Sin etiquetas

Añadir un comentario

Debes estar conectado para publicar un comentario