Python – Encryption and Decryption of a message

This month I have finished with my Python course in HackBulgaria, thus I have decided to continue with a course, called Algorithms. Python

The course had a requirement of three tasks, which should be resolved in a reasonable time. The first one is a little too trivial to be presented here, but the other two took me a reasonable time, thus I have decided to write about them. So, let’s start with the second one, which requires the making of an algorithm, that decrypts hidden messages into something meaningful.

The full task is published here.

At first, when I saw it I thought that it would be rather easy to do it, but it was not the case. I started to make the algorithm to decrypt the message and after some hour or so I was ready (a lot of time, indeed, but I was also testing and drinking beer). Also, I did not get from the first time the idea for the alphabet word, I tought that I should go to the ASCII table instead.

Once, I was ready with the encryption, I started to decrypt. It was a little easier, until the moment, when I had the resulting index (“hevrItommseIal vi”) and the indices of the key (“12, 6, 3, 7, 12, 6, 3, 7, 12, 6, 3, 7, 12, 6, 3, 7, 12”). With these two I had to build the sum of the key with the original message. It seemed tough, because there was a remainder in the whole story and I was not sure where to apply the whole number. So, I simply disregarded it (Never do this at work!) 🙂 and I noticed that the results were coming negative in the positions, where the remainder had to be applied. Thus, with one “if” I managed to build up my decryption machine.

Here comes the code:

Enjoy it! 🙂

About

VBA Developer

Tagged with: , , ,