0

This program should prompt the user for an encryption key to be input through the serial monitor. The encryption key contains 16 characters. However, the message that will be encrypted can be up to 128 characters. As such, when storing the encryption key in the EEPROM, you should repeat it so that it fills locations 0-127.

in the code, I'm trying to repeat the 16 character key 8 times

volatile bool prese_button = false;
String Password;
int counter = 8;
boolean right_pass;
void setup() {
 DDRD &= 0b11111011;
 PORTD |=0b00000100;
 EICRA |= 0b00000010;
 EIMSK |= 0b00000001;
 Serial.begin(9600);
}
void loop() {
 Serial.println("Please enter a 127 character password:"); 
 while (Serial.available() == 0) {} //wait for serial terminal to be ready 
 Password = Serial.readString(); 
 Serial.print("your password is: "); //just to verify it was read correctly 
 Serial.println(Password);
 for ( int j = 0 ;j < 128; j++) // 28 char 
 {
 for (int i = 0; i<16 ; i++) { //16 char
 EEPROM_write ( (j), Password[i] );
 }
 }
}
StarCat
1,6711 gold badge7 silver badges15 bronze badges
asked Apr 14, 2020 at 19:08
2
  • And what exactly is the problem? Commented Apr 14, 2020 at 19:23
  • I don't think your code does what you've described. But what exactly are you asking? Commented Apr 14, 2020 at 19:43

1 Answer 1

1
 for ( int j = 0 ;j < 128; j++) // 28 char 
 {
 for (int i = 0; i<16 ; i++) { //16 char
 EEPROM_write ( (j), Password[i] );
 }
 }

In these two for loops you are writing 128 times 16 characters. That seems more than you described in your post. If you have 16 things and need to repeat to fill 128 slots then you need 128 / 16 = 8 repeats of the 16 character sequence. It's just basic math. So that outer loop should count to 8, not 128.

for ( int j = 0 ;j < 8; j++) // 8 repeats of the 16 char 
 {
 for (int i = 0; i<16 ; i++) { //16 char
 EEPROM_write ((i + (16*j)), Password[i] );
 }
 }
answered Apr 14, 2020 at 19:45
1
  • Yes, and you'd have to calculate the address. I'll add an example to the answer. Commented Apr 14, 2020 at 20:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.