A very simple C + + module to encrypt/decrypt strings based on B64 and Vigenere Ciper.

Source: Internet
Author: User
Tags base64 decrypt wrapper

A very simple C + + module to encrypt/decrypt strings based on B64 and Vigenere Ciper.

Https://github.com/philipperemy/easy-encryption

Easy encryption

A very simple yet powerful standalone C + + module (API) to encrypt/decrypt strings based on B64 and Vigenere Ciper (symmetr IC cipher).

It works as follows:

    • Alice encodes in base64 the message and then uses the Vigenere private key to encrypt the message.
    • The encrypted message is sent through an unsecured channel.
    • Bob gets the message and decrypts it with the Vigenere private key. He then decodes it with Base64.

Diagram Summary:

Message, B64 ENCODE, Vigenere ENCRYPT, encrypted message, Vigenere DECRYPT, B64 DECODE Age

The system is safe and unbreakable because:

  • Vigenere cipher is vulnerable to bruteforce attacks with dictionaries. Our system encodes first the string in base64. All frequencies and other attacks is void.
  • A very large key is used for the Vigenere encryption. We strongly encourage the key to being larger than any message to being sent. The reason is this vigenere is almost uncrackable if the cipher key was extremely long compared to the average message Leng Th.
  • The reason why we apply b64 encode before Vigenere is because it's very easy for somebody to apply a b64 decode and see AB Out the structure of the message. For example, if we send {"hello":123} , an attacker can sniff the message, b64 decode the message and get {"qsggn":ygf} . Of course the attacker still needs the Vigenere cipher key, but at least, he can get a pretty clear idea that JSON format Messages is sent in the communication channel. The "the" to avoid-encode first in b64 then encrypt it with the Vigenere key. If the attacker tries to b64 decode first, it'll see a random string of weird characters.
Apic++
    • Encrypt message
std::string encrypt(std::string& msg, std::string& key)
    • Decrypt message
std::string decrypt(std::string& encrypted_msg, std::string& key)
Python
    • Encrypt message
wrapper.encrypt(message, key): returns encrypted message
    • Decrypt message
wrapper.decrypt(encrypted_message, key): returns decrypted message
Compilation and execution
g++ cl.cpp./a.out "Hello world" MYPRIVATEKEY 0

The encrypted message is: ttz9JqxZHBClNtu= .

./a.out ttz9JqxZHBClNtu= MYPRIVATEKEY 1

The decrypted message is Hello world .

Python Wrapper
rm a.outg++ cl.cpppython3 wrapper.py
example-encoding/decoding JSON Formatsource Code
#include <stdio.h>#include <string.h>#include <string>#include <iostream>#include <stdio.h>#include <ctype.h>#include "encrypt.h"using namespace std;int main() { // std::string msg = "HELLO WORLD"; std::string msg = "{\"id\":1,\"method\":\"service.subscribe\",\"params\":[\"myapp/0.1c\", null,\"0.0.0.0\",\"80\"]}"; std::string key = "THISISMYKEY"; std::cout << "  message to send: " << msg << std::endl; std::string encrypted_msg = encrypt(msg, key); std::cout << "encrypted message: " << encrypted_msg << std::endl; std::string decrypted_msg = decrypt(encrypted_msg, key); std::cout << "decrypted message: " << decrypted_msg << std::endl;    return 0;}
Output
  message to send: {"id":1,"method":"service.subscribe","params":["myapp/0.1c", null,"0.0.0.0","80"]}encrypted message: X5g7wjjTllj1ItCxShWUb77PKJsfP VNMAB7VtqaLCccGTr0ijkjxqw0IutQvXfSFK4OKo8cnpD1Lge0pdMCZf0fqQ8bjjFjkNn1h pBtdwNJD==decrypted message: {"id":1,"method":"service.subscribe","params":["myapp/0.1c", null,"0.0.0.0","80"]}

A very simple C + + module to encrypt/decrypt strings based on B64 and Vigenere Ciper.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.