Prvni odevzdani
This commit is contained in:
parent
e0beeeebb3
commit
52236ef522
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
Copyright (c) 2019-2021 xPablo.cz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
65
src/encString.cpp
Normal file
65
src/encString.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "encString.hpp"
|
||||
#include <WiFiConfig.h>
|
||||
#include <base64.h>
|
||||
#include <libb64/cdecode.h>
|
||||
|
||||
#if defined(ESP8266)
|
||||
# define ESP_getChipId() (ESP.getChipId())
|
||||
#else
|
||||
# include <esp_wifi.h>
|
||||
# define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
|
||||
#endif
|
||||
|
||||
void strEncode(String &str)
|
||||
{
|
||||
|
||||
const char *src = &str[0];
|
||||
uint8_t key[4];
|
||||
unsigned int enciphidx = 0;
|
||||
char c;
|
||||
unsigned int i;
|
||||
uint32_t cid = ESP_getChipId();
|
||||
uint32_t *pkey = (uint32_t *)&key[0];
|
||||
uint8_t data[str.length()];
|
||||
|
||||
*pkey = cid;
|
||||
for (i = 0; i < str.length(); i++) {
|
||||
c = src[i];
|
||||
c ^= key[enciphidx];
|
||||
++enciphidx;
|
||||
enciphidx %= sizeof(key);
|
||||
data[i] = c;
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
str = base64::encode(data, str.length(), false);
|
||||
#else
|
||||
str = base64::encode(data, str.length());
|
||||
#endif
|
||||
}
|
||||
|
||||
void strDecode(String &str)
|
||||
{
|
||||
|
||||
const char *src = &str[0];
|
||||
uint8_t key[4];
|
||||
unsigned int enciphidx = 0;
|
||||
unsigned int i;
|
||||
uint8_t b;
|
||||
uint32_t cid = ESP_getChipId();
|
||||
uint32_t *pkey = (uint32_t *)&key[0];
|
||||
uint8_t data[str.length()];
|
||||
unsigned int clen = base64_decode_chars(src, str.length(), (char *)data);
|
||||
String result = F("");
|
||||
|
||||
if (0 != clen) {
|
||||
*pkey = cid;
|
||||
for (i = 0; i < clen; i++) {
|
||||
b = data[i];
|
||||
b ^= key[enciphidx];
|
||||
++enciphidx;
|
||||
enciphidx %= sizeof(key);
|
||||
result.concat(char(b));
|
||||
}
|
||||
}
|
||||
str = result;
|
||||
}
|
9
src/encString.hpp
Normal file
9
src/encString.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _ENCSTRING_HPP_
|
||||
#define _ENCSTRING_HPP_
|
||||
#include <Arduino.h>
|
||||
|
||||
void strEncode(String &str);
|
||||
|
||||
void strDecode(String &str);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user