# Arduino atmega328p

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;
int counter = 8;
boolean right_pass;
void setup() {
DDRD &= 0b11111011;
PORTD |=0b00000100;
EICRA |= 0b00000010;
EIMSK |= 0b00000001;
Serial.begin(9600);
}

void loop() {
while (Serial.available() == 0) {}  //wait for serial terminal to be ready
for ( int j = 0 ;j < 128; j++) //   28 char
{
for (int i = 0; i<16 ; i++) {     //16 char
}
}
}
``````
• And what exactly is the problem? Apr 14 '20 at 19:23
• I don't think your code does what you've described. But what exactly are you asking? Apr 14 '20 at 19:43

``````   for ( int j = 0 ;j < 128; j++) //   28 char
{
for (int i = 0; i<16 ; i++) {     //16 char
}
}
``````

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] );
}
}
``````
• Yes, and you'd have to calculate the address. I'll add an example to the answer. Apr 14 '20 at 20:09