Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Vigchiff {
- public static void main(String[] args) {
- menu();
- }
- private static void menu(){
- int a;
- Scanner scan = new Scanner(System.in);
- System.out.println("1: Chiffrera");
- System.out.println("2: Dechiffrera");
- System.out.println("0: Exit");
- System.out.println("Choose Option..");
- a = scan.nextInt();
- if(a == 0){
- System.out.println("Exiting..");
- System.exit(0);
- }
- if(a == 1){
- System.out.println("Ange meddelande");
- String msg = readLine();
- System.out.println("Ange nyckel");
- String key = readLine();
- System.out.println("Chiffrerad text: " + Encrypt(msg, key));
- }
- if(a == 2){
- }
- else{
- System.out.println("Wrong choice, choose between 0-2");
- menu();
- }
- }
- private static String Encrypt(String msg, String key){
- ArrayList<Integer> list = new ArrayList<Integer>();
- String result;
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < msg.length(); i++){
- int x = (int) msg.charAt(i);
- int y = i+1;
- int z = 0;
- if(y > key.length() ){
- y = i%key.length();
- } else {
- z = (int) key.charAt(y-1) + x;
- if(z >)
- list.add(z);
- }
- }
- for(int i = 0; i<list.size(); i++){
- sb.append( (char) list.get(i).intValue());
- }
- result = sb.toString();
- return result;
- }
- private String Decrypt(String key){
- String result = new String();
- return result;
- }
- private static String readLine(){
- Scanner s = new Scanner(System.in);
- String msg = s.nextLine();
- return msg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement