abbi-gehl / masm-enigma

This is a digital simulation of the German Enigma machine written in x64 masm assembly and C++
Apache License 2.0
1 stars 0 forks source link

STORY: First Rotor #3

Closed abbi-gehl closed 7 months ago

abbi-gehl commented 8 months ago

Creating the first working rotor would be a good first step in the rotor system.

A way to do this could be to create a 26-element array that stores <Key, Value> pairs.

Every time a new character goes through the rotor, we should increment the rotor by looking at the next element.

Harrison-Blair commented 8 months ago

Code written to populate a c++ map that does the same functionality as the Key Value pairs.

Should look into how the map is indexed, and how it will be best translated over to MASM.

My initial thought is maybe using the default alphabet array to index the Map, and indexing that array to get the corresponding character in the alphabet so we can just worry about integers. We could instead increment say an ASKEY value by whatever the difference between letters is, but that may prove unnecessarily complicated. We may just be able to increment the map by an integer, I should really just look at the documentation.

Harrison-Blair commented 8 months ago

https://cplusplus.com/reference/map/map/begin/

Seems like we can iterate through it in c++ using an iterator, that would function similarly to an integer.

for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
    std::cout << it->first << " => " << it->second << '\n';

Instead of adding to an integer, we can call a function that will increment the iterator itself.

Harrison-Blair commented 8 months ago

https://cplusplus.com/reference/map/map/count/ EVEN BETTER!

for (c='a'; c<'h'; c++)
  {
    std::cout << c;
    if (mymap.count(c)>0)
      std::cout << " is an element of mymap.\n";
    else 
      std::cout << " is not an element of mymap.\n";
  }

We can just increment a c++ variable that is a character, starting with 'A' and just incrementing until 'Z'. The only thing we need now is to handle looping back to 'A' from 'Z'.

abbi-gehl commented 7 months ago

WOW