rewriten attack algorithm