Advertisement
AlvaroOrtiz

Descifrado.java

Mar 31st, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.cuarentena;
  7.  
  8. import java.io.*;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author Álvaro Ortiz Falcón y Arturo Martínez Menor
  14.  */
  15. public class Descifrado {
  16.  
  17.     public static void main(String[] args) {
  18.  
  19.         Scanner sc = null;
  20.         String palabra[];
  21.         String palabraCifrada;
  22.         FileWriter myobj = null;
  23.         int desplazarletra = Integer.parseInt(args[1]);
  24.  
  25.         try {
  26.             File cifrado = new File(args[0]);
  27.             File f1 = new File(cifrado.getName() + ".uncfr");
  28.             sc = new Scanner(cifrado);
  29.             myobj = new FileWriter(f1);
  30.             desplazarletra = desplazarletra * -1;
  31.             while (sc.hasNextLine()) {
  32.                 palabra = sc.nextLine().split(" ");
  33.                 for (String c : palabra) {
  34.                     palabraCifrada = Cifrar.Cifra(desplazarletra, c);
  35.                     myobj.write(palabraCifrada + " ");
  36.                 }
  37.                 myobj.write("\n");
  38.             }
  39.             System.out.println("Archivo descifrado correctamente");
  40.         } catch (Exception e) {
  41.             System.out.println("Vaya... parece que algo no ha salido bien, puede que no se encuentre el archivo especificado o que no funcione el descifrado cosa bastante improbable");
  42.         } finally {
  43.             if (sc != null) {
  44.                 sc.close();
  45.             }
  46.             if (myobj != null) {
  47.                 try {
  48.                     myobj.close();
  49.                 } catch (Exception e) {
  50.                     System.out.println("Algo ha salido mal y el fichero no se ha podido cerrar bien revisa el código");
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement