Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-147

Substitution Cipher Score

Problem

Score a substitution cipher key by summing the expected English frequencies of the decrypted letters. key is a 26-character string where key[i] is the plaintext letter for ciphertext letter i, and freqs is a 26-entry frequency table indexed by plaintext letter A=0.

Hint

Better keys decrypt common letters like E into common English letters.

Test cases

case 1
in: ["IFMMP","ABCDEFGHIJKLMNOPQRSTUVWXYZ",[8.167,1.492,2.782,4.253,12.702,2.228,2.015,6.094,6.966,0.153,0.772,4.025,2.406,6.749,7.507,1.929,0.095,5.987,6.327,9.056,…
expected: 15.935000000000002
case 2
in: ["HELLO","ABCDEFGHIJKLMNOPQRSTUVWXYZ",[8.167,1.492,2.782,4.253,12.702,2.228,2.015,6.094,6.966,0.153,0.772,4.025,2.406,6.749,7.507,1.929,0.095,5.987,6.327,9.056,…
expected: 34.352999999999994
case 3
in: ["ABC","ABCDEFGHIJKLMNOPQRSTUVWXYZ",[8.167,1.492,2.782,4.253,12.702,2.228,2.015,6.094,6.966,0.153,0.772,4.025,2.406,6.749,7.507,1.929,0.095,5.987,6.327,9.056,2.…
expected: 12.440999999999999
Starter codePython
def substitution_score(text, key, freqs):
    # Your code here
    pass

3 test cases · run your code against them in the editor