-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShift Encryption.java
More file actions
50 lines (44 loc) · 960 Bytes
/
Shift Encryption.java
File metadata and controls
50 lines (44 loc) · 960 Bytes
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
import java.util.Scanner;
class Main {
public static void main(String[] a) {
Scanner sc = new Scanner(System.in);
String m = sc.nextLine();
int x = sc.nextInt(), y = sc.nextInt();
StringBuilder e = new StringBuilder();
for (char c : m.toCharArray()) {
if (Character.isLowerCase(c)) {
if (c + x > 'z') {
e.append((char) (c + x - 26));
} else {
e.append((char) (c + x));
}
} else if (Character.isDigit(c)) {
int d = c - '0' + y;
e.append(d);
} else {
e.append(c);
}
}
System.out.println(e);
}
}
Example 1:
Input:
call me at 10 p.m
2
1
Output:
ecnn og cv 21 r.o
Example 2:
Input:
credit 1 lakh
3
Output:
fuhglw 1 odnk
Example 3:
Input:
interview rita at 4pm
1
6
Output:
joufswjfx sjub bu 10qn