Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class Zadanie_4 {
- public static void main(String[] args) throws FileNotFoundException {
- // Import z plików
- File tekstJawny = new File("tj.txt");
- File klucze = new File("klucze1.txt");
- Scanner odczytTJ = new Scanner(tekstJawny);
- Scanner odczytKlucze = new Scanner (klucze);
- PrintWriter odp_a = new PrintWriter("wynik4a.txt");
- for (int i = 0; i < 120; i++) {
- String slowo = odczytTJ.nextLine();
- String klucz = odczytKlucze.nextLine();
- StringBuilder word = new StringBuilder();
- char[] slowoChar = slowo.toCharArray();
- char[] kluczChar = klucz.toCharArray();
- int[] slowoValue = new int[slowoChar.length];
- int x = 0;
- for (int j = 0; j < slowoChar.length; j++) {
- if ( x == kluczChar.length ) { x = 0; }
- slowoValue[j] = (int)slowoChar[j] + (int)kluczChar[x] - 64;
- if ( slowoValue[j] > 90 ) { slowoValue[j] -= 26; }
- x++;
- slowoChar[j] = (char)slowoValue[j];
- word.append(slowoChar[j]);
- }
- odp_a.println( word.toString() );
- }
- odp_a.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement