Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-139

Unicity Distance Lite

Problem

Return the unicity distance: the amount of ciphertext needed on average to pin down the key. With key entropy in bits and per-character redundancy D:

U = key_bits / D

Assume the redundancy is positive.

Hint

Perfectly decodable ciphers have no redundancy and an infinite unicity distance.

Test cases

case 1
in: [40,1.5]
expected: 26.666666666666668
case 2
in: [20,2]
expected: 10
case 3
in: [0,1.5]
expected: 0
case 4
in: [64,3]
expected: 21.333333333333332
Starter codePython
def unicity_distance(key_bits, redundancy_bits):
    # Your code here
    pass

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