1
0
Fork 0

Update 'code.c.ino'

This commit is contained in:
NaiJi ✨ 2022-03-23 21:16:29 +00:00
parent 0e35915e62
commit 7f4aa0f9a9
1 changed files with 136 additions and 40 deletions

View File

@ -33,16 +33,16 @@ uint16_t toKeyIndex(const String& input_hex)
return index;
}
size_t forward(size_t index, size_t current_wheel)
size_t forward1(size_t index, size_t current_wheel)
{
size_t input = (index + key_shifts[current_wheel]) % ALPHABET_SIZE;
size_t output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations[current_wheel][i].from == input)
if (mutations1[i].from == input)
{
output = mutations[current_wheel][i].to;
output = mutations1[i].to;
break;
}
}
@ -50,15 +50,108 @@ size_t forward(size_t index, size_t current_wheel)
return output;
}
size_t backward(size_t index, size_t current_wheel)
size_t forward2(size_t index, size_t current_wheel)
{
size_t input = (index + key_shifts[current_wheel]) % ALPHABET_SIZE;
size_t output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations2[i].from == input)
{
output = mutations2[i].to;
break;
}
}
return output;
}
size_t forward3(size_t index, size_t current_wheel)
{
size_t input = (index + key_shifts[current_wheel]) % ALPHABET_SIZE;
size_t output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations3[i].from == input)
{
output = mutations3[i].to;
break;
}
}
return output;
}
size_t forward4(size_t index)
{
size_t input = index % ALPHABET_SIZE;
size_t output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations4[i].from == input)
{
output = mutations4[i].to;
break;
}
}
return output;
}
size_t backward1(size_t index, size_t current_wheel)
{
int output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (input == mutations[current_wheel][i].to)
if (index == mutations1[i].to)
{
output = (mutations[current_wheel][i].from - key_shifts[current_wheel]);
output = (mutations1[i].from - key_shifts[current_wheel]);
while (output < 0)
{
output += ALPHABET_SIZE;
}
output = output % ALPHABET_SIZE;
}
}
return output;
}
size_t backward2(size_t index, size_t current_wheel)
{
int output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (index == mutations2[i].to)
{
output = (mutations2[i].from - key_shifts[current_wheel]);
while (output < 0)
{
output += ALPHABET_SIZE;
}
output = output % ALPHABET_SIZE;
}
}
return output;
}
size_t backward3(size_t index, size_t current_wheel)
{
int output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (index == mutations3[i].to)
{
output = (mutations3[i].from - key_shifts[current_wheel]);
while (output < 0)
{
output += ALPHABET_SIZE;
@ -73,38 +166,34 @@ size_t backward(size_t index, size_t current_wheel)
size_t encode(size_t index)
{
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
{
index = forward(index, i);
}
size_t overturning_input = index % ALPHABET_SIZE;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations[3][i].from == overturning_input)
{
index = mutations[3][i].to;
break;
}
}
for (size_t i = (WHEELS_AMOUNT - 1); i >= 0; --i)
{
index = backward(index, i);
}
index = forward1(index, 0);
index = forward2(index, 1);
index = forward3(index, 2);
index = forward4(index);
index = backward3(index, 2);
index = backward2(index, 1);
index = backward1(index, 0);
return index;
}
void rotate()
{
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
++key_shifts[0];
if (key_shifts[0] == 26)
{
++key_shifts[i];
if (key_shifts[i] != ALPHABET_SIZE)
key_shifts[i] = 0;
else
break;
key_shifts[0] = 0;
++key_shifts[1];
if (key_shifts[1] == 26)
{
key_shifts[1] = 0;
++key_shifts[2];
if (key_shifts[2] == 26)
{
key_shifts[2] = 0;
}
}
}
}
@ -135,14 +224,21 @@ void loop()
size_t encoded_index = encode(index);
const String encoded_letter = key_values[encoded_index].view;
size_t y = 0;
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
{
HCuOLED.Cursor(4, y);
HCuOLED.SetFont(MedProp_11pt);
HCuOLED.Print(key_shifts[i]);
y += 20;
}
HCuOLED.Cursor(5, 5);
HCuOLED.Print(key_shifts[0]);
Serial.print(key_shifts[0]);
HCuOLED.Cursor(5, 25);
HCuOLED.Print(key_shifts[1]);
Serial.print(key_shifts[1]);
HCuOLED.Cursor(5, 40);
HCuOLED.Print(key_shifts[2]);
Serial.print(key_shifts[2]);
HCuOLED.Refresh();
HCuOLED.ClearBuffer();
Serial.println(" ");
if (lcd_output.length() == 16)
{