CryptographywithLB103
edited
... When we look at our coding table we obtain the following text message:
M E E T _M E_ AT_ P A …
...
When we look at our coding table we obtain the following text message:
M E E T _M E_ AT_ P A R I S_ C D G_ T E R M I N A L_ T W O_ O N_ O C T_ N I N E_ A T_ N O O N
CONCLUSION
Obviously when you use small primes and obtain a modulus of 33 we are doing a 6 bit RSA encryption which is effectively a simple substition cipher which
goes back in history to the Ceaser's age, so simple substition ciphers are called Ceaser's Ciphers and these are easily breakable with Frequency Analysis.
All of those super XOR 'unbreakable' ciphers are substitution ciphers and obviously they are very easily breakable.
Therefore, we have to have a key size of 2048 bits and above as of 2017 for a secure RSA encryption implementation. We only gave the small primes
example to make the idea easily illustrated. You can even test this with an EXCEL worksheet. The aritmetic is the same regardless of the size of prime
numbers. Formula is the same and even with high school mathematics knowledge you can understand RSA.
However, you can try much larger prime numbers with the following Liberty Basic example for about up to 128 bits modulus sizes for reasonable computational
times with Liberty Basic. If you want to use keys sizes such as 1024 or 2048 bits, you must call an external DLL such as OpenSSL.
On the other hand, even 128 bit RSA with Liberty Basic is pretty good for casual encryption purposes. Liberty Basic has an undocumented feature for
making huge integer arithmetic which is not possible with other programming languages. It was possible to make this RSA demonstration with Liberty Basic
due to this unusual capability.
Remember, with RSA the block of data you are encrypting must be the same size with the modulus bit size, For example for a modulus size of 128 bits,
the block size must be 128 bits or 16 bytes. If the data you are encrypting is less than the modulus size, you must pad your data block with a random
number after a delimiter to make it equal to modulus size. 2048 bits will be 256 bytes data blocks. Please, note that you can do 2048 bits RSA encryption
with exponent 3 using Liberty Basic but it will be too slow to decrypt 2048 bits blocks with native Liberty Basic.
One of the challenges of the RSA algorithm is the TRUST CHAIN. How will you trust somebody on Internet who sends his Public Key to you and invite
you to use this to send him/her encrypted messages such as trusting a web site who ask you to send your credit card number using an allegedly secure
public key?
This is the reason for the need for CA Certificate Authorities. CAs act like Notaries by signing Public Keys of individuals and companies so that we
can trust those public keys. These are called Public Key Certificates which are effectively Encrypted Public Keys which are enciphered with the
Secret Root Key of the CA. So, instead of Plain Public Key of an individual or company we request a Certificate signed by a trusted CA which can be
company wide internal CA or globally accepted CA like VeriSign, Comodo, Thawte, etc. Assuming that we have the Public Keys of the trusted CA
we can decrypt CA CERTIFICATE using the CA PUBLIC KEY and we can recover the PUBLIC KEY of the party we are going to send a secret
message. Arithmetic is the same. However, for this tutorial there is no need to make it more complicated with CA CERTIFICATES. Once the basics
are understood, it is not hard to make this extension.
Demonstration Program in Liberty Basic
dim stats(11)
CryptographywithLB103
edited
... Bob sends the following message to Alice:
SZZNYSZYANYDAXC,Y. MYNZXSCEALYNWIYIEYI.NYECEZYANYEI…
...
Bob sends the following message to Alice:
SZZNYSZYANYDAXC,Y. MYNZXSCEALYNWIYIEYI.NYECEZYANYEIIE
Eve intercepts
SZZNYSZYANYDAXC,Y.SZZNYSZYANYDAXC,Y. MYNZXSCEALYNWIYIEYI.NYECEZYANYEIIE but she can not
make any sense out of this garbled text because she does not have the secret key.
Alice converts this message according to above coding table:
19 26 26 14 25 19 26 25 01 14 25 04 01 24 03 28 25 27 31 13 25 14 26 24 19 03 05 01 12 25 14 23 09 25 09 05 25 09 27 14 25 05 03 05 26 25 01 14 25 05 09 09 05
...
a = c 7 mod 33
like
...
mod 33
893871739= 893871739 mod 33
13= 13 which corresponds
When we calculate all the numbers in the above message we will get:
13 05 05 20 31 13 05 31 01 20 31 16 01 18 09 19 31 03 04 07 31 20 05 18 13 09 14 01 12 31 20 23 15 31 15 14 31 15 03 20 31 14 09 14 05 31 01 20 31 14 15 15 14
CryptographywithLB103
edited
... decryption formula:
a = c d mod n
Simple RSA Example with Small Primes
Let's choose two sm…
...
decryption formula:
a = c d mod n
Simple RSA Example with Small Primes
Let's choose two small primes p=3 and q=11
Therefore, n = p . q = 3 x 11 = 33, the common modulus n=33.
Next, let's find the Euler-Totient number t=(p-1)(q-1)=(3-1)(11-1)=20.
We now choose the smallest possible odd prime number 3 as e and therefore
Alice's public key is (3,33) and Alice sends this to Bob with WhatsApp as
a different channel where both Alice and Bob trusts.
Alice than sets out the find d from e.d = 1 mod t equality and asks the
question which d multiplied by 3 and divided by 20 gives a remainder of 1?
This is not very hard to find, 3 x 7 = 21 and 21 divided by 20 gives a
remainder of 1.
Therefore, Alice's secret key is ( 7, 33 ) and she keeps this private
only to be used by Alice to decipher secret message coming to her with
her Public Key ( 3,33 )
Alice sends Bob a suggested coding table as follows with WhatsApp.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z . , ? ! _ ( )
Bob sends the following message to Alice:
SZZNYSZYANYDAXC,Y. MYNZXSCEALYNWIYIEYI.NYECEZYANYEIIE
Eve intercepts
SZZNYSZYANYDAXC,Y. MYNZXSCEALYNWIYIEYI.NYECEZYANYEIIE
Alice converts this message according to above coding table:
19 26 26 14 25 19 26 25 01 14 25 04 01 24 03 28 25 27 31 13 25 14 26 24 19 03 05 01 12 25 14 23 09 25 09 05 25 09 27 14 25 05 03 05 26 25 01 14 25 05 09 09 05
Finally Alice deciphers each number with her secret key (7,33) using the formula :
a = c 7 mod 33
like
a = 19 7 mod 33
893871739 mod 33
13 which corresponds to letter M
When we calculate all the numbers in the above message we will get:
13 05 05 20 31 13 05 31 01 20 31 16 01 18 09 19 31 03 04 07 31 20 05 18 13 09 14 01 12 31 20 23 15 31 15 14 31 15 03 20 31 14 09 14 05 31 01 20 31 14 15 15 14
When we look at our coding table we obtain the following text message:
M E E T M E A T P A R I S C D G T E R M I N A L T W O O N O C T N I N E A T N O O N
Demonstration Program in Liberty Basic
dim stats(11)