943,892 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 993
  • Assembly RSS
May 4th, 2009
0

cipher text idea ?

Expand Post »
this is my code which copies 1st string into 2nd String.

Assembly Syntax (Toggle Plain Text)
  1. AREA StrCopy1, CODE
  2. SWI_WriteC EQU &2
  3.  
  4. ENTRY ; mark the first instruction
  5. main
  6. ADR r1, srcstr ; pointer to first string
  7. ADR r0, dststr ; pointer to second string
  8. BL strcopy ; copy the first into second
  9. SWI 0x11 ; and exit
  10.  
  11. srcstr DCB " This is my first (source) string",&0a,&0d,0
  12. dststr DCB " This is my second (destination) string",&0a,&0d,0
  13.  
  14. ALIGN ; realign address to word boundary
  15.  
  16. strcopy
  17. LDRB r2, [r1], #1 ; load byte, then update address
  18. STRB r2, [r0], #1 ; store byte, then update address
  19. CMP r2, #0 ; check for zero terminator
  20. BNE printout ; branch if not equal, to Printout
  21.  
  22.  
  23. printOut
  24. SWINE SWI_WriteC ; Print the content
  25. B strcopy ; branch to strcopy
  26. MOV pc, lr ; return
  27. END
*******
Now i want to modify the above code so that it encrypts the dststr using Caesar cipher method and which of course will be printed out on the screen aswell.

Thanks for ur reply and i hope it makes the point clear if not feel free to ask me.

Br.
Last edited by j_cart007; May 4th, 2009 at 3:57 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_cart007 is offline Offline
17 posts
since May 2009
May 5th, 2009
0

Re: cipher text idea ?

Quote ...
Now i want to modify the above code so that it encrypts the dststr using Caesar cipher method and which of course will be printed out on the screen aswell.

Thanks for ur reply and i hope it makes the point clear if not feel free to ask me.

Br.
A caesar encryption is just a replacement encryption.
Couple of ways to go about this but I only have time to explain two
One is the simpliest you have two strings
ABCDEFGHI
WLPQSRNXZ
You take each char from the source string and find it's equiv in the top string and use that index to find it's equiv in the encryption key there at the bottom.

An faster way would be to setup your encryption key as the previous one for the first 9 characters...
WLPQSRNXZ

Now I find a character in my source string the first character happens to be an 'A' I check a mask to see if it's upper case or lower case and then depending on that outcome I subtract 'A' from it for upper case characters and 'a' from it for lower case characters.
What's this give me? An offset sir 'A' - 'A' is 0 and a 0 offset into our above string is 'W'
'B' - 'A' is 1 so a 1 offset.
Reputation Points: 57
Solved Threads: 5
Light Poster
sysop_fb is offline Offline
42 posts
since Apr 2009
May 5th, 2009
0

Re: cipher text idea ?

thankx for ur reply sir !
whatever i've got so far is in the code if u can pls have a look and correct me:

Assembly Syntax (Toggle Plain Text)
  1. AREA text, CODE
  2.  
  3. SWI_WriteC EQU &0
  4.  
  5. ENTRY
  6.  
  7. ADR r4, hello
  8. ADR r3, alpha
  9. ADR r2, key
  10. loop
  11.  
  12. LDRB r0, [r4], #1
  13. CMP r0, #0
  14. BNE check
  15.  
  16. check
  17. LDRB r1, [r3], #1
  18. CMP r0, r1
  19. BEQ encrypt
  20. B loop
  21. encrypt
  22. LDRB r5, [r2], #1
  23. SUB r0,r0,r5
  24. ADD r5,r5,#1
  25. STRB r0,[r5]
  26. SWINE SWI_WriteC
  27. B loop
  28.  
  29. endP
  30.  
  31. MOV pc, lr ; return
  32. END
  33.  
  34. hello DCB "Hello World ",0
  35. alpha DCB "ABCDEFGHIJKLMNOPQRSTUVWXYZ",0
  36. key DCB "XZYCJBTEKMGH",0
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_cart007 is offline Offline
17 posts
since May 2009

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: XY position
Next Thread in Assembly Forum Timeline: Space Invaders





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


Follow us on Twitter


© 2011 DaniWeb® LLC