try this...

alphainvert {
var %~ = 1 | while ((%~ < 255) && ($poscs($1-,$chr(%~),0) > 0)) inc %~ | %~ = $chr(%~)
return $replacecs($1- ,A,%~,Z,A,%~,Z, B,%~,Y,B,%~,Y, C,%~,X,C,%~,X, D,%~,W,D,%~,W, E,%~,V,E,%~,V, F,%~,U,F,%~,U, G,%~,T,G,%~,T, H,%~,S,H,%~,S, I,%~,R,I,%~,R, J,%~,Q,J,%~,Q, K,%~,P,K,%~,P, L,%~,O,L,%~,O, M,%~,N,M,%~,N ,a,%~,z,a,%~,z, b,%~,y,b,%~,y, c,%~,x,c,%~,x, d,%~,w,d,%~,w, e,%~,v,e,%~,v, f,%~,u,f,%~,u, g,%~,t,g,%~,t, h,%~,s,h,%~,s, i,%~,r,i,%~,r, j,%~,q,j,%~,q, k,%~,p,k,%~,p, l,%~,o,l,%~,o, m,%~,n,m,%~,n)
}

I used LocutusofBorg example of A,@, Z,A, @,Z but also protecting incase @ is in the string also, i replaced it with a value in %~ which most isnt going to be in the string (hopefully).

The reason your replace didnt work is becuase of how $repalce works. its like this.
"abz" replace a with z to get "zbz"
"zbz" replace b with y to get "zyz"
"zyz" replace c with x to get "zyz"
"
"
"zyz" replace y with b to get "zbz"
"zbz" replace z with a to get "aba"