943,898 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 1309
  • Assembly RSS
Dec 11th, 2007
0

Encoding help, run into block.

Expand Post »
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.

Assembly Syntax (Toggle Plain Text)
  1. Encode64:
  2. ;Read Input File (3 bytes)
  3. mov ah, 3fh
  4. mov bx, input_handle
  5. mov cx, Buff3b;seting the size to read at a time
  6. mov dx, offset input_pointer ;pointing the buffer where to store
  7. int 21h
  8. jc End_Program
  9.  
  10. ;Appends a 0 if the number of bytes read is less then 3
  11. ;ax = amount of read bytes
  12. cmp ax, 2
  13. jne start0
  14. mov input_pointer[2], 0
  15. start0:
  16. cmp ax, 1
  17. jne end0
  18. mov input_pointer[1],0
  19. mov input_pointer[2],0
  20. end0:
  21. or ax, ax
  22. jz done2 ;jump to done2 if ax=0
  23.  
  24. ;;;;;;;;;;Convert the 3byte data into 4 byte data
  25. ;;;;;;;;;;Storing the output into a buffer for writing
  26.  
  27.  
  28. B1:
  29. mov al, input_pointer[0]
  30. shr al, 2
  31. add al,65d
  32. mov output_pointer[0],al
  33.  
  34. B2:
  35. mov ax, word ptr input_pointer[0]
  36. xchg al, ah
  37. shl ax, 6
  38. shr ax, 10
  39. add al, 65d
  40.  
  41.  
  42.  
  43. mov output_pointer[1], al
  44.  
  45. B3:
  46. mov ax, word ptr input_pointer[1]
  47. xchg al, ah
  48. shl ax, 4
  49. shr ax, 10
  50. add al, 65d
  51. mov output_pointer[2],al
  52. B4:
  53. mov al, input_pointer[2]
  54. shl al, 4
  55. shr al,2
  56. add al, 61d
  57. mov output_pointer[3], al
  58.  
  59.  
  60. ;;;;;;;;;;;;;;;;;;;;;;;;; write 4b encoded data to output file
  61. mov cx, buff4b;set number of bye to write
  62. mov ah, 40h
  63. mov bx, output_handle
  64. mov dx, offset output_pointer ;write from buffer
  65. int 21h
  66. jc end_program
  67. jmp Encode64
Last edited by Ninjikiran; Dec 11th, 2007 at 1:15 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ninjikiran is offline Offline
10 posts
since Dec 2007
Dec 11th, 2007
0

Re: Encoding help, run into block.

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.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Dec 11th, 2007
0

Re: Encoding help, run into block.

Click to Expand / Collapse  Quote originally posted by Duoas ...
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.
xlat is definately a nifty feature, just applied it. That said it is defiantely working better but still working hard on it!. I will look into more in depth how to fix it with the suggestions you have outline. I'll come back if I run into any road blocks but hopefulyl that wont happen.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ninjikiran is offline Offline
10 posts
since Dec 2007
Dec 11th, 2007
0

Re: Encoding help, run into block.

Great. When you are ready to go the other way, you can use rep scasb to look for an item in the table, and subtract the difference between the location of the item in the table and the beginning of the table to get the index of the item.

Hope this helps.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Dec 11th, 2007
0

Re: Encoding help, run into block.

Thanks~ Definately helps, I was able to make a working program that perfectly encodes into Base64 100% of the time. As for decoding I decided to start working on it soon, thanks for the tip on how to go the other way!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ninjikiran is offline Offline
10 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Making a bootable Floppy/Standalone Code
Next Thread in Assembly Forum Timeline: gcc warning:'translating to 'fmulp' etc.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC