को संयोजित करते समय क्रैश और त्रुटियां मैं स्ट्रिंग में एईएस -256 एन्क्रिप्शन के आउटपुट को जोड़ने की कोशिश करता हूं (एंड्रॉइड फोन से भेजे गए एन्क्रिप्टेड स्ट्रिंग के खिलाफ इस स्ट्रिंग की तुलना करने के लिए)।Arduino: स्ट्रिंग्स
असल में, संगतता काम करने लगती है, लेकिन कुछ रन त्रुटियों के बाद (गैर पठनीय वर्ण, स्ट्रिंग लंबे समय के बजाय कम हो रही है) या दुर्घटनाएं होती हैं। यह पुन: उत्पन्न करने के बाद सटीक उसी बिंदु पर पुन: उत्पन्न होता है।
मैंने समस्या का प्रदर्शन करने वाले Arduino कोड की कुछ पंक्तियां निकालीं।
- एक यादृच्छिक संख्या बनाएँ और यह एक सरणी में लिखना (काम)
- AES- एनकोड इस सरणी (काम)
- प्रत्येक सरणी सूचकांक के एक हेक्स प्रतिनिधित्व बिल्ड (काम) : यह निम्नलिखित करता है
- एक स्ट्रिंग के लिए सूचकांक CONCATENATE (दुर्घटनाओं)
#include <SPI.h>
#include "aes256.h" //include this lib
uint8_t key[] = {9,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,
1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8 }; //the encryption key
aes256_context ctxt; //context needed for aes library
void setup() {
Serial.begin(9600);
}
void loop() {
uint8_t data[] = {
0x53, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66,
0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x65, }; //the message to be encoded
long InitialRandom = random(2147483647); //0 to highest possible long
String RandomString = "" ;
RandomString+=InitialRandom; //random number to String
Serial.println(RandomString); //for debugging
//update data array: Random String into data array
for (int x=0; x<RandomString.length(); x++){
data[x] = RandomString[x];
}
//this encrypts data array, which changes
aes256_init(&ctxt, key); //initialize the lib
aes256_encrypt_ecb(&ctxt, data); //do the encryption
aes256_done(&ctxt);
//Here the problem starts.............................................
String encrypted=""; //the string I need finally
for (int x=0; x<sizeof(data); x++){ //data array is 16 in size
int a = data[x];
String b = String (a, HEX);
if(b.length()==1) b="0"+b; //if result is e.g "a" it should be "0a"
encrypted.concat(b); //this line causes the problem!!!
//Serial.println(b); //works perfect if above line commented out
Serial.println(encrypted); //see the string geting longer until problems occur
}
//Here the problem ends.............................................
Serial.println(); //go for next round, until crashing
}
मैंने मंचों की खोज की है, (+ ऑपरेटर, स्ट्रैट) को जोड़ने के विभिन्न तरीकों का प्रयास किया है। सभी के समान प्रभाव थे। मैंने पढ़ा कि स्ट्रिंग लाइब्रेरी में एक बग था, 1.0 में Arduino IDE अपडेट किया गया।
यह मैं दिनों के लिए व्यस्त रखा गया है, किसी भी मदद अत्यधिक सराहना की है,
धन्यवाद एक बहुत!
स्ट्रिंग कितनी बड़ी है? – Anycorn
यह 0 से शुरू होता है और 32 बाइट तक बढ़ता है (प्रत्येक फॉर-लूप 2 दृश्य बाइट जोड़ता है) –