For some time I have been writing up information about some historic, and simple compared to modern, cryptonymic algorithms. They are collected in book form (a PDF actually – new release coming soon) that I have made available on my website. One algorithm that I have struggled with has been the Playfair Cipher. I don’t know why but for some reason I’ve had trouble with the algorithm. Mostly, I have struggled with how to code it up. Recently, I decided that I should work on that.
First step was to use something called Notebook LM. More on that in a future post. It’s pretty amazing. In any case, that tool helped me find a coded implementation of the Playfair Cipher. Great! Maybe I can learn from that. It turns out that I can.
The code was in Python and I am not very experienced with Python. Still with well over a dozen languages under my belt, figuring out the code was not hard. After reading the code I feel like I have a better handle on things.
I also learned more than I expected about how Python does things. So double the win. I do believe that reading code is a great way to better understand a programming language. It’s especially valuable if it helps you learn the idiom of the language.
So I now had a console application that worked and that I could play with. Now to me, a console application is so late 20th century that my next step was to convert to C# so I could use Windows Forms. Since I was already using “artificial intelligence” (that’s in quotes because I don’t completely buy that these tools are actually intelligent.) I asked Copilot to convert the Python code into C#. It did so quickly and easily. It wasn’t the way I am used to doing things though. Maybe that is why I was struggling with my own code? It’s a possibility.
The old joke is/was that a good FORTRAN programmer can write a good FORTRAN program in any programming language. Apparently, Copilot can write a good Python program in C#. Yes, the code looked a lot more like the Python code than I had expected. More than I really wanted as well. But along the way I learned that C# could do some things in some ways that I didn’t realize. There have been a lot of changes and updates in the language and I have clearly not kept up with all of them. Well, more learning is a good thing I guess.
Once I had the converted code I built a nice Windows application and have had some fun with it.
I am toying with messing with the C# code to make it look more like what I am comfortable with but that may not be the best use of my time. I might be better off experimenting with the new (to me) features of the language. Either way, learning is a good thing.