X86 Assembly Language
Help to implement the CipherChar Procedure at the end of the given code
INCLUDE Irvine32.inc
.data
KeyPrompt BYTE "Enter the
passphrase: ",0
TextPrompt BYTE "Enter the
plaintest: ",0
str1
BYTE "The passphrase has length:",0
str2
BYTE "The plaintest has length:",0
KeyIs BYTE "The passphrase:
",0
PlainTextIs BYTE "The plaintext:
",0
CipherTextIs BYTE "The ciphertext:
",0
KMAX = 64
;
passphrase buffer maximum size
BMAX = 128
;
test buffer maximum size
KSize DWORD KMAX;
BSize DWORD BMAX;
Key BYTE KMAX DUP(0)
;
buffer for passphrase
Buffer BYTE BMAX DUP(0)
; buffer for
(en/de-cryption) text
.code
main PROC
;
Get the passphrase from the user (put it in Key)
mov esi, OFFSET
KeyPrompt
mov edi, OFFSET Key
mov ecx, KSize
call GetString
mov KSize, eax
;
show it back to the user
(debug/verification)
mov esi, OFFSET KeyIs
mov edi, OFFSET Key
call DisplayStrings
mov edx, OFFSET
str1
call WriteString
call WriteDec
call CRLF
; Get
the plaintext from the user (put it in Buffer)
mov esi, OFFSET
TextPrompt
mov edi, OFFSET
Buffer
mov ecx, BSize
call GetString
mov BSize, eax
;
show it back to the user
(debug/verification)
mov esi, OFFSET
PlainTextIs
mov edi, OFFSET
Buffer
call DisplayStrings
mov edx, OFFSET
str2
call WriteString
call WriteDec
call CRLF
;
Show how the plain/cipher-text will 'lineup' with the
passphrase
mov esi, OFFSET
Buffer
mov edi, OFFSET Key
mov ecx, BSize
mov edx, KSize
call MatchUpBuffers
;
puts address of a buffer with passpharse
call WriteString
;
layout will line up the Text - show
; call
Transform and then CipherChar
mov esi, OFFSET
Buffer
mov edi, OFFSET Key
mov ecx, BSize
mov ebx, KSize
mov edx, 0
;
encrypt
call
TransformBuffer
call CRLF
exit
main ENDP
GetString PROC USES esi edi edx ecx
mov edx, esi
call WriteString
mov edx, edi
call ReadString
ret
GetString ENDP
DisplayStrings PROC USES eax
mov edx, esi
call WriteString
call CRLF
mov edx, edi
mov eax, 0
mov al, "'";
call WriteChar
call WriteString
call WriteChar
call CRLF
ret
DisplayStrings ENDP
MatchUpBuffers PROC
.data
msg
BYTE "Plaintext and passphrase are going to lineup as
follows:",13,10,0
shift
BYTE LENGTHOF Buffer DUP(0)
.code
pushad
;
save all regs
mov ebx, 0
;
index into key
mov eax, 0
;
zero out upper
push edx
;
save - EDX holds lengthof passphrase
mov edx,OFFSET msg
;
show message msg
call WriteString
pop edx
;
restore lenght of buffer(need it latter)
push esi
;
save esi (starting address of Buffer) and ecx (loop count)
push ecx
L2 :
mov
al, [esi]
;
move key char to register
call
WriteChar
;
show char from Buffer
inc
esi
loop L2
pop ecx
;
restore loop count (for next loop)
pop esi
;
set esi to begining of Buffer
call CRLF
L1 :
mov
al, [edi+ebx]
; copy
passphrase char to register
call
WriteChar
inc
ebx
cmp
ebx, edx
;
check if index greater then length of key string
jb
Skip
mov
ebx, 0
;
if edi > keySize reset it to zero
Skip:
loop L1
call CRLF
popad
;
restore all the register (see next line)
mov edx, OFFSET
shift ; move
address into EDX so client can call WriteString
ret
MatchUpBuffers ENDP
TransformBuffer PROC
pushad
;
save all the registes (could use USES)
mov eax, 0
;
zero chacters
mov eax, edx
;
copy over upper 16 bits (en/de-crytion)
mov ax, 0
;
zero out lower part of eax
mov edx, 0
;
zero INDEX
L1
:
mov
al, [esi]
; char
from Buffer
mov
ah, [edi+edx] ; char from
Passphrase
call
CipherChar ;
transform char
push
ax ;
save chars from Passphrase::Text
push
bx ;
save length passphrase
mov
bl,ah ; copy
passphrase char into bl
mov
ah,0 ;
overwrite ah (so WriteChar works correctly)
call
WriteChar ; print char from Text
mov
al, ":" ; lets make the output
nic eand readable
call
WriteChar
mov
al,bl ; no print
shift letter (from passphrase)
call
WriteChar
call
CRLF ; new
line
pop
bx
; restore length of passphrase
pop
ax
; restore chars from Passphrase::Text
mov [esi], al ; overwrite
orginal char with cipher version
inc eax
; increament point into BUFFER
inc edx
; increament the INDEX in to
passphrase
cmp edx,ebx ; check if
index greater then length of key string
jb Skip
mov
edx,0
;
if edi > keySize reset it to zero
Skip:
;
if still index < length we are okay
loop L1
popad
;
restore all registers
ret
TransformBuffer ENDP
;
--------------------------------------------------
; CipherChar - Does range shift
(32-126)
;
; EAX - VALUE (
char to en/de-crypt )
; ECX - SHIFT (
amount to shift either add or sub )
; if(VALUE <
LOWER) return - nonprintable ascii skip
; if(VALUE >
UPPER) return - out of range skip
; VALUE = VALUE - LOWER a
space(32) becomes 0 (see above)
; SHIFT = SHIFT - LOWER
; VALUE = VALUE +/- SHIFT
shift the char
; VALUE = VALUE % UPPER)
make sure stays in range
; VALUE = VALUE +
LOWER
;
; So takes an ascii value
0-127
;
if its between 32 and 126 (inclusively) (printible
ascii)
;
the converts number to range 0 to 94
(inclusively)
;
shift by passphrase value (add
encrypt/ sub decrypt)
;
if value now out of range move back
into (modulo)
;
adds back the 32 so back in orginal ASCII
(32-126)
;
; Receives: EAX
;
al -
char to shift
;
ah -
amount to shift
;
upper part of eax encrypte(0)
or decrypt (F)
;
; Returns: transformed char in
ax
;
--------------------------------------------------
CipherChar PROC USES EBX ECX EDX ESI
EDI
ret
CipherChar ENDP
X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code...
MASM Assembly Language programming question. I'm having serious issues. I am attempting to scan through a string and replace all the "o" characters with an exclamation mark (!). However my program does not work and no change seems to occur to the string. Also the loop breaks once the first "o" character is encountered.Is there anyone in this Universe that can help me???Please main PROC ;mov edi,OFFSET string mov ecx, LENGTHOF string mov edi,OFFSET string L1:...
Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex and endIndex The program should create a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. In other words you can say that beginIndex is inclusive and endIndex is exclusive while getting the substring. Initialize the following values in...
rnte a P instruction with indirect addressing, and call the ReadChar ein AL.)(10 pts.) BYTE named myString. Use the LOO edure from the book's link library- (ReadChar-returns its valu 50. Code a PROC declaration for a procedure named MySub. Use the USES operator to preserve the EAX and EBX registers. 51. Draw a flowchart that corresponds to the following code: (6 pts.) mov ecx, LENGTHOF array mov eax, 0 mov esi, OFFSET array L1: add eax, [esi] add esi, TYPE...
assembly language Given the following string definition: message1 BYTE "No pain, No gain",0 Which of the following sequence of statements will write message1 to standard output by using a Irvine32 library procedure? mov edx, message1 call WriteString mov eax,OFFSET message1 call WriteString mov edx,OFFSET message1 call WriteString
Task is to implement the following algorithms in Assembly language for x86 processor1) Insertion sort Demonstrate Sorted Array of 10 elements in Watch Window for each one Running time of each algorithmsample bubble sort code:;----------------------------------------------------------BubbleSort PROC USES eax ecx esi,pArray:PTR DWORD, ; pointer to arrayCount:DWORD ; array size;; Sort an array of 32-bit signed integers in ascending; order, using the bubble sort algorithm.; Receives: pointer to array, array size; Returns: nothing;-----------------------------------------------------------mov ecx,Countdec ecx ; decrement count by 1L1: push ecx ; save outer...
I need help finding the input that wont result in explode_bomb in this assembly 08048cd3 <phase_4>: 8048cd3: 57 push %edi 8048cd4: 56 push %esi 8048cd5: 53 push %ebx 8048cd6: 83 ec 10 sub $0x10,%esp 8048cd9: 8b 74 24 20 mov 0x20(%esp),%esi 8048cdd: 89 34 24 mov %esi,(%esp) 8048ce0: e8 f6 03 00 00 call 80490db <string_length> 8048ce5: 83 c0 01 add $0x1,%eax 8048ce8: 89 04 24 mov %eax,(%esp) 8048ceb: e8 10 fb ff ff call 8048800 <malloc@plt> 8048cf0: 89 c7...
In Nasm: In the following code what it's needed to sort the array in ascending order: ;;;;;;;;;;;;;;;;;;;; MACRO DEFINITIONS ;;;;;;;;;;;;;;;;;;;; ; A macro with two parameters ; Implements the write system call %macro writestring 2 mov eax, 4 ;sys_write system call number mov ebx, 1 ;file descriptor std_out mov ecx, %1 ;message to write from parameter 1 mov edx, %2 ;message length from parameter 2 int 0x80 %endmacro...
I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates and prints out the first five Fibonacci numbers FO=0; F1=1; F2=1; F3=F1+F2; F4=F3+F2; F5=F4+F3 If we use 0, 1 and initial conditions the sequence would be: 0, 1, 1, 2, 3 Use the ebx, eax, and ecx registers. Note WriteHex, Writelnt, WriteDec, all use eax So use ebx for first and eax for second and ecx for temporary The calculation could go something like...
NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib. The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers. Fibonacci sequence is described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). The value of N is to be communicated to this...
Can someone explain how to get the answer to these two questions please? This is a review for school. ; code fragment V Use this information and the code at the right to answer questions # 20-21. mov edx, OFFSET string mov ecx , MAXSIZE dec ecx call Readstring mov ecx, eax ; number of Given the following declarations for an IA-32 processor MAXSIZE 10 data ; digits entered ;initialize val string BYTE MAXSIZE DUP (?) mov val,0 mov esi,...