technomonkey76

Vigenère Cipher Tool

Feb 13th, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .nolist
  2. #include "ti83plus.inc"
  3. #include "dcs7.inc"
  4. .list
  5. .org $9D93
  6. .db t2ByteTok,tAsmCmp
  7.  
  8. CipherText          .equ appBackUpScreen            ; Will contain final result
  9. ExpandedKey         .equ appBackUpScreen+256        ; Will contain key to full length
  10. OffsetConvString    .equ appBackUpScreen+512        ; Will contain string as values 0-25
  11.  
  12. Init:                                       ; Doors CS 7 Header
  13.     xor d
  14.     ret
  15.     jr Start
  16.    
  17.     .dw Description
  18.     .db $07,$00
  19.     .dw Icon
  20.     .dw 0000
  21.  
  22. Start:
  23.     bcall(_ClrLCDFull)
  24.     call OpenGUIStack
  25.     ld hl,MainGUIData
  26.     call PushGUIStacks
  27.     ld hl,0
  28.     call GUIMouse
  29.     ret
  30.  
  31. Encrypt:
  32.     call ResetAppPage
  33.     call ExpandKey
  34. ;   call ASCIIToOffset
  35.     ld hl,OffsetConvString
  36.     ld de,ExpandedKey
  37.     ld bc,CipherText
  38.     bcall(_GetKey)
  39.     ret
  40.  
  41.  
  42.  
  43. ASCIIToOffset:
  44.     ; I'm not sure what a good routine for this would be
  45.     ret
  46.  
  47. Decrypt:
  48.     ; This will be trivial once enciphering is working
  49.     call ResetAppPage
  50.     ret
  51.  
  52.  
  53.  
  54. GetStringLocation:
  55.     call GUIFindThis
  56.     ld de,6
  57.     add hl,de
  58.     ret
  59.  
  60.  
  61.  
  62. Sub26:
  63.     sub 26
  64.     ret
  65.  
  66. ExpandKey:
  67.     ld a,3
  68.     call GetStringLocation      ; hl contains pointer to string
  69.     ld b,0
  70. StringSizeLoop:
  71.     inc hl
  72.     inc b
  73.     ld a,(hl)
  74.     cp 0
  75.     jr z,SizeCheckComplete
  76.     jr StringSizeLoop
  77. SizeCheckComplete:              ; b contains character count from string
  78.     call ResetKeyPointer        ; hl has pointer to key
  79.     ld de,ExpandedKey
  80. ExpandKeyLoop:
  81.     ld a,(hl)
  82.     cp 0
  83.     jr z,ResetKeyPointer
  84.     ld (de),a
  85.     inc de
  86.     inc hl
  87.     djnz ExpandKeyLoop
  88.     ret
  89.  
  90. ResetKeyPointer:
  91.     push de
  92.     push bc
  93.     ld a,4
  94.     call GetStringLocation
  95.     pop bc
  96.     pop de
  97.     ret
  98.  
  99. About:
  100.     call ResetAppPage
  101.     ld hl,AboutGUIData
  102.     call PushGUIStacks
  103.     ld hl,0
  104.     call GUIMouse
  105.     ret
  106. ReturnFromAbout:
  107.     call ResetAppPage
  108.     ld b,3
  109.     call PopGUIStacks
  110.     ld hl,0
  111.     call GUIMouse
  112.     ret
  113.  
  114. Quit:
  115.     call ResetAppPage
  116.     call CloseGUIStack
  117.     ret
  118.  
  119. CharacterData:
  120.     ; There are likely other Doors-compatible characters not here which need to be
  121.     .db "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890 %#.-?()[],*/+^",$5B,$B0,$26,$22,$27,$D0,$B6,$B7,$5D,$C1,$05,$21,$24,$1A,0
  122. ; If 0<=n<=25, keep as-is; if 26<=n<=51, subtract 26; if n>=52, ignore
  123. ; >=52, use cp 52 & check for nc
  124. ; <=25, use cp 26 & check for c
  125. ; 26<=n<=51, neither of the above conditions were true
  126.  
  127. MainGUIData:
  128. ; Main window
  129.     .dw 29                          ; Section size
  130.     .db GUIRLargeWin                ; Element type
  131.     .db %10001000                   ; Window icon
  132.     .db %11011000
  133.     .db %01010000
  134.     .db %01010000
  135.     .db %00100000
  136.     .db "Vigenere Cipher Tool",0    ; Window title
  137. ; Buttons for main window
  138.     .dw 10                          ; Section size
  139.     .db GUIRWinButtons              ; Element type
  140.     .db %00100000                   ; No _, no [], yes X
  141.     .dw 0                           ; No pointer for _
  142.     .dw 0                           ; No pointer for []
  143.     .dw Quit                        ; Jump to Quit when X pressed
  144. ; Text "Plaintext"
  145.     .dw 16                          ; Section size
  146.     .db GUIRText                    ; Element type
  147.     .db 8,0                         ; x,y
  148.     .db 0                           ; Font (must be 0 atm)
  149.     .db "Plaintext",0               ; Text
  150. ; Text "Key"
  151.     .dw 10                          ; Section size
  152.     .db GUIRText                    ; Element type
  153.     .db 64,0                        ; x,y
  154.     .db 0                           ; Font (must be 0 atm)
  155.     .db "Key",0                     ; Text
  156. ; Plaintext input
  157.     .dw 10                          ; Section size
  158.     .db GUIRTextMultiline           ; Element type
  159.     .db 1,7                         ; x,y
  160.     .db 6                           ; 6 Rows
  161.     .db 44                          ; 44 px wide
  162.     .dw 0                           ; Offset
  163.     .db 0                           ; Default message
  164. ; Key input
  165.     .dw 10                          ; Section size
  166.     .db GUIRTextMultiline           ; Element type
  167.     .db 48,7                        ; x,y
  168.     .db 6                           ; 6 Rows
  169.     .db 44                          ; 44 px wide
  170.     .dw 0                           ; Offset
  171.     .db 0                           ; Default message
  172. ; Encrypt button
  173.     .dw 16                          ; Section size
  174.     .db GUIRButtonText              ; Element type
  175.     .db 5,45                        ; x,y
  176.     .dw Encrypt                     ; Encrypt when clicked
  177.     .db "Encipher",0                ; Text
  178. ; Decrypt button
  179.     .dw 16                          ; Section size
  180.     .db GUIRButtonText              ; Element type
  181.     .db 56,45                       ; x,y
  182.     .dw Decrypt                     ; Decrypt when clicked
  183.     .db "Decipher",0                ; Text
  184. ; About button
  185.     .dw 14                          ; Section size
  186.     .db GUIRButtonImg               ; Element type
  187.     .db 43,45                       ; x,y
  188.     .dw About                       ; Load about screen
  189.     .db 1                           ; 1 byte per row
  190.     .db 5                           ; 5 px per byte
  191.     .db %11011000                   ; Icon
  192.     .db %11111000
  193.     .db %10011000
  194.     .db %11011000
  195.     .db %10001000
  196. ; End of main win data
  197.     .dw $FFFF                       ; Tell DCS the data ends
  198.  
  199. AboutGUIData:
  200. ; About window
  201.     .dw 16                          ; Section size
  202.     .db GUIRSmallWin                ; Element type
  203.     .db 8,13                        ; x,y
  204.     .db %00100000                   ; Icon
  205.     .db %00000000
  206.     .db %01100000
  207.     .db %00100000
  208.     .db %01110000
  209.     .db "About",0                   ; Window title
  210. ; About text
  211.     .dw 50                          ; Section size
  212.     .db GUIRWrappedText             ; Element type
  213.     .db 5,0                         ; x,y
  214.     .db 72                          ; 77px wide
  215.     .db 0                           ; Font (must be 0 atm)
  216.     .db "Vigenere Cipher Tool",$D6,"  (C)2012 Jonathan Z.",0    ; Text
  217. ; About window buttons
  218.     .dw 10                          ; Section size
  219.     .db GUIRWinButtons              ; Element type
  220.     .db %00100000                   ; Only X button
  221.     .dw 0                           ; Nothing for _
  222.     .dw 0                           ; Nothing for []
  223.     .dw ReturnFromAbout             ; Jump to ReturnFromAbout when X is clicked
  224. ; End of about win data
  225.     .dw $FFFF
  226.  
  227. ;----------;
  228. ; DCS Data ;
  229. ;----------;
  230.  
  231. Description:                        ; DCS7 Description
  232.     .db "Vigenere Cipher Tool",0
  233. Icon:                               ; DCS7 Icon
  234.     .db %00000011,%11000000
  235.     .db %00001100,%00110000
  236.     .db %00010001,%10001000
  237.     .db %00010010,%01001000
  238.     .db %00010010,%01001000
  239.     .db %00010010,%01001000
  240.     .db %00010010,%01001000
  241.     .db %01111111,%11111110
  242.     .db %01000000,%00000010
  243.     .db %01000011,%11000010
  244.     .db %01000011,%11000010
  245.     .db %01000011,%11000010
  246.     .db %01000001,%10000010
  247.     .db %01000001,%10000010
  248.     .db %01000000,%00000010
  249.     .db %01111111,%11111110
Advertisement
Add Comment
Please, Sign In to add comment