How to resolve the algorithm Rot-13 step by step in the X86 Assembly programming language
How to resolve the algorithm Rot-13 step by step in the X86 Assembly programming language
Table of Contents
Problem Statement
Implement a rot-13 function (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program (like tr, which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of input contained in each file listed on its command line, or (if no filenames are passed thereon) acting as a filter on its "standard input."
(A number of UNIX scripting languages and utilities, such as awk and sed either default to processing files in this way or have command line switches or modules to easily implement these wrapper semantics, e.g., Perl and Python). The rot-13 encoding is commonly known from the early days of Usenet "Netnews" as a way of obfuscating text to prevent casual reading of spoiler or potentially offensive material. Many news reader and mail user agent programs have built-in rot-13 encoder/decoders or have the ability to feed a message through any external utility script for performing this (or other) actions. The definition of the rot-13 function is to simply replace every letter of the ASCII alphabet with the letter which is "rotated" 13 characters "around" the 26 letter alphabet from its normal cardinal position (wrapping around from z to a as necessary). Thus the letters abc become nop and so on. Technically rot-13 is a "mono-alphabetic substitution cipher" with a trivial "key". A proper implementation should work on upper and lower case letters, preserve case, and pass all non-alphabetic characters in the input stream through without alteration.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Rot-13 step by step in the X86 Assembly programming language
Source code in the x86 programming language
format ELF executable 3
entry start
segment readable writeable
buf rb 1
segment readable executable
start: mov eax, 3 ; syscall "read"
mov ebx, 0 ; stdin
mov ecx, buf ; buffer for read byte
mov edx, 1 ; len (read one byte)
int 80h
cmp eax, 0 ; EOF?
jz exit
xor eax, eax ; load read char to eax
mov al, [buf]
cmp eax, "A" ; see if it is in ascii a-z or A-Z
jl print
cmp eax, "z"
jg print
cmp eax, "Z"
jle rotup
cmp eax, "a"
jge rotlow
jmp print
rotup: sub eax, "A"-13 ; do rot 13 for A-Z
cdq
mov ebx, 26
div ebx
add edx, "A"
jmp rotend
rotlow: sub eax, "a"-13 ; do rot 13 for a-z
cdq
mov ebx, 26
div ebx
add edx, "a"
rotend: mov [buf], dl
print: mov eax, 4 ; syscall write
mov ebx, 1 ; stdout
mov ecx, buf ; *char
mov edx, 1 ; string length
int 80h
jmp start
exit: mov eax,1 ; syscall exit
xor ebx,ebx ; exit code
int 80h
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the C programming language
You may also check:How to resolve the algorithm Classes step by step in the Phix programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Gapful numbers step by step in the Erlang programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the Fortran programming language