Last active
October 1, 2024 08:17
-
-
Save kakopappa/f2a97c449199217e20cc7af688611d80 to your computer and use it in GitHub Desktop.
How to Encrypt in Flutter and Decrypt in ESP8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Encrypt in Flutter | |
String encryptDecrypt(String input) { | |
var key = ['KCQ']; //Can be any chars, and any size array | |
var output = []; | |
for(var i = 0; i < input.length; i++) { | |
var charCode = input.codeUnitAt(i) ^ key[i % key.length].codeUnitAt(0); | |
output.add(new String.fromCharCode(charCode)); | |
} | |
return output.join(""); | |
} | |
Decrypt in ESP8266 | |
String request = ""; | |
char * key = "KCQ"; | |
char *p = const_cast<char*>(request.c_str()); | |
char *xor(char *string, const char *key) | |
{ | |
char *s = string; | |
size_t length = strlen(key), i = 0; | |
while (*s) { | |
*s++ ^= key[i++ % length]; | |
} | |
return string; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment