Advertisement
Guest User

faf

a guest
Sep 22nd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Vigchiff {
  7.  
  8.  
  9. public static void main(String[] args) {
  10. menu();
  11. }
  12.  
  13. private static void menu(){
  14. int a;
  15. Scanner scan = new Scanner(System.in);
  16. System.out.println("1: Chiffrera");
  17. System.out.println("2: Dechiffrera");
  18. System.out.println("0: Exit");
  19. System.out.println("Choose Option..");
  20.  
  21. a = scan.nextInt();
  22.  
  23. if(a == 0){
  24. System.out.println("Exiting..");
  25. System.exit(0);
  26. }
  27. if(a == 1){
  28. System.out.println("Ange meddelande");
  29. String msg = readLine();
  30.  
  31. System.out.println("Ange nyckel");
  32. String key = readLine();
  33.  
  34. System.out.println("Chiffrerad text: " + Encrypt(msg, key));
  35.  
  36.  
  37. }
  38. if(a == 2){
  39.  
  40. }
  41. else{
  42. System.out.println("Wrong choice, choose between 0-2");
  43. menu();
  44. }
  45. }
  46.  
  47. private static String Encrypt(String msg, String key){
  48. ArrayList<Integer> list = new ArrayList<Integer>();
  49. String result;
  50. StringBuilder sb = new StringBuilder();
  51.  
  52. for(int i = 0; i < msg.length(); i++){
  53. int x = (int) msg.charAt(i);
  54. int y = i+1;
  55. int z = 0;
  56. if(y > key.length() ){
  57. y = i%key.length();
  58. } else {
  59. z = (int) key.charAt(y-1) + x;
  60. if(z >)
  61.  
  62.  
  63. list.add(z);
  64. }
  65. }
  66.  
  67. for(int i = 0; i<list.size(); i++){
  68. sb.append( (char) list.get(i).intValue());
  69. }
  70. result = sb.toString();
  71. return result;
  72. }
  73.  
  74. private String Decrypt(String key){
  75. String result = new String();
  76. return result;
  77. }
  78.  
  79. private static String readLine(){
  80. Scanner s = new Scanner(System.in);
  81. String msg = s.nextLine();
  82. return msg;
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement