/
(MSyC1)demonstration.dasm16
91 lines (71 loc) · 1.79 KB
/
(MSyC1)demonstration.dasm16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
; cypher
; Authors: Sasha Crofter, dylwhich
;
; This performs a simple encryption by
; generating a random stream from a
; seed, and XORing each word with each
; word that needs to be cyphered. The
; same operation undoes the cypher.
; This particular demo writes two lines
; of white, blank characters to 0x8000
; and on, which is the expected screen
; memory. It then performs a cypher
; using our method on those lines.
; It then copies the lines elsewhere
; onscreen, and decyphers those.
;testrun
JSR fillscrn
SET [0x4000], 0xABCD ;SEED
SET [0x4001], 0x4C1F ;SEED
SET [0x4002], 0x7004 ;SEED
SET [0x4003], 0x3FA7 ;SEED
SET A, 0x8000 ;Starting address of data to be cyphered
SET B, 64 ;Length of block
SET C, 0x4000 ;location of seed
JSR func_cypher ;Perform cypher
;DATA CYPHERED
JSR copy ;Copy the cyphered data
;MOVED CYPHER
SET A, 0x8060 ;Starting address of data to be decyphered
SET B, 64 ;Length of block
SET C, 0x4000 ;Seed (same as before)
JSR func_cypher ;Perform decypher (with exactly the same operation as before)
SET PC, EOF ;End demonstration
:fillscrn ;Demo
SET C, 0x803F
:fillloop
SET [C], 0xFFFF
SUB C, 1
IFG C, 0x7FFF
SET PC, fillloop
SET PC, POP
:copy ;Demo
SET B, 0x809F
SET C, 0x803F
:copyloop
SET [B], [C]
SUB B, 1
SUB C, 1
IFG C, 0x7FFF
SET PC, copyloop
SET PC, POP
:func_cypher ; (adr, len, seedloc)
ADD B, A ;make "ending adr" from adr and len
SET PUSH, X
SET X, [C]
ADD C, 1
SET C, [C]
:loop
;random stream
MUL C, X ;increment seed
XOR X, O ;pseudorandomly
SHL X, 1
XOR [A], C ;cypher or decypher word
XOR [A], X
ADD A, 1 ;increment address
IFG B, A ;check if the ending address is greater than the current
;address, because a successful check is less expensive
SET PC, loop ;loop back if check succeeds
SET X, POP
SET PC, POP ;end subroutine if check fails
:EOF SET PC, EOF