Getting stuck on a problem can hinder productivity. Sometimes, these problems can take hours to solve. Learn how to quickly progress using a rubber ducky....
In this challenge we are asked given the problem statement:
One of the 60-character strings in this file has been encrypted by single-character XOR.
(Your code from #3 should help.)
The idea behind this problem is to go through each line, find the highest-valued histogram, record the weight value, and find the highest weight of each of the lines. This approach works because we assume the line we are interested in is the only line which is not filled with garbage. Therefore, if we find the line which has the highest probability of being an English sentence (frequency weights) we can safely assume that it is the desired line.
The code for this problem is relatively simple, so I will describe the process in words then paste the code at the bottom of this post.
- Define variables for the highest-valued string, the plaintext it encodes, and its line number
- Open the file in read mode
- For each line in the file:
a. Call the SingleCharXOR() function written for #1-3
b. If the frequency value from (4) exceeds the highest recorded value, save it
- Print the best phrase, line number, and character
In code this looks something like:
When the above code block is executed we find the information we are seeking in the form of, yet another, Vanilla Ice quote:
Now that the party is jumping
ON LINE 170
XORED AGAINST: 5