Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.cuarentena;
- import java.io.*;
- import java.util.Scanner;
- /**
- *
- * @author Álvaro Ortiz Falcón y Arturo Martínez Menor
- */
- public class Descifrado {
- public static void main(String[] args) {
- Scanner sc = null;
- String palabra[];
- String palabraCifrada;
- FileWriter myobj = null;
- int desplazarletra = Integer.parseInt(args[1]);
- try {
- File cifrado = new File(args[0]);
- File f1 = new File(cifrado.getName() + ".uncfr");
- sc = new Scanner(cifrado);
- myobj = new FileWriter(f1);
- desplazarletra = desplazarletra * -1;
- while (sc.hasNextLine()) {
- palabra = sc.nextLine().split(" ");
- for (String c : palabra) {
- palabraCifrada = Cifrar.Cifra(desplazarletra, c);
- myobj.write(palabraCifrada + " ");
- }
- myobj.write("\n");
- }
- System.out.println("Archivo descifrado correctamente");
- } catch (Exception e) {
- 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");
- } finally {
- if (sc != null) {
- sc.close();
- }
- if (myobj != null) {
- try {
- myobj.close();
- } catch (Exception e) {
- System.out.println("Algo ha salido mal y el fichero no se ha podido cerrar bien revisa el código");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement