| | |
Encoding help, run into block.
Thread Solved
![]() |
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
Hey, im trying to make an assembly program which encodes a file using base64.
Anyway I have a program that works in converting the word "Man" to TWFu. Problem is it does not convert anything else but a few 3 letter words like Tan and Ban probally because of its similarity with Man. Below is a code snippet I am using to run the encode, taking 3 bytes from the read file and converting it to 4 bytes writing it to the file then grabbing another 3 bytes and doing the same thing. If anyone could help me figure out what I am doing wrong here help would be appreciated. I am completely stumped at this point and spent the weekend stuck on this one issue.
By the way this is x86 Assembly code, 16 bit. I am using Masm as my compiler.
Anyway I have a program that works in converting the word "Man" to TWFu. Problem is it does not convert anything else but a few 3 letter words like Tan and Ban probally because of its similarity with Man. Below is a code snippet I am using to run the encode, taking 3 bytes from the read file and converting it to 4 bytes writing it to the file then grabbing another 3 bytes and doing the same thing. If anyone could help me figure out what I am doing wrong here help would be appreciated. I am completely stumped at this point and spent the weekend stuck on this one issue.
By the way this is x86 Assembly code, 16 bit. I am using Masm as my compiler.
Assembly Syntax (Toggle Plain Text)
Encode64: ;Read Input File (3 bytes) mov ah, 3fh mov bx, input_handle mov cx, Buff3b;seting the size to read at a time mov dx, offset input_pointer ;pointing the buffer where to store int 21h jc End_Program ;Appends a 0 if the number of bytes read is less then 3 ;ax = amount of read bytes cmp ax, 2 jne start0 mov input_pointer[2], 0 start0: cmp ax, 1 jne end0 mov input_pointer[1],0 mov input_pointer[2],0 end0: or ax, ax jz done2 ;jump to done2 if ax=0 ;;;;;;;;;;Convert the 3byte data into 4 byte data ;;;;;;;;;;Storing the output into a buffer for writing B1: mov al, input_pointer[0] shr al, 2 add al,65d mov output_pointer[0],al B2: mov ax, word ptr input_pointer[0] xchg al, ah shl ax, 6 shr ax, 10 add al, 65d mov output_pointer[1], al B3: mov ax, word ptr input_pointer[1] xchg al, ah shl ax, 4 shr ax, 10 add al, 65d mov output_pointer[2],al B4: mov al, input_pointer[2] shl al, 4 shr al,2 add al, 61d mov output_pointer[3], al ;;;;;;;;;;;;;;;;;;;;;;;;; write 4b encoded data to output file mov cx, buff4b;set number of bye to write mov ah, 40h mov bx, output_handle mov dx, offset output_pointer ;write from buffer int 21h jc end_program jmp Encode64
Last edited by Ninjikiran; Dec 11th, 2007 at 1:15 am.
I'm not sure exactly what problems you are having, but the stuff following B4 has some errors.
First, if you only want to clear the top two bits of AL then
Or, even simpler:
Also, you only add 61 to it instead of 65 as you did in all the others.
You are aware, I presume, that simply adding 'A' doesn't account for three things: punctuation characters between A..Z and a..z, a control character (ASCII 127), and the fact that you exceed the ASCII character range by one character (your domain is 65..128, while ASCII is only defined on 0..127).
You would do better to use a lookup table for ASCII digits and use the xlat instruction to convert AL.
Hope this helps.
First, if you only want to clear the top two bits of AL then
shl al, 2shr al, 2Or, even simpler:
and al, 3FhAlso, you only add 61 to it instead of 65 as you did in all the others.
You are aware, I presume, that simply adding 'A' doesn't account for three things: punctuation characters between A..Z and a..z, a control character (ASCII 127), and the fact that you exceed the ASCII character range by one character (your domain is 65..128, while ASCII is only defined on 0..127).
You would do better to use a lookup table for ASCII digits and use the xlat instruction to convert AL.
Hope this helps.
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
I'm not sure exactly what problems you are having, but the stuff following B4 has some errors.
First, if you only want to clear the top two bits of AL then
shl al, 2
shr al, 2
Or, even simpler:
and al, 3Fh
Also, you only add 61 to it instead of 65 as you did in all the others.
You are aware, I presume, that simply adding 'A' doesn't account for three things: punctuation characters between A..Z and a..z, a control character (ASCII 127), and the fact that you exceed the ASCII character range by one character (your domain is 65..128, while ASCII is only defined on 0..127).
You would do better to use a lookup table for ASCII digits and use the xlat instruction to convert AL.
Hope this helps.
![]() |
Similar Threads
- StreamReader and Position (C#)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- StreamReader and Position (In VB) (VB.NET)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- Handling a multiple submit from VXML (PHP)
- Forwarding Hotmail with attachments (Windows NT / 2000 / XP)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the Assembly Forum
- Previous Thread: Making a bootable Floppy/Standalone Code
- Next Thread: gcc warning:'translating to 'fmulp' etc.
| Thread Tools | Search this Thread |






