Skip to content

Commit 8dd593b

Browse files
committed
tessting
1 parent 43ffb32 commit 8dd593b

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

ECC/Decoder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public String decode(Matrix A) {
3737

3838
private String getPlainText(Matrix A) {
3939
String plaintText = "";
40+
System.out.println("4) Convert the matrix M to a list of points");
41+
A.toPoints().stream().forEach(System.out::print);
42+
System.out.println("");
43+
4044
for (Point p : A.toPoints()) {
4145
if (pointTable.get(p) != null) {
4246
int asciCode = pointTable.get(p);

ECC/ECC.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ private int[] encrypt(String msg, PublicKey key) {
3939

4040
Point keyHint = c.multiply(g, k); // key to send
4141

42-
System.out.println("----------------- Encrypt -----------------");
43-
System.out.println("Msg to encrypt : " + msg);
44-
System.out.println("Bob public key : " + publicKey);
45-
System.out.println("Alice private key : " + k);
46-
System.out.println("sharedSecret : " + sharedSecret);
47-
48-
System.out.println("keyHint : " + keyHint);
42+
System.out.println("----------------- Encryption process -----------------");
43+
System.out.println(c);
44+
System.out.println("Mesage to encrypt, m = " + msg);
45+
System.out.println("Bob's public key, Pb = " + publicKey);
46+
System.out.println("Alice's private key, k = " + k);
47+
System.out.println("The ecryption key, sharedSecret = k * Pb = " + sharedSecret);
48+
System.out.println("The hint to compute sharedSecret for bob, keyHint = " + keyHint);
49+
4950
Matrix mMatrix = mEncoder.encode(msg);
5051
mMatrix.performAddition(Helpers.toBinary(sharedSecret));
51-
System.out.println("sharedSecret bit format :");
52+
System.out.println("sharedSecret binary format :");
5253
Helpers.print(Helpers.toBinary(sharedSecret));
53-
System.out.println("encrypted matrix (code addition) :");
54+
System.out.println("4) encrypt the matrix with sharedSecret (code addition)");
5455
System.out.println(mMatrix);
5556
return mMatrix.toArray(Helpers.toBinary(keyHint));
5657
}
@@ -64,18 +65,23 @@ private String decrypt(int[] cipherText, PrivateKey key) {
6465
Point keyHint = Point.make(cipherText);
6566
Point sharedSecret = c.multiply(keyHint, privateKey);
6667

67-
System.out.println("decrypt cipher :");
68+
System.out.println("\n----------------- Decryption process -----------------");
69+
System.out.println("1) Bob receive this :");
6870
Helpers.print(cipherText);
71+
System.out.println("");
72+
System.out.println("2) Extract keyhint and the matrix C");
73+
System.out.println("KeyHint = "+keyHint);
6974

7075
//get the decypted matrix
7176
Matrix mMatrix = Matrix.make(cipherText);
72-
System.out.println("Matrix before substraction");
77+
System.out.println("C = ");
7378
System.out.println(mMatrix);
7479
//substract the key form the matrix
7580
mMatrix.performSubstraction(Helpers.toBinary(sharedSecret));
7681
System.out.println("Matrix after substraction");
7782
System.out.println(mMatrix);
7883
//decode the matrix
84+
System.out.println("3) Reverse Matrix Scrambling");
7985
return mDecoder.decode(mMatrix);
8086
}
8187

@@ -135,16 +141,18 @@ public static void main(String[] args) {
135141
EllipticCurve c = new EllipticCurve(4, 20, 29, new Point(1, 5));
136142
ECC ecc = new ECC(c);
137143
ecc.displayCodeTable();
138-
System.out.println(c);
139144
String msg = "i understood the importance in principle of public key cryptography, but it is all moved much faster than i expected i did not expect it to be a mainstay of advanced communications technology";
140145
msg = "hi there";
141146
// generate pair of keys
142147
KeyPair keys = generateKeyPair(c);
143148
// encrypt the msg
144149
int[] cipherText = ecc.encrypt(msg, keys.getPublicKey());
150+
System.out.println("5) Alice send this to Bob:");
151+
Helpers.print(cipherText);
145152

146153
// decrypt the result
147154
String plainText = ecc.decrypt(cipherText, keys.getPrivateKey());
155+
System.out.println("\n5) Translate each point to a carracter");
148156

149157
//System.out.println("Cipher : ");
150158
//Helpers.print(cipherText);

ECC/EllipticCurve.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static void main(String[] args) {
160160

161161
@Override
162162
public String toString() {
163-
return "(EC) " + "y^2 = x^3 + " + a + "x + " + b + "c mod " + p + "\n G = " + basePoint + '}';
163+
return "EllipticCurve EC : " + "y^2 = x^3 + " + a + "x + " + b + "c mod " + p + "\nGenerator point G = " + basePoint + '}';
164164
}
165165

166166
}

ECC/Encoder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public Encoder(HashMap<Integer, Point> charTable) {
1616

1717
public Matrix encode(String plainText) {
1818
Matrix mMatrix = createMatrix(plainText);
19-
System.out.println("Matrix before scrambling : ");
19+
System.out.println("\n2) Convert the list of points to a binary Matrix");
2020
System.out.println(mMatrix);
21+
System.out.println("\n3) Matrix Scrambling");
2122
int w = new BigInteger(ECC.PAD, ECC.getRandom()).intValue();
2223
int[] bits = Helpers.toBinary(ECC.getRandom().nextInt(1024), ECC.PAD * 2);
23-
System.out.println("w : " + w + " Bits :");
24+
System.out.println("number of transformations, w = " + w);
25+
System.out.println("Random sequence of bits, Bits = ");
2426
Helpers.print(bits);
2527
int bit, i = 0;
2628
do {
@@ -35,7 +37,7 @@ public Matrix encode(String plainText) {
3537
}else{
3638
i++;
3739
}
38-
System.out.println("scrambling...");
40+
//System.out.println("scrambling...");
3941
System.out.println(mMatrix);
4042
w--;
4143
} while (w > 0);
@@ -48,7 +50,7 @@ private Matrix createMatrix(String plainText) {
4850
Point p = charTable.get((int) c.charValue());
4951
pList.add(p);
5052
}
51-
System.out.print("List of Points : ");
53+
System.out.println("\n1) Convert m to a list of Points");
5254
pList.stream().forEach(System.out::print);
5355
System.out.println("");
5456
List<Integer> bList = new ArrayList<>();

0 commit comments

Comments
 (0)