-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAffineDecrypt.java
More file actions
48 lines (39 loc) · 1.08 KB
/
AffineDecrypt.java
File metadata and controls
48 lines (39 loc) · 1.08 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
43
44
45
46
47
48
import java.util.Scanner;
import java.io.InputStreamReader;
public class AffineDecrypt {
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 input: ");
String input = scanner.nextLine();
int len = input.length();
int[] aVals = new int[] {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
int flag;
int a;
int aInv = 0;
for(int i = 0; i < 12; i++)
{
a = aVals[i];
for(int j = 0; j < 26; j++)
{
flag = (a * j) % 26;
if(flag == 1)
{
aInv = j;
break;
}
}
// find inverse of a value
for(int b = 0; b < 26; b++)
{
for(int m = 0; m < len; m++)
{
char curr = (char)(((aInv * (input.charAt(m) - 'a' - b + 26)) % 26) + 'a');
System.out.print(curr);
}
System.out.println();
}
}
}
}