Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include "Base64.h"
  2. #include <AESLib.h>
  3. #include <ESP11.h>
  4.  
  5. ESP11 wifi = ESP11();
  6. char lorem[3005];
  7.  
  8. void serialSetup(){
  9.  
  10.   Serial.begin(115200);
  11.   Serial.println(F("READY, AES, delay-time-chunks, RECEIVER"));
  12.  
  13.   do {
  14.       delay(250);
  15.   }while(Serial.available() <= 0);
  16. }
  17.  
  18. void remove_padding(char* data, int len) {
  19.     //16 - length % 16
  20.     int done = 0;
  21.     while(!done){
  22.         len--;
  23.         if(data[len] == (char)0x80){
  24.             data[len] = '\0';  
  25.         }else {
  26.           done = 1;  
  27.         }
  28.     }
  29. }
  30.  
  31. void aes128dec(char data[]) {
  32.  
  33.     uint8_t key[] = "1234567890123456";
  34.     char* pointer = data;
  35.     int baselen = strlen(data);
  36.     for(int from = 0; from < baselen; from += 16) {
  37.         char dest[32];
  38.         strncpy(dest, pointer+from, 16);
  39.         aes128_dec_single(key, dest);
  40.         if((baselen-from) <= 16) {
  41.             remove_padding(dest, 16);
  42.         }
  43.         dest[16] = '\0';    
  44.         Serial.println(dest);
  45.  
  46.     }
  47. }
  48.  
  49. void setup() {
  50.  
  51.     serialSetup();
  52.     wifi.reset();  
  53.     wifi.stationMode();
  54.     wifi.connect(F("THESIS99"), "");
  55.     wifi.sendData("AT+CIPMUX=1",2000, "");
  56.     wifi.sendData("AT+CIPSERVER=1,80",2000, "OK");
  57.     wifi.sendData("AT+CIFSR",2000, "");
  58.     Serial.println("READY");
  59. }
  60.  
  61. void loop() {
  62.     String encodedStr = wifi.receivedata();
  63.     if(encodedStr.length() != 0){
  64.      
  65.         int decodedLen = base64_dec_len((char *)encodedStr.c_str(), encodedStr.length());
  66.         char data[decodedLen];
  67.        
  68.         base64_decode(data, (char*)encodedStr.c_str(), encodedStr.length());
  69.        // aes128dec(data);
  70.         wifi.flush();
  71.         Serial.println("Done");
  72. //        wifi.close();
  73.     }  
  74.     delay(250);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement