1
0
Fork 0

Update 'code.c.ino'

master
NaiJi ✨ 2 years ago
parent 0e35915e62
commit 7f4aa0f9a9

@ -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,66 @@ 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;
@ -71,40 +122,78 @@ size_t backward(size_t index, size_t current_wheel)
return output;
}
size_t encode(size_t index)
size_t backward2(size_t index, size_t current_wheel)
{
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
{
index = forward(index, i);
}
int output = 0;
size_t overturning_input = index % ALPHABET_SIZE;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
if (mutations[3][i].from == overturning_input)
if (index == mutations2[i].to)
{
index = mutations[3][i].to;
break;
output = (mutations2[i].from - key_shifts[current_wheel]);
while (output < 0)
{
output += ALPHABET_SIZE;
}
output = output % ALPHABET_SIZE;
}
}
for (size_t i = (WHEELS_AMOUNT - 1); i >= 0; --i)
return output;
}
size_t backward3(size_t index, size_t current_wheel)
{
int output = 0;
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
{
index = backward(index, i);
if (index == mutations3[i].to)
{
output = (mutations3[i].from - key_shifts[current_wheel]);
while (output < 0)
{
output += ALPHABET_SIZE;
}
output = output % ALPHABET_SIZE;
}
}
return output;
}
size_t encode(size_t index)
{
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;
}
}
}
}
@ -134,15 +223,22 @@ 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.SetFont(MedProp_11pt);
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)
{
@ -155,4 +251,4 @@ void loop()
lcd.clear();
lcd.print(lcd_output);
rotate();
}
}
Loading…
Cancel
Save