Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.PrintWriter;
  4. import java.util.Scanner;
  5.  
  6. public class Zadanie_4 {
  7.     public static void main(String[] args) throws FileNotFoundException {
  8.         // Import z plików
  9.         File tekstJawny = new File("tj.txt");
  10.         File klucze = new File("klucze1.txt");
  11.        
  12.         Scanner odczytTJ = new Scanner(tekstJawny);
  13.         Scanner odczytKlucze = new Scanner (klucze);
  14.        
  15.         PrintWriter odp_a = new PrintWriter("wynik4a.txt");
  16.  
  17.         for (int i = 0; i < 120; i++) {
  18.             String slowo = odczytTJ.nextLine();
  19.             String klucz = odczytKlucze.nextLine();
  20.            
  21.             StringBuilder word = new StringBuilder();
  22.            
  23.             char[] slowoChar = slowo.toCharArray();
  24.             char[] kluczChar = klucz.toCharArray();
  25.            
  26.             int[] slowoValue = new int[slowoChar.length];
  27.            
  28.             int x = 0;
  29.            
  30.             for (int j = 0; j < slowoChar.length; j++) {
  31.                 if ( x == kluczChar.length ) { x = 0; }            
  32.                     slowoValue[j] = (int)slowoChar[j] + (int)kluczChar[x] - 64;
  33.                 if ( slowoValue[j] > 90 ) { slowoValue[j] -= 26; }  
  34.                 x++;
  35.            
  36.                 slowoChar[j] = (char)slowoValue[j];
  37.                 word.append(slowoChar[j]);
  38.             }
  39.            
  40.             odp_a.println( word.toString() );
  41.         }
  42.        
  43.         odp_a.close();
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement