Forth (gforth), 77 bytes
: f 0 tuck do over i + c@ '# - ?dup if 24 = - else 127 mod emit 0 then loop ; ###Code Explanation
Code Explanation
: f \ start a new word definition 0 tuck \ put 0 on the top of the stack and stick a copy behind the second stack item do \ begin a counted loop from 0 to string length - 1 over i + \ get the address of the next character c@ '# - \ get the next character's ascii value and subtract ascii # (35) ?dup \ if result is not 0, duplicate if \ if result is true (not 0) 24 = - \ check if result = 24, and subtract -1 from accumulator if it is (0 otherwise) else \ else (if result was equal to 35) 127 mod \ get accumulator mod 127 emit 0 \ output accumulator and replace with 0 then \ end if loop \ end loop ; \ end word definition