-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.s
281 lines (198 loc) · 5.17 KB
/
final.s
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
@This Prints the uInput string other way around...
.text
.global main
main:
sub sp,sp,#4 @ stro link register for further use
str lr,[sp,#0]
ldr r0, =formatp1
bl printf
@ 8 bytes from the stack is allocated first,and then 64 bit inputs scanned one by one
@ and stored them in registers.
@ same 8 bytes were used to scan the both inputs
sub sp,sp,#8
ldr r0, =formats1
mov r1,sp @ 1st 64 bit part of the key
bl scanf
ldr r4,[sp,#4] @ stored in registers
ldr r5,[sp,#0]
ldr r0, =formats1
mov r1,sp @ 2nd 64 bit part of the key
bl scanf
ldr r6,[sp,#4] @ stored in registers
ldr r7,[sp,#0]
ldr r0, =formatp2
bl printf
ldr r0, =formats1 @ 1st part of the text
mov r1,sp
bl scanf
ldr r8,[sp,#4] @ stored in registers
ldr r9,[sp,#0]
ldr r0, =formats1
mov r1,sp @ 2nd part of the text
bl scanf
ldr r10,[sp,#4] @ stored in registers
ldr r11,[sp,#0]
add sp,sp,#8 @ all the inputs were scanned. so freed the allocated space
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ encrypt and round functions are implemented in the main method @@@@@@@@@@@@@@
mov r0,r8
mov r1,r9
@mov r2,#8
bl rightShift
@@@@ x1-fist part of the text y1-2nd part of the text
@@@@ k1 - first part of the key k2-2nd part of the key
adds r1,r1,r11 @ least part are added first of the 1st part of the text
adc r0,r0,r10 @ x1 = x1 + y1,(will consider if there was a carry from the previous operation)
eor r0,r0,r6 @ xor x1 and k1
eor r1,r1,r7 @ xor x2 and k2
mov r8,r0 @ do the changes to r0 and r1
mov r9,r1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mov r0,r10
mov r1,r11
@mov r2,#3
bl leftShift
eor r0,r0,r8
eor r1,r1,r9
mov r10,r0
mov r11,r1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mov r3,#0
loop:
cmp r3,#31
bge exit
mov r0,r4
mov r1,r5
@mov r2,#8
bl rightShift
@@@@@@@@@@@@@@@@@@@@
adds r1,r1,r7
adc r0,r0,r6
eor r1,r1,r3 @ here the xor part is done for only one part of the text because r3 is a 32 bit number
mov r4,r0 @ so xor cannot be dne on r0
mov r5,r1
@@@@@@@@@@@@@@@@@@@
mov r0,r6
mov r1,r7
@mov r2,#3
bl leftShift
eor r1,r1,r5
eor r0,r0,r4
mov r6,r0 @ giving the news values to r4 and r5
mov r7,r1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mov r0,r8
mov r1,r9
@mov r2,#8
bl rightShift
adds r1,r1,r11 @ x2 = x2 + y2
adc r0,r0,r10 @ x1 = x1 + y1,(will consider if there was a carry from the previous operation)
eor r0,r0,r6 @ xor x1 and k1
eor r1,r1,r7 @ xor x2 and k2
mov r8,r0 @ do the changes to r0 and r1
mov r9,r1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mov r0,r10
mov r1,r11
@mov r2,#3
bl leftShift
eor r0,r0,r8
eor r1,r1,r9
mov r10,r0
mov r11,r1
add r3,r3,#1
b loop
leftShift:
@ x1 is in r0 , x2 is in r1, r is r2
sub sp,sp,#32
str r3,[sp,#0]
str r4,[sp,#4]
str r5,[sp,#8]
str r6,[sp,#12]
str r7,[sp,#16]
str r8,[sp,#20]
str r9,[sp,#24]
str lr,[sp,#28]
@mov r3,#32
@sub r3,r3,r2 @ 32 - r
mov r4,r0, lsl #3 @ shift opearations on x1 , x1 << r)
mov r5,r1, lsl #3 @ shift operation on x2, x2 << r)
mov r6,r0, lsr #29 @ shift opearations on x1 , x1 >> 32 - r)
mov r7,r1, lsr #29 @ shift opearations on x2 , x2 >> 32 - r)
orr r8,r4,r7 @ or operation on r4 and r7
orr r9,r5,r6 @ or operation on r5 and r6
mov r0,r8
mov r1,r9
@mov r1,r8
@mov r2,r9
@ldr r0, =formatp4
@bl printf
ldr r3,[sp,#0]
ldr r4,[sp,#4]
ldr r5,[sp,#8]
ldr r6,[sp,#12]
ldr r7,[sp,#16]
ldr r8,[sp,#20]
ldr r9,[sp,#24]
ldr lr,[sp,#28]
add sp,sp,#32
mov pc,lr
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
rightShift:
@ x1 is in r0 , x2 is in r1, r is r2
sub sp,sp,#32
str r3,[sp,#0]
str r4,[sp,#4]
str r5,[sp,#8]
str r6,[sp,#12]
str r7,[sp,#16]
str r8,[sp,#20]
str r9,[sp,#24]
str lr,[sp,#28]
@mov r3,#32
@sub r3,r3,r2 @ 32 - r
mov r4,r0,lsr #8 @ shift opearations on x1 , x1 << r)
mov r5,r1, lsr #8 @ shift operation on x2, x2 << r)
mov r6,r0,lsl #24 @ shift opearations on x1 , x1 >> 32 - r)
mov r7,r1,lsl #24 @ shift opearations on x2 , x2 >> 32 - r)
orr r8,r4,r7 @ or operation on r4 and r7
orr r9,r5,r6 @ or operation on r5 and r6
mov r0,r8
mov r1,r9
@mov r1,r8
@mov r2,r9
@ldr r0, =formatp4
@bl printf
ldr r3,[sp,#0]
ldr r4,[sp,#4]
ldr r5,[sp,#8]
ldr r6,[sp,#12]
ldr r7,[sp,#16]
ldr r8,[sp,#20]
ldr r9,[sp,#24]
ldr lr,[sp,#28]
add sp,sp,#32
mov pc,lr
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
exit:
ldr r0,=formatp3
bl printf
ldr ro,=formatp4
mov r1,r9 @ print x
mov r2,r8
bl printf
ldr r0,=formats2
mov r1,r11
mov r2,r10 @ print y
bl printf
mov r0,#0
ldr lr,[sp,#0]
add sp,sp,#4
mov pc,lr
.data @ data memory
formatp1: .asciz "Enter the key:\n"
formats1: .asciz "%llx"
formatp2: .asciz "Enter the plain text:\n"
formatp3: .asciz "Cipher text is:\n"
formatp4: .asciz"%llx "
formats2: .asciz "%llx\n"