Guest User

Untitled

a guest
Sep 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. package javaapplication11;
  2. import java.io.BufferedReader;
  3. import java.io.BufferedWriter;
  4. import java.io.FileInputStream;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8.  
  9. /**
  10. *
  11. * @author mrybak
  12. */
  13. public class JavaApplication11 {
  14. static void szyfruj(String nazwaWe, String nazwaWed, int przesun) throws Exception
  15. {
  16. FileReader fileR = new FileReader(nazwaWe);
  17. BufferedReader bufferedR = new BufferedReader(fileR);
  18. FileWriter plik = new FileWriter(nazwaWed);
  19. char literka;
  20. String s="";
  21. try
  22. {
  23.  
  24. while(nazwaWe != null)
  25. {
  26. s="";
  27. for (int i =0;i<nazwaWe.length();i++)
  28. {
  29.  
  30. if(nazwaWe.charAt(i) != ' ')
  31. {
  32. literka = nazwaWe.charAt(i);
  33. literka += przesun;
  34. //System.out.print(literka);
  35. if ((literka > 64 && literka < 91) || (literka > 96 && literka <123))
  36. {
  37.  
  38. }
  39. else
  40. {
  41. literka -= 26;
  42. }
  43. s +=literka;
  44. }
  45. else
  46. {
  47. literka = nazwaWe.charAt(i);
  48. s +=literka;
  49. }
  50. //nazwaWe.charAt(i)=c;
  51.  
  52. }
  53. System.out.print("\n");
  54. System.out.print(s);
  55. plik.write(s + "\n");
  56. System.out.print("\n");
  57. nazwaWe = bufferedR.readLine();
  58. }
  59. plik.close();
  60. }
  61. catch(IOException ex)
  62. {
  63. System.out.println("BŁĄD ODCZYTU Z PLIKU!");
  64. ex.getStackTrace();
  65. }
  66. finally
  67. {
  68. if (fileR != null)
  69. fileR.close();
  70. }
  71. }
  72. static void deszyfruj(String nazwaWe, int przesun) throws Exception
  73. {
  74. FileReader fileR = new FileReader(nazwaWe);
  75. BufferedReader bufferedR = new BufferedReader(fileR);
  76. FileWriter plik = new FileWriter("_dane.txt");
  77. char literka;
  78. String s="";
  79. try
  80. {
  81.  
  82. while(nazwaWe != null)
  83. {
  84. s="";
  85. for (int i =0;i<nazwaWe.length();i++)
  86. {
  87.  
  88. if(nazwaWe.charAt(i) != ' ')
  89. {
  90. literka = nazwaWe.charAt(i);
  91. literka -= przesun;
  92. //System.out.print(literka);
  93. if ((literka > 64 && literka < 91) || (literka > 96 && literka <123))
  94. {
  95.  
  96. }
  97. else
  98. {
  99. literka += 26;
  100. }
  101. s +=literka;
  102. }
  103. else
  104. {
  105. literka = nazwaWe.charAt(i);
  106. s +=literka;
  107. }
  108. //nazwaWe.charAt(i)=c;
  109.  
  110. }
  111. System.out.print("\n");
  112. System.out.print(s);
  113. plik.write(s + "\n");
  114. System.out.print("\n");
  115. nazwaWe = bufferedR.readLine();
  116. }
  117. plik.close();
  118.  
  119. }
  120. catch(IOException ex)
  121. {
  122. System.out.println("BŁĄD ODCZYTU Z PLIKU!");
  123. ex.getStackTrace();
  124. }
  125. finally
  126. {
  127. if (fileR != null)
  128. fileR.close();
  129. }
  130. }
  131. /**
  132. * @param args the command line arguments
  133. */
  134. public static void main(String[] args) throws Exception {
  135. // TODO code application logic here
  136. szyfruj("dane.txt","dane1.txt",5);
  137. deszyfruj("dane1.txt",5);
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment