Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- /**
- *
- * @author Oscar
- */
- public class DescifradoSinDesplazamiento {
- public static void main(String[] args) {
- int fin = 0;
- char[] x;
- int[] veces = new int[26];
- Scanner scFile = null;
- int numero = 0;
- File f = null;
- File f1 = null;
- try {
- f = new File(args[0]);
- f1 = new File(f.getName() + ".uncfr");
- scFile = new Scanner(f);
- while (scFile.hasNext()) {
- x = scFile.next().toCharArray();
- for (char ch : x) {
- if (Character.isLetter(ch) && Character.getNumericValue(ch) > 0) {
- veces[(Character.getNumericValue(ch) - 10)]++;
- }
- }
- }
- for (int i = 0; i < veces.length; i++) {
- if (veces[i] > fin) {
- fin = veces[i];
- numero = i;
- }
- }
- } catch (Exception e) {
- System.out.println("Ha ocurrido un error");
- } finally {
- if (scFile != null) {
- scFile.close();
- }
- }
- scFile = null;
- FileWriter fw = null;
- String salida;
- int distancia;
- String[] linea;
- try {
- scFile = new Scanner(f);
- fw = new FileWriter(f1);
- distancia = numero - 4;
- while (scFile.hasNextLine()) {
- linea = scFile.nextLine().split(" ");
- for (String pal : linea) {
- salida = Cifrar.cifrarDocumento(distancia * -1, pal);
- fw.write(salida + " ");
- }
- fw.write("\n");
- }
- System.out.println("el archivo se ha descifrado correctamente");
- } catch (Exception e) {
- System.out.println("Ha ocurrido un error");
- } finally {
- if (fw != null) {
- try {
- fw.close();
- } catch (Exception e) {
- System.out.println("ha ocurrido un error");
- }
- }
- if (scFile != null) {
- scFile.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement