-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mutation.java
74 lines (45 loc) · 1.54 KB
/
Mutation.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cryptanalysis_gas;
import java.util.Random;
/**
*
* @author Abdullah_PC
*/
public class Mutation {
int key[][];
int x=0,y=0;
public Mutation(String Plain_Text[],int keys[][],int mution_ratio) {
key=new int[keys.length][keys[0].length];
Random rand=new Random();
int n1,n2;
for(int i=0;i<keys.length*mution_ratio/100;i++)
{
do{
x=1+rand.nextInt(keys[0].length);
y=1+rand.nextInt(keys[0].length);
}while (x==y);
System.out.println("Key("+i+1+") Two random Postions= "+x+" , "+y);
n1= keys[i][x-1];
n2= keys[i][y-1];
keys[i][x-1]=n2;
keys[i][y-1]=n1;
}
key=keys;
print(key);
}
public void print(int[][] keyss){
System.out.println();
System.out.println("Final Table of keyes(New Population)");
System.out.println("-------------------------------------");
for(int i=0;i<keyss.length;i++)
{
for(int j=0;j<keyss[i].length;j++)
System.out.print(" "+keyss[i][j]+" ");
System.out.println();
}
}
}