-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.java
More file actions
93 lines (87 loc) · 2.01 KB
/
Copy pathEncryption.java
File metadata and controls
93 lines (87 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.*;
public class Encryption
{
public static int shift = 6;
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);
int c =0;
do
{
System.out.print("Encrypt or Decrypt: ");
String a = keyboard.nextLine();
if(a.equalsIgnoreCase("encrypt"))
{
System.out.println("Running encryption");
encryption();
System.out.println();
}
else if(a.equalsIgnoreCase("decrypt"))
{
System.out.println("Running Decryption");
decryption();
}
else
{
System.out.println("NO");
c++;
}
}
while(c == 0);
}
public static void encryption()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your message: ");
String origin = keyboard.nextLine();
//orgin = the original message
//was tring to make the screen move down
/*for(int c = 0; c < x + 20; c++)
System.out.println();*/
String changed = rotationCipher(origin);
//changed = rotationCipher(changed);
System.out.println("Encrypted message = " + changed);
}
public static void decryption()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your message: ");
String origin = keyboard.nextLine();
int x = origin.length();
String product = "";
//decrypts the rotation cipher
for(int c = 0; c < x; c++)
{
char a = origin.charAt(c);
int b = (int)a;
b -= shift;
product += (char)b;
}
System.out.println("Decrypted message = " + product);
}
public static String rotationCipher(String origin)
{
//this for loop is a rotation cipher
String product = "";
int x = origin.length();
for(int c = 0; c < x; c++)
{
char a = origin.charAt(c);
int b = (int)a; //int casting
b += shift;
product += (char)b;
}
return product;
}
/*public static String swapLetter(String origin)
{
int x = origin.length();
String product = "";
for(int c = 0; c >= 0; c--) {
char a1 = origin.charAt(x);
product = a1 + product;
}
return product;
}
public static String unSwapLetter(String origin) {*/
}