-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCiphers.java
More file actions
36 lines (32 loc) · 1.1 KB
/
Ciphers.java
File metadata and controls
36 lines (32 loc) · 1.1 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
import java.io.*;
import java.util.Arrays;
import java.lang.*;
public class Ciphers {
public static void main(String[] args){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] alphabet = new char[]{'a', 'b','c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
try
{
System.out.print("Enter text to encode: ");
String plainText = br.readLine();
for (int i = 0; i < plainText.length(); i++){
char c = plainText.charAt(i);
if (c != ' ')
{
int p = Arrays.binarySearch(alphabet, c);
char x = alphabet[(p+3) % 26];
plainText = plainText.replace(c, x);
}
else
{
plainText = plainText.replace(' ', ' ');
}
}
String cipherText = plainText;
System.out.println("Encrypted text: " + cipherText);
}
catch (IOException e)
{
}
}
}