The reason is simple - once the first line is screwed, it works with the screwed line. Best thing I can come up now is a tempreplace:

replace all a's with @
replace all z's with a
replace all @ with z

replace all b with @
replace all y with b
replace all @ with y

Code:
alias alphainvert {
  [color:green]; save into a variable for easy editing[/color]
  set %templine $1-
  var %i = 1
  [color:green]; we're gonna do this 13 times (13 couples)[/color]
  while (%i <= 13) {
    [color:green]; define first letter[/color]
    var %first = $calc(96 + %i)
    [color:green]; define second letter[/color]
    var %last = $calc(123 - %i)
    [color:green]; replace letter 1 with a dummy character[/color]
    %templine = $replace(%templine,$chr(%first),@)
    [color:green]; replace letter 2 with letter 1[/color]
    %templine = $replace(%templine,$chr(%last),$chr(%first))
    [color:green]; replace dummy character with letter 1[/color]
    %templine = $replace(%templine,@,$chr(%last))
    inc %i
  }
  [color:green]; this echoes the inputted text[/color]
  echo -a $1-
  [color:green]; this returns the changed text to the script[/color]
  return %templine
}


input:
a b c d e f g h i j k l m n o p q r s t u v w x y z
output:
z y x w v u t s r q p o n m l k j i h g f e d c b a

Note that this piece is specific only to lowercase a - z, but so was your original code