Hello, this is Dr. Miller, and this
is Episode twelve point seven of
Assembly today
we're going to give an esteemed
example.
So ACMD example.
So here's our problem to be solved.
So we're going to read a string from
the user and then we're going to
read a key from the user and then
we're going to encrypt that data.
All right.
So to start off, we're going to have
a couple of different pieces of data
here,
we're going to have several
different formats.
So I have a
string.
So we're going to have two formats,
one is for reading in a string, the
other one is for reading in a hex.
I need a name these appropriately.
So this is also a string,
we're also going to allocate some
empty space in the box.
So this is blank space, but
we're allowed to read and write to
it.
So we'll define our array.
It is just a
space for 64 bytes
and that'll be used at the end.
We're also going to use a couple of
functions, so, for example,
we're going to scan F and print F.
And here we'll get into our main
function.
All right, so in
order to get things set up, we're
going to have to save our registers.
So we'll set up our stack
or.
And then we're going to allocate
quite a bit of space, so sub espie
as P.
It's to give ourselves some room to
work with.
OK, at the end, what we want to
do is we want to
fix our stacks of sub.
From the frame point, the number
four, because we added to it
and then top
frame pointer and link register.
So now those are said that up.
All right.
So what we're going to do now is
we're going to create a pointer
to our memory that we're going to
use for the frame pointer, so we'll
go ahead and sub
that. We're going to say even to our
one and we'll use the frame pointer
and we'll subtract one hundred and
eighty.
So this is some number less than
this. Two hundred, but
of course, greater than our four.
So that's going to be our pointer.
And we're putting it in our one
because in
our zero, we are going to
have our format
and then we'll call scan.
So that will scan
this string here and
it'll store it on the stack
with the offset frame pointer
plus one hundred and eighty.
So down the stack, one hundred and
eighty bytes.
So that should save our data there.
And then what we want
to do is we want to figure out how
long the string is.
So you can go and look up
documentation on a function called
sterling.
But we would go ahead and use that.
So
we need to.
Story into our zero
hour frame point or minus or plus
one hundred and eighty,
and then we'll call to think SCANA
or sorry, Sterling.
So that will tell us how long
our string is, so that's going to
give us a result inside of our zero,
which is our return result.
And for now, I'm going to copy that
into our because I'm end up using
our zero in the future.
All right, now I'm going to set up a
loop, so with
this percent X up here, I'm
going to have to read each one of
these. And so these are going to be
my key, my encryption keys.
But I want to read the same number
of encryption keys as
I have characters in my string,
which is why I called the
Sterling.
So what we can do here is
we're going to set up a loop.
So move our aked.
So our aid is going to be our
offset.
We'll give it the number zero and
we'll increment that each time
and we'll just do a compare of
our eight and our
sorry, our eight
and our nine and see if they're
equal.
And we're going to jump to this
label down here that we're going to
make, so down
here we're going to have a label
called Dunn Reading.
And we'll do stuff after that
if we don't.
Well, so this is the place where I
come back up to so we'll call this
top
and then at the bottom of our loop,
we're going to say brands to top.
So always jump back up there and
then do our comparison.
All right. So we're done reading,
but now we need to set up our
pointers. So we're going to, again,
call scaff.
And so our one is going to have to
be our pointer to our memory.
So we are going to
sub our one.
Frame pointer, and here we're going
to copy this data into a different
location.
So this one was at 180
and gave us 80 bytes
to go into here at one hundred.
All right.
And then so our offset
is stored in our eight.
So, all right. We're going to
increment each time so we can go
ahead and add our eight
or eight, the number one.
So our eight is being added each
time and it starts off at zero.
So we have offset zero.
But we're going to have to add that
to our pointer in our
one. So add our one
or eight.
So add those two together
to get the we've got our correct
offset stored in our one.
Now we need our format and our zero.
OK, and then we can call
if.
So that should allow us to
read in, right?
And each time we're going to loop
through because we do this ad at the
bottom and so we'll go ahead and
loop through in here and
read that number of keys that we
need for our data.
All right. So now we're done reading
and then we're going to want to do
our exclusive
or for our encryption.
So we've got to load it into our
registers.
So
I'll start Sabbar zero
frame pointer.
So load in the text
key that they entered.
And then we'll do Velda E.R..
Sixty four,
so we'll go ahead and load that into
zero at
our zero
and then we're going to use
our one
for the next one.
So our encryption key is at 100,
Yelda.
Sixty four.
We go ahead and do D one,
and then we're going to get the data
at R one.
OK, so now we can do
our exclusive or so B
or
D to D,
doesn't matter the order D, one
and zero.
All right, so now we've encrypted
it, but now we need to save it
so that we can print it off,
so that's what we have our array
for.
So when do Eldar,
our one,
get the address of our ouray?
And then.
We will go ahead and
do our vesty are
saved to get the location
pointed to our one, so that's
the area that we loaded in.
So I should save our data.
We also want to move a zero
in there, so
move our three.
The number is zero, and
then I'll do a star
are three into
we'll do our one.
So we're just going to read in a
maximum of eight bytes
is what
we're doing just for this example,
so that we can fit it in.
So we'll set by eight automatically
to a zero
and we'll actually set a bunch of
bytes here. So we'll set three by
four bytes to zero.
All right. So now we're ready to
print all or
one.
Array ldi are
zero
hour format that we want to use to
print and then
print F.
All right, so.
Couple of typos here, so
I got my ass.
Yes.
And then I think I forgot my colon
after my label here.
All right,
so if I enter.
Matt.
I'll just do that to start
and then my encryption key is zero
x one zero
six three
and you can type these one at a
time. We'll do them here in a
second.
So I got l beeps
So now if I run it again and type L
beep s
and then I enter my encryption key
one three,
four, seven,
I'll get Matt.
So here I with my encryption
key is right here.
And so I took Matt, I encrypted
it. I got this value here.
And then the only way to decrypt it
is to know what the
key here is.
And so I go ahead and.
Type that and again, and I'll get my
original text back.
So today, we used ACMD
to do example of doing
encryption using exclusive or.
So looking forward, we'll talk about
the mode and then conditional
execution, if
you have questions, you can e-mail
me millirems, you and Kadiatu,
and you can find me on Twitter at
Inelasticity.