So you're already familiar with the different
ways of printing out your string variables,
what I have on my screen right here. I created the variable username
and assigned the value of cyber as a string to it.
And then I simply said print username
that of course resulted in printing out cyber very, very simple, very basic.
And now from line four,
I assigned the exact same value cyber to the variable username.
But notice that line five and six,
I demonstrate two different ways of printing out the variable
I could have said welcome to the world of programming
and then comma and then the name of the variable,
which is of course, user name,
Cyber
and the output is welcome to the world of programming cyber.
And then on line six instead of using the comma sign, I use the plus symbol.
And this basically is what we call
concatenation whenever you're using the plus symbol
and then you have the exact same output. However,
notice that there is a slight difference in the spacing
with the comma symbol,
you tend to have a bit more space in between your string and then the actual
a name of your variable.
Nevertheless, both methods work pretty well. It's only a matter of choice.
However, let me show you a few other basic ways of manipulating your strength. So
say, for example, I wanted to print cyber 10 times,
right?
Instead of me creating username, cyber, username, cyber, username,
cyber 10 times.
What I could simply do right here is I could
just add the asteric symbol and then just say times 10
and then
all I have to do right now is just to simply print
the username.
And if I run the program, you can see we have cyber, cyber, cyber, cyber,
cyber 10 times.
And if I want space in between my words,
I can just add a space between the R letter
and the closing code.
And if I run the program again,
there you go. We have Cyber, Cyber, cyber.
So this is what we call repetition, right?
One of the function I wanted to let you know regarding strings
is the length of a string. We can determine
how long a string is. Basically, in other words,
we can determine the number of characters in a string.
So for example,
over here,
if I wanted to figure out how many
characters were in cyber,
all I have to do is to come over here after the print function,
I can introduce another function called the length function,
which is of course, Len
and then I will have to add my closing
bracket by that.
And now if I run the program, can you guess what the value is going to be?
The value is going to be five
because cyber is made up of five characters, five letters.
Now, you might be wondering, ok, this is all good. But how is this relevant?
How do we apply this in the world of cybersecurity specifically?
I'm pretty sure you must have seen on websites before where
they ask you to log in,
you begin to type in your password,
but then you don't see the actual characters instead,
you might see like the dash symbol or
most commonly the asterisk symbol in their place.
We can use the knowledge we've gained so
far to actually recreate a similar scenario.
So
check this out. OK,
I'm gonna create a new variable right now and call it password.
And now let's add the actual password. I'm gonna say swordfish,
which isn't exactly the best password, but
never mind. We're gonna go with saltfish.
So now
I want to print out
swd fish. So I can just say print a password, right?
So if I run the program, it's gonna say salt fish, but
we want to replace each letter in saltfish with the asterisk symbol.
So basically,
we should have nine asterisk symbols in place of the actual letters themselves.
So what do we do?
I can create another variable right now
and call it the masked
underscore password.
And now this will be equal to what
I'm going to add my quotes and now add the asteric symbol.
Ok. The asteric symbol
and now multiply it again
by the length of the characters of our password string.
And there it is.
So now if I run the program
and that did not work, oh, do forgive me for the print password.
We need to change line three here to mask the password because
we're no longer printing out the password. Oops, that was a bit embarrassing.
Ok. So
we're gonna print out the mask password now. And if I run the program,
there you go. Ok. So now we have nine
asterisk symbols because SUF fish itself is made up of nine letters
and just to prove to you that this actually works if I added
three more characters, digits in this case right now, 123.
And when it again, now you can see the number of
ahe
symbols has increased by three instead of nine, it is now 12.
So this is how you could recreate something very similar in your real world program.
If you wanted to create
a masked password system,
you can use these kinds of concepts. So thank you for watching the video.
I will see you in the next class.