2017-12-15

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

ROT13

Algorithm creator(s)

n/a


PB author(s)

Borje Hagsten


Description

Adds 13 to each byte (a-z and A-Z only) in the target string.


Note

Easily broken by subtracting 13 from each byte in the target string.


Source

https://forum.powerbasic.com/forum/user-to-user-discussions/programming/18232-need-a-very-fast-way-to-mangle-text-no-protection?t=17739


See also

n/a


Source Code

Download source code file rot13.bas (Right-click -> "Save as ...")

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

Mirror provided by Knuth Konrad