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

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?

UserRevisionLine numberNew contents of line
priyanshu_varshney 0:65a36a7b25d0 1 #include <iostream>
priyanshu_varshney 0:65a36a7b25d0 2
priyanshu_varshney 0:65a36a7b25d0 3 using namespace std;
priyanshu_varshney 0:65a36a7b25d0 4
priyanshu_varshney 0:65a36a7b25d0 5 string encryptDecrypt(string toEncrypt) {
priyanshu_varshney 0:65a36a7b25d0 6 char key[3] = {'K', 'C', 'Q'};
priyanshu_varshney 0:65a36a7b25d0 7 string output = toEncrypt;
priyanshu_varshney 0:65a36a7b25d0 8
priyanshu_varshney 0:65a36a7b25d0 9 for (int i = 0; i < toEncrypt.size(); i++)
priyanshu_varshney 0:65a36a7b25d0 10 output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
priyanshu_varshney 0:65a36a7b25d0 11
priyanshu_varshney 0:65a36a7b25d0 12 return output;
priyanshu_varshney 0:65a36a7b25d0 13 }
priyanshu_varshney 0:65a36a7b25d0 14 int main(int argc, const char * argv[])
priyanshu_varshney 0:65a36a7b25d0 15 {
priyanshu_varshney 0:65a36a7b25d0 16 string encrypted = encryptDecrypt("Priyanshu");
priyanshu_varshney 0:65a36a7b25d0 17 cout << "Encrypted:" << encrypted << "\n";
priyanshu_varshney 0:65a36a7b25d0 18
priyanshu_varshney 0:65a36a7b25d0 19 string decrypted = encryptDecrypt(encrypted);
priyanshu_varshney 0:65a36a7b25d0 20 cout << "Decrypted:" << decrypted << "\n";
priyanshu_varshney 0:65a36a7b25d0 21
priyanshu_varshney 0:65a36a7b25d0 22 return 0;
priyanshu_varshney 0:65a36a7b25d0 23 }