Project Euler/59: Difference between revisions
From charlesreid1
| Line 16: | Line 16: | ||
==Approach== | ==Approach== | ||
Create list of most common bigrams in English language | |||
Sliding window of 2 letters at a time | |||
For each pair of letters in the ciphertext, for each most common bigram, find the corresponding secret key at that position that would cause this bigram to become the most common bigram | |||
Can weight each secret key by how common the bigram is | |||
<s> | |||
Part 2: | |||
Create list of most common trigrams in English language | |||
Sliding window of 3 letters at a time | |||
For each triplet of letters, for each most common trigram, find the corresponding secret key at that position that would cause this trigram to become the most common trigram | |||
</s> | |||
<s> | |||
Part 3; | |||
Create list of most common letters in English language, plus weights | |||
For each "letter" in the ciphertext, for each most common letter, find the corresponding secret key at that position that would cause the ciphertext to become the most common letter | |||
</s> | |||
==Flags== | ==Flags== | ||
{{ProjectEulerFlag}} | {{ProjectEulerFlag}} | ||
Revision as of 20:23, 14 April 2025
Problem Statement
This question is about a method of encrypting ASCII text.
Each character in ASCII has some representation (e.g., A=65, *=42, k=107)
Encryption technique is to take text file, convert bytes to ASCII, and XOR each byte with a character from a secret key
Password method: use a password in place of a secret one-time pad; shorter than message, so repeated cyclically throughout method.
You are given a file with encrypted ascii codes, knowledge that plain text must contain common English words, and told encryption key consists of 3 lowercase characters. Decrypt message, find sum of ascii values in original text.
Sample file looks like this: 36,22,80,0,0,4,23,...
Link: https://projecteuler.net/problem=59
Approach
Create list of most common bigrams in English language
Sliding window of 2 letters at a time
For each pair of letters in the ciphertext, for each most common bigram, find the corresponding secret key at that position that would cause this bigram to become the most common bigram
Can weight each secret key by how common the bigram is
Part 2:
Create list of most common trigrams in English language
Sliding window of 3 letters at a time
For each triplet of letters, for each most common trigram, find the corresponding secret key at that position that would cause this trigram to become the most common trigram
Part 3;
Create list of most common letters in English language, plus weights
For each "letter" in the ciphertext, for each most common letter, find the corresponding secret key at that position that would cause the ciphertext to become the most common letter
Flags