-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAffineEncrypt.java
More file actions
24 lines (21 loc) · 839 Bytes
/
AffineEncrypt.java
File metadata and controls
24 lines (21 loc) · 839 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
import java.util.Scanner;
import java.io.InputStreamReader;
public class AffineEncrypt {
public static void main(String[] args) {
Scanner scanner = new Scanner(new InputStreamReader(System.in));
System.out.println("Reading input from console using Scanner in Java ");
System.out.println("Please enter your text to encrypt:");
String input = scanner.nextLine();
System.out.println("Please enter encryption key a:");
int a = Integer.parseInt(scanner.nextLine());
System.out.println("Please enter encryption key b:");
int b = Integer.parseInt(scanner.nextLine());
int len = input.length();
char curr;
for (int i = 0; i < len; i++) {
curr = (char) ((a * (input.charAt(i) - 'a') + b) % 26 + 'a');
System.out.print(curr);
}
System.out.println();
}
}