@@ -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 ("\n 5) Translate each point to a carracter" );
148156
149157 //System.out.println("Cipher : ");
150158 //Helpers.print(cipherText);
0 commit comments