Since things didn't work out between me and mbedtls, here are the basic encryption algorithms.

## guide.txt@0:65a36a7b25d0, 7 months ago (annotated)

- Committer:
- priyanshu_varshney
- Date:
- Sat Nov 10 20:11:01 2018 +0000
- Revision:
- 0:65a36a7b25d0

Simple encryption algorithms apart from mbedtls(not working)

### Who changed what in which revision?

User | Revision | Line number | New contents of line |
---|---|---|---|

priyanshu_varshney | 0:65a36a7b25d0 | 1 | >>>> Xor Encryption |

priyanshu_varshney | 0:65a36a7b25d0 | 2 | XOR encryption (or Exclusive-OR encryption) is a common method of encrypting text into a format that cannot be trivially cracked by the average person. XOR encryption is great for storing things like game save data, and other data types that are stored locally on a users computer, that while not a big deal if they are tampered with, you would like to deter people from doing so. XOR encryption is also used often as a part of more complex encryption algorithms. |

priyanshu_varshney | 0:65a36a7b25d0 | 3 | |

priyanshu_varshney | 0:65a36a7b25d0 | 4 | The idea behind it is that if you don't know the original character or the XOR encryption key, it is impossible to determine what either one is. However, the reason that it is not entirely secure is that data almost always contains patterns (JSON uses '{' and '}' characters, XML contains plenty of '<' and '>' characters, etc.) so if someone is able to determine the pattern and unlock even one character, they will have the key to unlocking everything else. |

priyanshu_varshney | 0:65a36a7b25d0 | 5 | |

priyanshu_varshney | 0:65a36a7b25d0 | 6 | However secure or insecure XOR encryption really is, it has plenty of valid use cases. Any kind of deterrent added to data that you don't want users to tamper with but that they will have easy access to is a prime candidate, so long as security isn't paramount. |

priyanshu_varshney | 0:65a36a7b25d0 | 7 | |

priyanshu_varshney | 0:65a36a7b25d0 | 8 | The concept is simple, you define a key character, and for every character in the string you want to encrypt, you apply the key. Once you want to unencrypt the encrypted data, you simply go through the string and apply the key again. |

priyanshu_varshney | 0:65a36a7b25d0 | 9 | |

priyanshu_varshney | 0:65a36a7b25d0 | 10 | --------------------------------------------- |

priyanshu_varshney | 0:65a36a7b25d0 | 11 | >>>> RSA ENCRYPTION |

priyanshu_varshney | 0:65a36a7b25d0 | 12 | |

priyanshu_varshney | 0:65a36a7b25d0 | 13 | >> Generating Public Key : |

priyanshu_varshney | 0:65a36a7b25d0 | 14 | Select two prime no's. Suppose P = 53 and Q = 59. |

priyanshu_varshney | 0:65a36a7b25d0 | 15 | Now First part of the Public key : n = P*Q = 3127. |

priyanshu_varshney | 0:65a36a7b25d0 | 16 | |

priyanshu_varshney | 0:65a36a7b25d0 | 17 | We also need a small exponent say e : |

priyanshu_varshney | 0:65a36a7b25d0 | 18 | But e Must be |

priyanshu_varshney | 0:65a36a7b25d0 | 19 | |

priyanshu_varshney | 0:65a36a7b25d0 | 20 | An integer. |

priyanshu_varshney | 0:65a36a7b25d0 | 21 | |

priyanshu_varshney | 0:65a36a7b25d0 | 22 | Not be a factor of n. |

priyanshu_varshney | 0:65a36a7b25d0 | 23 | |

priyanshu_varshney | 0:65a36a7b25d0 | 24 | 1 < e < Φ(n) [Φ(n) is discussed below], |

priyanshu_varshney | 0:65a36a7b25d0 | 25 | Let us now consider it to be equal to 3. |

priyanshu_varshney | 0:65a36a7b25d0 | 26 | Our Public Key is made of n and e |

priyanshu_varshney | 0:65a36a7b25d0 | 27 | |

priyanshu_varshney | 0:65a36a7b25d0 | 28 | >> Generating Private Key : |

priyanshu_varshney | 0:65a36a7b25d0 | 29 | |

priyanshu_varshney | 0:65a36a7b25d0 | 30 | We need to calculate Φ(n) : |

priyanshu_varshney | 0:65a36a7b25d0 | 31 | Such that Φ(n) = (P-1)(Q-1) |

priyanshu_varshney | 0:65a36a7b25d0 | 32 | so, Φ(n) = 3016 |

priyanshu_varshney | 0:65a36a7b25d0 | 33 | |

priyanshu_varshney | 0:65a36a7b25d0 | 34 | |

priyanshu_varshney | 0:65a36a7b25d0 | 35 | Now calculate Private Key, d : |

priyanshu_varshney | 0:65a36a7b25d0 | 36 | d = (k*Φ(n) + 1) / e for some integer k |

priyanshu_varshney | 0:65a36a7b25d0 | 37 | For k = 2, value of d is 2011. |

priyanshu_varshney | 0:65a36a7b25d0 | 38 | Now we are ready with our – Public Key ( n = 3127 and e = 3) and Private Key(d = 2011) |

priyanshu_varshney | 0:65a36a7b25d0 | 39 | >> Example |

priyanshu_varshney | 0:65a36a7b25d0 | 40 | Now we will encrypt “HI” : |

priyanshu_varshney | 0:65a36a7b25d0 | 41 | |

priyanshu_varshney | 0:65a36a7b25d0 | 42 | Convert letters to numbers : H = 8 and I = 9 |

priyanshu_varshney | 0:65a36a7b25d0 | 43 | |

priyanshu_varshney | 0:65a36a7b25d0 | 44 | |

priyanshu_varshney | 0:65a36a7b25d0 | 45 | Thus Encrypted Data c = 89e mod n. |

priyanshu_varshney | 0:65a36a7b25d0 | 46 | Thus our Encrypted Data comes out to be 1394 |

priyanshu_varshney | 0:65a36a7b25d0 | 47 | |

priyanshu_varshney | 0:65a36a7b25d0 | 48 | |

priyanshu_varshney | 0:65a36a7b25d0 | 49 | Now we will decrypt 1394 : |

priyanshu_varshney | 0:65a36a7b25d0 | 50 | |

priyanshu_varshney | 0:65a36a7b25d0 | 51 | Decrypted Data = cd mod n. |

priyanshu_varshney | 0:65a36a7b25d0 | 52 | Thus our Encrypted Data comes out to be 89 |

priyanshu_varshney | 0:65a36a7b25d0 | 53 | |

priyanshu_varshney | 0:65a36a7b25d0 | 54 | 8 = H and I = 9 i.e. "HI". |