Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class DescifrarSinRango {
- static String abecedario = Utils.alfabeto;
- static int[] contador;
- public static int generarNumero(String ruta) {
- String texto;
- int n, max = 0, pos = 0;
- char letra;
- File archivo = null;
- Scanner scFile = null;
- try {
- archivo = new File(ruta);
- scFile = new Scanner(archivo);
- while (scFile.hasNext()) {
- texto = scFile.nextLine().toLowerCase();
- for (int i = 0; i < texto.length(); i++) {
- letra = texto.charAt(i);
- n = abecedario.indexOf(letra);
- if (n != -1) {
- contador[n]++;
- }
- }
- }
- max = contador[0];
- pos = 0;
- for (int i = 1; i < contador.length; i++) {
- if (contador[i] > max) {
- max = contador[i];
- pos = i;
- }
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- } finally {
- try {
- scFile.close();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
- }
- return pos - abecedario.indexOf("e");
- }
- public static void main(String[] args) {
- String ruta;
- boolean hechoCorrectamente = false;
- contador = new int[abecedario.length()];
- int numeroDesplazamiento = generarNumero(args[0]);
- hechoCorrectamente = Utils.escribirTexto(args[0], args[0] + ".uncfr", 26 - numeroDesplazamiento);
- if (hechoCorrectamente) {
- System.out.println("Se ha generado correctamente");
- } else {
- System.out.println("No se ha podido generar");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement