Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

System Security HM 9

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

System Security HM 9

Q1)

def compare(real_passwd, user_input): # compare lengths of both strings real_passwd vs


user_input

if len(user_input) != len(real_passwd): # if length of both strings are not same, then they
cannot be anagram

return False

for i in range(len(user_input)): # compare the character between both strings

if user_input[i] != real_passwd[i]:

return False

return True

An anagram happens when a string is compared to another string and it contain the same
characters. The order of characters can be different. An example is “abcdef” and “defabc”
are anagram of each other.

a) The problem with such a system is that it is based on comparison of strings of the same
length and same type of characters in the strings but not necessarily the correct position
of the characters. This type of comparisons are not suitable for password checking cos
for password comparison, it need not only check the correct length but also need check
that the characters are in the precise order.

b) We can learn the length and anagram of real_password when interacting with the
function. The password can be recovered if we add sort and compare conditions into the
function.

Import collect

def compare(real_passwd, user_input):

real_passwd, user_input = checkChar(real_passwd),


checkChar(user_input)

if len(real_passwd)!=len(user_input):
return

counts=collect.defaultalpha(int)
for char in real_passwd:
counts[char]+=1

for char in user_input:


counts[char]-=1

if counts[char]<0:

return True

c)

def compare(real_passwd, user_input):

if len(real_passwd) > len(user_input):


difference = len(real_passwd) - len(user_input)
string1[:difference]

elif len(user_input) > len(real_passwd):


difference = len(user_input) - len(real_passwd)
user_input [:difference]user_input

else:
difference = 0

for i in range(len(real_passwd)):
if real_passwd [i] != user_input [i]:
difference += 1

return difference

print(edit_distance("smitten", "sitting")) #3
print(edit_distance("median", "medium")) #2

From computer science perspective, edit distance is one way of quantifying how two non-
similar strings or words are related to one another by counting the minimum number of
operations required to transform one string onto the other. Edit distances can be found in
applications such as language processing and bioinformatics, where automatic spelling
correction can help user to correct a misspelled word by selecting words from a dictionary
that have a low distance to the word that is spelled. In the case of bioinformatics, it can be
used to quantify similar DNA sequences, when viewed as strings of the.

The edit distance between two strings is the minimum number of character insertions,
deletions or substitutions needed to change from one string to the other. An example is the
edit distance between the words "smitten" and "sitting" is three: append a "m", substitute
the "e" for "i" and append a "g".

You might also like