BBS algorithm