completed barrel-cypher in scala