Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication11;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- /**
- *
- * @author mrybak
- */
- public class JavaApplication11 {
- static void szyfruj(String nazwaWe, String nazwaWed, int przesun) throws Exception
- {
- FileReader fileR = new FileReader(nazwaWe);
- BufferedReader bufferedR = new BufferedReader(fileR);
- FileWriter plik = new FileWriter(nazwaWed);
- char literka;
- String s="";
- try
- {
- while(nazwaWe != null)
- {
- s="";
- for (int i =0;i<nazwaWe.length();i++)
- {
- if(nazwaWe.charAt(i) != ' ')
- {
- literka = nazwaWe.charAt(i);
- literka += przesun;
- //System.out.print(literka);
- if ((literka > 64 && literka < 91) || (literka > 96 && literka <123))
- {
- }
- else
- {
- literka -= 26;
- }
- s +=literka;
- }
- else
- {
- literka = nazwaWe.charAt(i);
- s +=literka;
- }
- //nazwaWe.charAt(i)=c;
- }
- System.out.print("\n");
- System.out.print(s);
- plik.write(s + "\n");
- System.out.print("\n");
- nazwaWe = bufferedR.readLine();
- }
- plik.close();
- }
- catch(IOException ex)
- {
- System.out.println("BŁĄD ODCZYTU Z PLIKU!");
- ex.getStackTrace();
- }
- finally
- {
- if (fileR != null)
- fileR.close();
- }
- }
- static void deszyfruj(String nazwaWe, int przesun) throws Exception
- {
- FileReader fileR = new FileReader(nazwaWe);
- BufferedReader bufferedR = new BufferedReader(fileR);
- FileWriter plik = new FileWriter("_dane.txt");
- char literka;
- String s="";
- try
- {
- while(nazwaWe != null)
- {
- s="";
- for (int i =0;i<nazwaWe.length();i++)
- {
- if(nazwaWe.charAt(i) != ' ')
- {
- literka = nazwaWe.charAt(i);
- literka -= przesun;
- //System.out.print(literka);
- if ((literka > 64 && literka < 91) || (literka > 96 && literka <123))
- {
- }
- else
- {
- literka += 26;
- }
- s +=literka;
- }
- else
- {
- literka = nazwaWe.charAt(i);
- s +=literka;
- }
- //nazwaWe.charAt(i)=c;
- }
- System.out.print("\n");
- System.out.print(s);
- plik.write(s + "\n");
- System.out.print("\n");
- nazwaWe = bufferedR.readLine();
- }
- plik.close();
- }
- catch(IOException ex)
- {
- System.out.println("BŁĄD ODCZYTU Z PLIKU!");
- ex.getStackTrace();
- }
- finally
- {
- if (fileR != null)
- fileR.close();
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws Exception {
- // TODO code application logic here
- szyfruj("dane.txt","dane1.txt",5);
- deszyfruj("dane1.txt",5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment