-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCipher.java
56 lines (40 loc) · 1.49 KB
/
Cipher.java
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
import org.w3c.dom.Text;
import java.util.Scanner;
import jdk.tools.jlink.builder.ImageBuilder;
/*
Carmine Attanasio
3.28.21
Ceaser Cipher Encryptor/Decryptor
The objective of this program is to use the Ceaser Cipher
to encrypt and decrypt user input
*/
public class Cipher{
public static void main(String[] args)
{
Scanner userIn = new Scanner(System.in);
System.out.println("Please enter what you would like to encrypt");
String Input = userIn.nextLine();
System.out.println("Please enter a key for encryption");
int key=userIn.nextInt();
System.out.println("To be encrypted: " +Input);
System.out.println("Encrypting using key of: " + key);
System.out.println("-----------------------");
char[] inputConv = Input.toCharArray(); //converts input string to char array
//using input converted to string, char array is shifted x number to encrypt using ascii
System.out.println("Input Encrypted:");
for(char c : inputConv) //c is key for shifting
{
c += key;
System.out.print(c);
}
System.out.println();
System.out.println("-----------------------");
System.out.println("Input Decrypted:");
for(char c : inputConv)
{
c +=key;
c-=key;
System.out.print(c);
}
}
}