Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-171

Password Entropy

Problem

Return the entropy in bits of a uniformly random password drawn from a charset of the given size with the given length:

H = length * log2(charset_size)

Hint

Each character adds log2(charset_size) bits of entropy.

Test cases

case 1
in: [26,8]
expected: 37.603517745128734
case 2
in: [10,4]
expected: 13.287712379549449
case 3
in: [2,1]
expected: 1
case 4
in: [95,8]
expected: 52.55884486664758
Starter codePython
import math
def password_entropy(charset_size, length):
    # Your code here
    pass

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