MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / ceaserCipherEncryption

Method ceaserCipherEncryption

Programs/CeaserCipher.java:28–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 }
27 }
28 public static void ceaserCipherEncryption() {
29 Scanner textInput = new Scanner(System.in);
30 System.out.print("PlainText: ");
31 String textToEncrypt = textInput.nextLine();
32 System.out.print("shifting key: ");
33 int keyToUse = textInput.nextInt();
34 String cipher = "";
35 for (int i = 0; true; i++) {
36 if (keyToUse > 50 && keyToUse <= 0) {
37 System.out.print("Please Enter key value <= 50: ");
38 keyToUse = textInput.nextInt();
39 } else {
40 for (int j = 0; j < textToEncrypt.length(); j++) {
41 char temp = textToEncrypt.charAt(j);
42 if (temp >= 'A' && temp <= 'Z') {
43 temp = (char) (temp + keyToUse);
44 if (temp > 'Z') { // go back to A in Ascii
45 temp = (char) (temp + 'A' - 'Z' - 1);
46
47 }
48 cipher += temp;
49 } else if (temp >= 'a' && temp <= 'z') {
50 temp = (char) (temp + keyToUse);
51 if (temp > 'z') { // go back to a in Ascii
52 temp = (char) (temp + 'a' - 'z' - 1);
53
54 }
55 cipher += temp;
56 } else
57 cipher += temp;
58
59 }
60 }
61 System.out.println("Enrypted text is: " + cipher);
62 break;
63
64 }
65 }
66
67
68 public static void ceaserCipherDecryption() {

Callers 1

mainMethod · 0.95

Calls 2

printMethod · 0.80
lengthMethod · 0.80

Tested by

no test coverage detected