NAME: ROT13
CREATOR: n/a
PB AUTHOR: Borje Hagsten
DESCRIPTION: Adds 13 to each byte (a-z and A-Z only) in the target string.
NOTES: Easily broken by subtracting 13 from each byte in the target string.
SOURCE: http://www.powerbasic.com/support/forums/Forum6/HTML/001173.html
Viewing source from rot13.bas   1667 bytes   Last modified Wed, 20 September 2006

SUB asmROT13(a$)
  LOCAL ln AS LONG
  ln = LEN(a$)             ' get string's len into ln

  ! cmp ln, 0              ; does the string have a length?
  ! je Exit13Loop          ; exit if zero

  ! mov eax, a$            ; eax = pointer to string handle
  ! mov eax, [eax]         ; eax = pointer to string data

  Bgn13Loop:
     ! mov edx, [eax]      ; move current char into edx
     ! cmp ln, 0           ; exit when ln = zero
     ! jne Continue13Loop
        ! jmp Exit13Loop   ; jump out on end of string

  Continue13Loop:
     ! cmp dl, 65          ; CASE 65 TO 90
     ! jb NoRot            ;    if dl < 65  then get next character
     ! cmp dl, 90
     ! jbe Rot13Upper      ;    if dl <= 90
     ! cmp dl, 97          ; CASE 97 TO 122
     ! jb NoRot            ;    if dl < 97  then next character
     ! cmp dl, 122
     ! jbe Rot13Lower      ;    if dl <= 122
     ! jmp NoRot           ; CASE ELSE - get next character

  Rot13Lower:
     ! add dl, 13          ; Rotate 13 steps forward
     ! cmp dl, 122
     ! ja AdjChar          ; if dl became > 122
     ! mov [eax], dl       ; else write changed char back into a$
     ! jmp NoRot

  Rot13Upper:
     ! add dl, 13          ; Rotate 13 steps forward
     ! cmp dl, 90
     ! ja AdjChar          ; if dl became > 90
     ! mov [eax], dl       ; else write changed char back into a$
     ! jmp NoRot

  AdjChar:
     ! sub dl, 26
     ! mov [eax], dl       ; else write changed char back into a$
     ! jmp NoRot

  NoRot:
     ! inc eax
     ! dec ln              ; decrease the ln (length) counter
     ! jmp bgn13Loop

  Exit13Loop:
END SUB

Back to The Archives