forked from adityabiswal2147207/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.java
More file actions
42 lines (31 loc) · 1.13 KB
/
Copy pathconvert.java
File metadata and controls
42 lines (31 loc) · 1.13 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
import java.util.*;
import javax.print.DocFlavor.STRING;
import java.io.*;
class Conversion{
public static final String alpha = "abcdefghijklmnopqrstuvwxyz";
//making the encryption function-->
public String encrypt(String message, int shiftkey){
message = message.toLowerCase(); //making all the string to lowercase
String ciphertext = "";
for(int i=0;i<message.length();i++){
int charPosition = alpha.indexOf(message.charAt(i));
int keyVal = (shiftkey + charPosition) % 26;
char varReplace = alpha.charAt(keyVal);
ciphertext += varReplace;
}
return ciphertext;
}
}
public class Convert {
public static void main(String[] args){
Conversion obj = new Conversion();
Scanner sc = new Scanner(System.in);
String message = new String();
int key = 0;
System.out.print("Enter your password: ");
message = sc.next();
System.out.print("Enter shiftkey for encryption process: ");
key = sc.nextInt();
System.out.println("Encryted key : "+obj.encrypt(message,key));
}
}