Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Entregable9_1;
- import java.io.*;
- import java.util.Scanner;
- /**
- *
- * @author unaim
- */
- public class DescifradoCesar {
- public static void main(String[] args) {
- Scanner scFile = null;
- FileWriter fw = null;
- String[] linea;
- String salida;
- int n;
- try {
- File fichero = new File(args[0]);
- File fichero1 = new File(fichero.getName() + ".uncfr");
- scFile = new Scanner(fichero);
- fw = new FileWriter(fichero1);
- if (Integer.parseInt(args[1]) > 25) {
- n = Integer.parseInt(args[1]) % 26;
- } else if (Integer.parseInt(args[1]) < -25) {
- n = Integer.parseInt(args[1]) * -1 % 26;
- n *= -1;
- }else{
- n = Integer.parseInt(args[1]);
- }
- while (scFile.hasNextLine()) {
- linea = scFile.nextLine().split(" ");
- for (String palabra : linea) {
- salida = MetodoCifrar.cifrarFichero(n * -1, palabra);
- fw.write(salida + " ");
- }
- fw.write("\n");
- }
- System.out.println("El archivo ha sido descifrado correctamente");
- } catch (Exception e) {
- System.out.println("Se ha producido un error");
- }finally{
- if(scFile != null){
- scFile.close();
- }
- if (fw != null) {
- try{
- fw.close();
- }catch(Exception e){
- System.out.println("Se ha producido un error");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement